I was able to get this to work, but not without considerable modifications
and limitations.

1. You need to define new aggregation types. You can't use
'historical_min', because that SQL statement is designed for using the
daily summaries. To calculate historical hourly data, you'll have to use
the main archive table:

'historical_hour_min': "SELECT min({obs_type}) FROM {table} "
                       "WHERE STRFTIME('%m-%d-%H', datetime,
'unixepoch', 'localtime') "
                       "= '{month:02d}-{day:02d}-{hour:02d}'",
'historical_hour_max': "SELECT max({obs_type}) FROM {table} "
                       "WHERE STRFTIME('%m-%d-%H', datetime,
'unixepoch', 'localtime') "
                       "= '{month:02d}-{day:02d}-{hour:02d}'",

2. The Python code in xaggs.py is designed for using the daily summaries,
so it must be modified as well. Here's the total diff:

*** xaggs.py 2021-12-09 07:00:04.000000000 -0800

--- /Users/Shared/weewx/bin/user/xaggs.py 2021-12-12 04:12:45.000000000
-0800

***************

*** 51,56 ****

--- 51,62 ----

                                    "WHERE STRFTIME('%m-%d',
dateTime,'unixepoch','localtime') = '{month:02d}-{day:02d}';",

              'historical_avg': "SELECT SUM(`wsum`), SUM(`sumtime`) FROM
{table}_day_{obs_type} "

                                "WHERE STRFTIME('%m-%d',
dateTime,'unixepoch','localtime') = '{month:02d}-{day:02d}';",

+             'historical_hour_min': "SELECT min({obs_type}) FROM {table} "

+                                    "WHERE STRFTIME('%m-%d-%H', datetime,
'unixepoch', 'localtime') "

+                                    "= '{month:02d}-{day:02d}-{hour:02d}'",

+             'historical_hour_max': "SELECT max({obs_type}) FROM {table} "

+                                    "WHERE STRFTIME('%m-%d-%H', datetime,
'unixepoch', 'localtime') "

