$span of trailing 24h but with each period starting on the :00 min

81 views
Skip to first unread message

Andrew McGinnis

unread,
May 6, 2025, 9:34:02 AM5/6/25
to weewx-user
I'm trying to get an on-the-hour series value generated. I can get trailing 24h via $span(hour_delta=24), or the :00 hour via $day.

$day.pm2_5out.series(time_series='start', aggregate_type='max', aggregate_interval='3600')
results in this:
00:00, 12.0 µg/m³
01:00, 9.0 µg/m³
02:00, 20.0 µg/m³
03:00, 17.0 µg/m³
04:00, 18.0 µg/m³
05:00, 13.0 µg/m³
06:00, 14.0 µg/m³
07:00, 12.0 µg/m³
08:00, 11.0 µg/m³
09:00, 6.0 µg/m³

whereas $span results in this:
$span(hour_delta=24).pm2_5out.series(time_series='start', aggregate_type='max', aggregate_interval='3600')
09:12, 7.0 µg/m³
10:12, 8.0 µg/m³
11:12, 9.0 µg/m³
12:12, 8.0 µg/m³
13:12, 8.0 µg/m³
14:12, 8.0 µg/m³
15:12, 8.0 µg/m³
16:12, 9.0 µg/m³
17:12, 10.0 µg/m³
18:12, 9.0 µg/m³
19:12, 10.0 µg/m³
20:12, 13.0 µg/m³
21:12, 14.0 µg/m³
22:12, 14.0 µg/m³
23:12, 15.0 µg/m³
00:12, 12.0 µg/m³
01:12, 9.0 µg/m³
02:12, 20.0 µg/m³
03:12, 15.0 µg/m³
04:12, 18.0 µg/m³
05:12, 13.0 µg/m³
06:12, 14.0 µg/m³
07:12, 12.0 µg/m³
08:12, 11.0 µg/m³

What I'm after is the .min/.avg/etc for each hour, on the hour, for the trailing 24. Such that today at 09:27am, it would then be pulling the current-day 09:00 (ideally, as it does in $day), 08:00 hour, 07:00 hour, ..., prior-day 12:00 hour, 11:00 hour, 10:00 hour.  $day gets the minutes right, but is limited to >= midnight. $span gets the period right, but is using current time and offsetting 60min from it. 

Is there some combination where I can get the hours of a span on a :00-59 basis?

gjr80

unread,
May 7, 2025, 5:18:40 AM5/7/25
to weewx-user
Unfortunately there is no single tag that will give you what you seek. A couple of workarounds spring to mind.

You could use some in-template python code to iterate over yesterday and todays 'hours', calculate the aggregate you want for each 'hour', filter out those 'hours' you don't want and save those you do to a list. The code is going to be lengthy and inefficient but it should be doable. I'm not even going to try to show some example code.

I'd probably favour using a little in-template python code to obtain the current number of minutes past the hour then use this value in seconds as an offset in your $span tag using the time_delta parameter, eg (untested):

#set $offset = int($current.dateTime.format('%M')) * 60
$span(time_delta=$offset, hour_delta=24).pm2_5out.series(time_series='start', aggregate_type='max', aggregate_interval='3600')

There are probably other approaches that can be used, but I expect they are all going to involve some code.

Gary

wfs...@gmail.com

unread,
May 7, 2025, 9:40:32 AM5/7/25
to weewx-user
I'm not sure this is 100% correct but I did a table of the last 24 hour readings using something like

#for $seq1 in range(25)
    $hour($hours_ago=$seq1).outTemp.lasttime
    $hour($hours_ago=$seq1).outTemp.last

It was more complicated than that because I wanted to show the hourly deltas, but the first (most recent) row will have the
latest observation for the hour, and the older rows will be on the hour. 
Screenshot 2025-05-07 083815.png
Reply all
Reply to author
Forward
0 new messages