you could just use span with a day delta:

eg
$span($day_delta=1).rain.sum for the rain total for previous 24 hours 
according to the customisation guide
or
$span($day_delta=1).outTemp.avg for the average temperature during previous 
24 hours



On Friday, 18 May 2018 01:09:48 UTC+3, Lorin Tremblay wrote:
>
> Hi!
>
> Trying to modify the xstats to add the last 24hrs to stats.
>
> here is the modification that I have made, but obviously not being a coder 
> there is one or more mistake, can anyone help me sort it out?
>
> "*#*
>
> *#    Copyright (c) 2009-2015 Tom Keffer *
>
> *#*
>
> *#    See the file LICENSE.txt for your full rights.*
>
> *#*
>
> *"""Extended stats based on the xsearch example*
>
>
> *This search list extension offers extra tags:*
>
>
> *  'alltime':    All time statistics.*
>
>
> *  '24_hrs':  Statistics for the last 24 hours.* 
>
>
> *  'seven_day':  Statistics for the last seven days.* 
>
>
> *  'thirty_day': Statistics for the last thirty days.*
>
>
> *You can then use tags such as $alltime.outTemp.max for the all-time max*
>
> *temperature, or $seven_day.rain.sum for the total rainfall in the last 
> seven*
>
> *days, or $thirty_day.wind.max for maximum wind speed in the past thirty 
> days.*
>
> *"""*
>
> *import* datetime
>
> *import* time
>
>
> *from* weewx.cheetahgenerator *import* SearchList
>
> *from* weewx.tags *import* TimespanBinder
>
> *from* weeutil.weeutil *import* TimeSpan
>
>
> *class* ExtendedStatistics(SearchList):
>
>     
>
>     *def** __init__*(self, generator):
>
>         SearchList.__init__(self, generator)
>
>   
>
>     *def** get_extension_list*(self, timespan, db_lookup):
>
>         *"""Returns a search list extension with additions.*
>
>
> *        timespan: An instance of weeutil.weeutil.TimeSpan. This holds*
>
> *                  the start and stop times of the domain of valid times.*
>
>
> *        db_lookup: Function that returns a database manager given a*
>
> *                   data binding.*
>
> *        """*
>
>
>        * # First, create a TimespanBinder object for all time. This one 
> is easy*
>
>        * # because the object timespan already holds all valid times to 
> be*
>
>        * # used in the report.*
>
>         all_stats = TimespanBinder(timespan,
>
>                                    db_lookup,
>
>                                    context=*'alltime'*,
>
>                                    formatter=self.generator.formatter,
>
>                                    converter=self.generator.converter)
>
>         
>
>        * # Now use a similar process to get statistics for the last 24 
> hours.*
>
>         hour_dt = datetime.date.fromtimestamp(timespan.stop) - 
> datetime.timedelta(hour=24)
>
>         hour_ts = time.mktime(hour_dt.timetuple())
>
>         24_hours_stats = TimespanBinder(TimeSpan(hour_ts, timespan.stop),
>
>                                           db_lookup,
>
>                                           context=*'24_hrs'*,
>
>                                           
> formatter=self.generator.formatter,
>
>                                           
> converter=self.generator.converter)
>
>
>        * # Now create a TimespanBinder for the last seven days. This one 
> we*
>
>        * # will have to calculate. First, calculate the time at midnight, 
> seven*
>
>        * # days ago. The variable week_dt will be an instance of 
> datetime.date.*
>
>         week_dt = datetime.date.fromtimestamp(timespan.stop) - 
> datetime.timedelta(weeks=1)
>
>         week_ts = time.mktime(week_dt.timetuple())
>
>         seven_day_stats = TimespanBinder(TimeSpan(week_ts, timespan.stop),
>
>                                          db_lookup,
>
>                                          context=*'seven_day'*,
>
>                                          
> formatter=self.generator.formatter,
>
>                                          
> converter=self.generator.converter)
>
>
>        * # Now use a similar process to get statistics for the last 30 
> days.*
>
>         days_dt = datetime.date.fromtimestamp(timespan.stop) - 
> datetime.timedelta(days=30)
>
>         days_ts = time.mktime(days_dt.timetuple())
>
>         thirty_day_stats = TimespanBinder(TimeSpan(days_ts, timespan.stop),
>
>                                           db_lookup,
>
>                                           context=*'thirty_day'*,
>
>                                           
> formatter=self.generator.formatter,
>
>                                           
> converter=self.generator.converter)
>
>
>         *return* [{*'alltime'*: all_stats,
>
>                  *'24_hrs'*: 24_hours_stats,
>
>                  *'seven_day'*: seven_day_stats,
>
>                  *'thirty_day'*: thirty_day_stats}]
>
>
> *# For backwards compatibility:*
>
> ExtStats = ExtendedStatistics
> "
>
>

-- 
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 weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to