+                                    "= '{month:02d}-{day:02d}-{hour:02d}'",

          },

          'mysql': {

              'historical_min': "SELECT MIN(`min`) FROM
{table}_day_{obs_type} "

***************

*** 81,106 ****

          if aggregate_type not in XAggsHistorical.sql_stmts[dbtype]:

              raise weewx.UnknownAggregation(aggregate_type)



          # The time span must lie on midnight-to-midnight boundaries

!         if db_manager.first_timestamp is None or
db_manager.last_timestamp is None:

!             raise weewx.UnknownAggregation(aggregate_type)

!         if not (isStartOfDay(timespan.start) or timespan.start ==
db_manager.first_timestamp) \

!                 or not (isStartOfDay(timespan.stop) or timespan.stop ==
db_manager.last_timestamp):

!             raise weewx.UnknownAggregation("%s of %s" % (aggregate_type,
timespan))

!

!         start_day = datetime.date.fromtimestamp(timespan.start)

!         stop_day = datetime.date.fromtimestamp(timespan.stop)

!

!         # The timespan must cover just one day

!         delta = stop_day - start_day

!         if delta.days != 1:

!             raise weewx.UnknownAggregation("%s of %s" % (aggregate_type,
timespan))



          interp_dict = {

              'table': db_manager.table_name,

              'obs_type': obs_type,

              'month': start_day.month,

!             'day': start_day.day

          }



          # Get the correct sql statement, and format it with the
interpolation dictionary.

--- 87,113 ----

          if aggregate_type not in XAggsHistorical.sql_stmts[dbtype]:

              raise weewx.UnknownAggregation(aggregate_type)



+         start_day = datetime.datetime.fromtimestamp(timespan.start)

+         stop_day = datetime.datetime.fromtimestamp(timespan.stop)

+

          # The time span must lie on midnight-to-midnight boundaries

!         if aggregate_type not in ['historical_hour_min',
'historical_hour_max']:

!             if db_manager.first_timestamp is None or
db_manager.last_timestamp is None:

!                 raise weewx.UnknownAggregation(aggregate_type)

!             if not (isStartOfDay(timespan.start) or timespan.start ==
db_manager.first_timestamp) \

!                     or not (isStartOfDay(timespan.stop) or timespan.stop
== db_manager.last_timestamp):

!                 raise weewx.UnknownAggregation("%s of %s" %
(aggregate_type, timespan))

!             # The timespan must cover just one day

!             delta = stop_day - start_day

!             if delta.days != 1:

!                 raise weewx.UnknownAggregation("%s of %s" %
(aggregate_type, timespan))



          interp_dict = {

              'table': db_manager.table_name,

              'obs_type': obs_type,

              'month': start_day.month,

!             'day': start_day.day,

!             'hour' : start_day.hour,

          }



          # Get the correct sql statement, and format it with the
interpolation dictionary.

3. The skin.conf image specification looks like:

[[day_images]]
    x_label_format = %H:%M
    bottom_label_format = %A %d %B %Y  %H h %M min
    time_length = 97200 # 27 hours

    [[[dayhistorical]]]
         time_length = 86400
         [[[[min]]]]
             label = min
             aggregate_type = historical_hour_min
             aggregate_interval = hour
             data_type = outTemp
         [[[[outTemp]]]]
         [[[[max]]]]
            label = max
            aggregate_type = historical_hour_max
            aggregate_interval = hour
            data_type = outTemp


4. Finally, it is *slow*. The reason is that for the daily historical
statistics, it can use the daily summaries, which are quite small. To find
historical hourly data, the query engine must scan the entire database
table. On my Mac M1, it took 27 seconds to do one plot!

Here's the results:

[image: image.png]
-tk

On Sun, Dec 12, 2021 at 3:42 AM [email protected] <[email protected]> wrote:

> The query is ok. I can use it with $day.outTemp.historical_temp.The space
> I think was a bad copy.  I refer to xaggs labels to the aggregations of
> xaggs like historical_avg.
> What I can't do is get it to work for me on the daily chart. Before it
> produced the error that I put before.
> Now for some reason it just doesn't plot the graph but it doesn't give an
> error. I'm looking at where the difference can be from before but I can't
> find it. I tried with interval_aggregation= hour and day but nothing.
>
>
> El viernes, 10 de diciembre de 2021 a las 20:50:13 UTC+1, [email protected]
> escribió:
>
>> I don't see why your approach would not work, although you have a syntax
>> error in your calls to strftime(). There cannot be a space between the '%'
>> and the time modifier. It should look something like this:
>>
>> select avg (outtemp) from archive where strftime ('%m %d %H', datetime,
>> 'unixepoch') = strftime ('%m %d %H', 'now')";
>>
>> I'm not sure what you mean by "xaggs labels", but if you mean the $day
>> tag, then, yes, it is indeed aggregating over one day.
>>
>>
>>
>>
>> On Fri, Dec 10, 2021 at 9:14 AM [email protected] <[email protected]>
>> wrote:
>>
>>> I had not seen the points on the weekly chart.
>>> Then the only thing that doesn't work is the daily chart because when
>>> adding aggregate_interval = day or hour it gives an error and this is the
>>> one that interests me the most.
>>> I wanted to make a graph with the historical temperature of the current
>>> moment and the current temperature. For this I had created an sql in xaggs:
>>> 'historical_temp': "select avg (outtemp) from archive where strftime ('%
>>> m-% d% H', datetime, 'unixepoch') = strftime ('% m-% d% H', 'now')",
>>> Can you think of a way to do it?
>>> I understand that in the case of xaggs labels, aggregation should not be
>>> necessary since it only gives one data per day. Unless we group by weeks or
>>> months.
>>> El viernes, 10 de diciembre de 2021 a las 14:28:55 UTC+1,
>>> [email protected] escribió:
>>>
>>>> Sorry, I was looking for user.xaggs.XAggsService at the end of
>>>> xtype_services.
>>>>
>>>> Yes, an aggregation type and an aggregation interval must always be
>>>> specified together. Otherwise, they wouldn't mean anything.
>>>>
>>>> The aggregation interval must always be one day. I'll amend the
>>>> documentation to make that clear.
>>>>
>>>> If you look closely at your weekly chart, you'll see that it is indeed
>>>> showing dots for the historical data --- it's just that they are not
>>>> connected. See the section "Dots in the plots
>>>> <http://www.weewx.com/docs/usersguide.htm#dots_in_plots>" in the
>>>> User's Guide.
>>>>
>>>> Yes, I am the author of XAggs.
>>>>
>>>> On Fri, Dec 10, 2021 at 4:40 AM [email protected] <[email protected]>
>>>> wrote:
>>>>
>>>>> I think at least one problem is that aggs tags have no aggregation.
>>>>> They simply give one data per day. The problem is that imagegenerator.py
>>>>> doesn't support aggregation_type without aggregation_interval.
>>>>> I have tried with None and it is the same as if I don't put
>>>>> aggregation_interval.
>>>>> Give a message:
>>>>> Aggregate interval required for aggregate type historical_min
>>>>> What I don't understand is its different behavior in the weekly
>>>>> charts, it doesn't paint anything and in the monthly charts it does.
>>>>> Are you the author of xagss?
>>>>>
>>>>> El viernes, 10 de diciembre de 2021 a las 12:53:08 UTC+1,
>>>>> [email protected] escribió:
>>>>>
>>>>>> I have tested the chart you posted and it is very strange. The only
>>>>>> place it works is putting it in monthly charts like the one you sent.
>>>>>> In the weekly chart, the chart that I sent before appears where
>>>>>> neither the min nor the historical max appear only outTemp
>>>>>> And if I put it on the daily chart and putting aggregation_period =
>>>>>> hour it produces the same error that I showed before with the exception
>>>>>>   **** weewx.UnknownType: outTemp
>>>>>>
>>>>>> El viernes, 10 de diciembre de 2021 a las 11:28:34 UTC+1,
>>>>>> [email protected] escribió:
>>>>>>
>>>>>>> But it does. It is the first of the line xtypes_services
>>>>>>> xtype_services = user.xaggs.XAggsService ,
>>>>>>> weewx.wxxtypes.StdWXXTypes, weewx.wxxtypes.StdPressureCooker,
>>>>>>> weewx.wxxtypes.StdRainRater, weewx.wxxtypes.StdDelta
>>>>>>> Also I can use its historical_max, historical_min ... tags on the
>>>>>>> web page with $day.outTemp.historical_min
>>>>>>> And skin.conf is stock unless I change to make this chart
>>>>>>>
>>>>>>>
>>>>>>> El viernes, 10 de diciembre de 2021 a las 0:17:28 UTC+1,
>>>>>>> [email protected] escribió:
>>>>>>>
>>>>>>>> I would like to see skin.conf as well, but, no matter, your
>>>>>>>> xtype_services section does not include  'user.xaggs.XAggsService'. 
>>>>>>>> See an earlier
>>>>>>>> email
>>>>>>>> <https://groups.google.com/g/weewx-user/c/NCuKcrFTPkQ/m/uGiWUrENAQAJ>
>>>>>>>> in this thread. It should read
>>>>>>>>
>>>>>>>>         xtype_services = user.xaggs.XAggsService,
>>>>>>>> weewx.wxxtypes.StdWXXTypes, weewx.wxxtypes.StdPressureCooker,
>>>>>>>> weewx.wxxtypes.StdRainRater, weewx.wxxtypes.StdDelta,
>>>>>>>> user.xaggs.XAggsService
>>>>>>>>
>>>>>>>> (all on one line).
>>>>>>>>
>>>>>>>> On Thu, Dec 9, 2021 at 2:49 PM [email protected] <[email protected]>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> El jueves, 9 de diciembre de 2021 a las 23:34:32 UTC+1,
>>>>>>>>> [email protected] escribió:
>>>>>>>>>
>>>>>>>>>> Hmmm. It certainly works for me.
>>>>>>>>>>
>>>>>>>>>> Can you post your copy of skin.conf, and the [Engine] section of
>>>>>>>>>> weewx.conf? I'll use them on my end and see if I can reproduce your 
>>>>>>>>>> result.
>>>>>>>>>>
>>>>>>>>>> On Thu, Dec 9, 2021 at 2:29 PM [email protected] <[email protected]>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> More than ten. I insist that if I use
>>>>>>>>>>> $day.outTemp.historical_min   it works and give me a number
>>>>>>>>>>>
>>>>>>>>>>> El jueves, 9 de diciembre de 2021 a las 23:27:56 UTC+1,
>>>>>>>>>>> [email protected] escribió:
>>>>>>>>>>>
>>>>>>>>>>>> Perhaps you don't have enough data? How many years of data in
>>>>>>>>>>>> your database?
>>>>>>>>>>>>
>>>>>>>>>>>> On Thu, Dec 9, 2021 at 2:26 PM [email protected] <
>>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Yes. I have user.xaggs.XAggService in xtype_services in
>>>>>>>>>>>>> weewx.conf
>>>>>>>>>>>>>
>>>>>>>>>>>>> El jueves, 9 de diciembre de 2021 a las 23:19:34 UTC+1,
>>>>>>>>>>>>> [email protected] escribió:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Did you add 'user.xaggs.XAggsService' to the end of
>>>>>>>>>>>>>> xtype_services, as mentioned in an earlier email in this thread?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Thu, Dec 9, 2021 at 2:18 PM [email protected] <
>>>>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> The problem was I had put that section on the day charts. If
>>>>>>>>>>>>>>> i put in week or month there no errors but it don't plot 
>>>>>>>>>>>>>>> anything.
>>>>>>>>>>>>>>> [image: weekhistorical.png]
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>>>>>> Google Groups "weewx-user" group.
>>>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails
>>>>>>>>>>>>>>> from it, send an email to [email protected].
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>>>>>>> https://groups.google.com/d/msgid/weewx-user/96003050-8169-41b4-91cc-9dadf59aed18n%40googlegroups.com
>>>>>>>>>>>>>>> <https://groups.google.com/d/msgid/weewx-user/96003050-8169-41b4-91cc-9dadf59aed18n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> --
>>>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>>>> Google Groups "weewx-user" group.
>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>>>>>>>> it, send an email to [email protected].
>>>>>>>>>>>>>
>>>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>>>>> https://groups.google.com/d/msgid/weewx-user/5e2ac174-f98b-47ea-a4a1-cce3ceae565cn%40googlegroups.com
>>>>>>>>>>>>> <https://groups.google.com/d/msgid/weewx-user/5e2ac174-f98b-47ea-a4a1-cce3ceae565cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>>>>>> .
>>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>> Google Groups "weewx-user" group.
>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>>>>>> it, send an email to [email protected].
>>>>>>>>>>>
>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>>> https://groups.google.com/d/msgid/weewx-user/a5b1bd4a-dc42-44e0-a7a7-256215106348n%40googlegroups.com
>>>>>>>>>>> <https://groups.google.com/d/msgid/weewx-user/a5b1bd4a-dc42-44e0-a7a7-256215106348n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>>>> .
>>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>>> Groups "weewx-user" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>>> send an email to [email protected].
>>>>>>>>>
>>>>>>>> To view this discussion on the web visit
>>>>>>>>> https://groups.google.com/d/msgid/weewx-user/ba71942e-d16c-4c3a-a0cd-352d1fef25f5n%40googlegroups.com
>>>>>>>>> <https://groups.google.com/d/msgid/weewx-user/ba71942e-d16c-4c3a-a0cd-352d1fef25f5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>> .
>>>>>>>>>
>>>>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "weewx-user" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>>
>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/weewx-user/08a26d42-1f89-4bf5-991c-225d7a39bc74n%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/weewx-user/08a26d42-1f89-4bf5-991c-225d7a39bc74n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "weewx-user" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/weewx-user/023a50f2-aa2e-4c75-b298-53fb0b207558n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/weewx-user/023a50f2-aa2e-4c75-b298-53fb0b207558n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/b69d3c69-9144-4643-bda1-69b54df0c5cbn%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-user/b69d3c69-9144-4643-bda1-69b54df0c5cbn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAPq0zEDjCEUjzuQ99LWy9hk00KP8jS1Y1hfxeP%3Doo6iKArq_QQ%40mail.gmail.com.

Reply via email to