mirror of
https://github.com/weewx/weewx.git
synced 2026-05-19 07:15:18 -04:00
Add tag time periods of last_hour, last_day, last_week, last_month and last_year. Add month_delta and year_delta to span.
YOu can iterate over those periods. See http://carlingfordweather.sydney/TEST/tag-test.txt for Top Temperatures over the last immediate week.
This commit is contained in:
@@ -473,9 +473,10 @@ def archiveHoursAgoSpan(time_ts, hours_ago=0, grace=1):
|
||||
return TimeSpan(time.mktime(start_span_dt.timetuple()),
|
||||
time.mktime(stop_span_dt.timetuple()))
|
||||
|
||||
def archiveSpanSpan(time_ts, time_delta=0, hour_delta=0, day_delta=0, week_delta=0):
|
||||
def archiveSpanSpan(time_ts, time_delta=0, hour_delta=0, day_delta=0, week_delta=0, month_delta=0, year_delta=0):
|
||||
""" Returns a TimeSpan for the last xxx seconds where xxx equals
|
||||
time_delta sec + hour_delta hours + day_delta days + week_delta weeks
|
||||
time_delta sec + hour_delta hours + day_delta days + week_delta weeks + month_delta months + year_delta years
|
||||
Note: For month_delta, 1 month = 30 days, For year_delta, 1 year = 365 days
|
||||
|
||||
Example:
|
||||
>>> os.environ['TZ'] = 'Australia/Brisbane'
|
||||
@@ -490,6 +491,10 @@ def archiveSpanSpan(time_ts, time_delta=0, hour_delta=0, day_delta=0, week_delta
|
||||
[2015-07-20 08:05:35 AEST (1437343535) -> 2015-07-21 09:05:35 AEST (1437433535)]
|
||||
>>> print archiveSpanSpan(time_ts, week_delta=4)
|
||||
[2015-06-23 09:05:35 AEST (1435014335) -> 2015-07-21 09:05:35 AEST (1437433535)]
|
||||
>>> print archiveSpanSpan(time_ts, month_delta=1)
|
||||
[2015-06-21 09:05:35 AEST (1434841535) -> 2015-07-21 09:05:35 AEST (1437433535)]
|
||||
>>> print archiveSpanSpan(time_ts, year_delta=1)
|
||||
[2014-07-21 09:05:35 AEST (1405897535) -> 2015-07-21 09:05:35 AEST (1437433535)]
|
||||
>>> print archiveSpanSpan(time_ts)
|
||||
[2015-07-21 09:05:34 AEST (1437433534) -> 2015-07-21 09:05:35 AEST (1437433535)]
|
||||
"""
|
||||
@@ -497,7 +502,7 @@ def archiveSpanSpan(time_ts, time_delta=0, hour_delta=0, day_delta=0, week_delta
|
||||
if time_ts is None:
|
||||
return None
|
||||
start_ts = time_ts - time_delta - hour_delta * 3600 - day_delta * 86400 - \
|
||||
week_delta * 604800
|
||||
week_delta * 604800 - month_delta * 2592000 - year_delta * 31536000
|
||||
if start_ts == time_ts:
|
||||
start_ts -= 1
|
||||
return TimeSpan(start_ts, time_ts)
|
||||
|
||||
@@ -82,9 +82,9 @@ class TimeBinder(object):
|
||||
def hour(self, data_binding=None):
|
||||
return self.hours_ago(data_binding)
|
||||
|
||||
def span(self, data_binding=None, time_delta=0, hour_delta=0, day_delta=0, week_delta=0):
|
||||
def span(self, data_binding=None, time_delta=0, hour_delta=0, day_delta=0, week_delta=0, month_delta=0, year_delta=0):
|
||||
return TimespanBinder(weeutil.weeutil.archiveSpanSpan(self.report_time, time_delta=time_delta,
|
||||
hour_delta=hour_delta, day_delta=day_delta, week_delta=week_delta),
|
||||
hour_delta=hour_delta, day_delta=day_delta, week_delta=week_delta, month_delta=month_delta, year_delta=year_delta),
|
||||
self.db_lookup, data_binding=data_binding,
|
||||
context='day', formatter=self.formatter, converter=self.converter,
|
||||
**self.option_dict)
|
||||
@@ -124,8 +124,17 @@ class TimeBinder(object):
|
||||
self.db_lookup, data_binding=data_binding,
|
||||
context='rainyear', formatter=self.formatter, converter=self.converter,
|
||||
**self.option_dict)
|
||||
|
||||
|
||||
def last_hour(self, data_binding=None):
|
||||
return self.span(data_binding, hour_delta=1)
|
||||
def last_day(self, data_binding):
|
||||
return self.span(data_binding, day_delta=1)
|
||||
def last_week(self, data_binding=None):
|
||||
return self.span(data_binding, week_delta=1)
|
||||
def last_month(self, data_binding=None):
|
||||
return self.span(data_binding, month_delta=1)
|
||||
def last_year(self, data_binding=None):
|
||||
return self.span(data_binding, year_delta=1)
|
||||
|
||||
#===============================================================================
|
||||
# Class TimespanBinder
|
||||
#===============================================================================
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
@@ -1078,6 +1078,31 @@ $month.outTemp.max</pre>
|
||||
set by option <a href="usersguide.htm#rain_year_start"><span class="code">rain_year_start</span></a>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$last_hour</td>
|
||||
<td class="code">$last_hour.barometer.avg</td>
|
||||
<td>The average barometer over the immediate last hour.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$last_day</td>
|
||||
<td class="code">$last_day.dewpoint.max</td>
|
||||
<td>The maximum dewpoint over the immediate last day (24 hours).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$last_week</td>
|
||||
<td class="code">$last_week.outTemp.max</td>
|
||||
<td>The maximum temperature over the immediate last week (7 days).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$last_month</td>
|
||||
<td class="code">$last_month.outTemp.min</td>
|
||||
<td>The minimum temperature over the immediate last month (30 days).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$last_year</td>
|
||||
<td class="code">$last_year.rain.sum</td>
|
||||
<td>The accumulated rain over the immediate last year (365 days).</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="unit_conversion_options">Unit conversion options</h3>
|
||||
@@ -1545,6 +1570,16 @@ or in foobar units: $day.barometer.min.foobar
|
||||
<td class="code">$span($week_delta=2).barometer.max</td>
|
||||
<td>The maximum barometric pressure over the last immediate 2 weeks.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$month_delta=<i>months</i></td>
|
||||
<td class="code">$span($month_delta=3).outTemp.min</td>
|
||||
<td>The minimum temperture over the last immediate 3 months (90 days).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="first_col code">$year_delta=<i>years</i></td>
|
||||
<td class="code">$span($year_delta=1).windchill.min</td>
|
||||
<td>The minimum wind chill over the last immediate 1 year (365 days).</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user