mirror of
https://github.com/weewx/weewx.git
synced 2026-04-18 08:36:54 -04:00
Shorter time increments now use one hour boundaries.
This commit is contained in:
@@ -168,7 +168,7 @@ def scaletime(tmin_ts, tmax_ts) :
|
||||
>>> time_ts = time.mktime(time.strptime("2013-05-17 07:45", "%Y-%m-%d %H:%M"))
|
||||
>>> xmin, xmax, xinc = scaletime(time_ts - 3*3600, time_ts)
|
||||
>>> print to_string(xmin), to_string(xmax), xinc
|
||||
2013-05-17 04:45:00 PDT (1368791100) 2013-05-17 07:45:00 PDT (1368801900) 900
|
||||
2013-05-17 05:00:00 PDT (1368792000) 2013-05-17 08:00:00 PDT (1368802800) 900
|
||||
|
||||
Example 6: 3 hours on a non-15 minute boundary
|
||||
>>> time_ts = time.mktime(time.strptime("2013-05-17 07:46", "%Y-%m-%d %H:%M"))
|
||||
@@ -191,24 +191,9 @@ def scaletime(tmin_ts, tmax_ts) :
|
||||
tmin_dt = datetime.datetime.fromtimestamp(tmin_ts)
|
||||
tmax_dt = datetime.datetime.fromtimestamp(tmax_ts)
|
||||
|
||||
# How big a time delta are we talking about?
|
||||
if tdelta <= 3 * 3600:
|
||||
# Three hours or less. Use a time increment of 15 minutes:
|
||||
interval = 900
|
||||
# m is the number of minutes
|
||||
m = tmax_dt.timetuple()[4]
|
||||
# This will be the 15 minute boundary below tmax:
|
||||
stop_dt = tmax_dt.replace(second=0, microsecond=0) - datetime.timedelta(minutes=m%15)
|
||||
# If tmax happens to be on a 15 minute boundary, we're done. Otherwise, round
|
||||
# up to the next one:
|
||||
if tmax_dt > stop_dt:
|
||||
stop_dt += datetime.timedelta(minutes=15)
|
||||
n_hours = int((tdelta + 3599) / 3600)
|
||||
start_dt = stop_dt - datetime.timedelta(hours=n_hours)
|
||||
|
||||
elif tdelta <= 12 * 3600:
|
||||
# Twelve hours or less. Use an increment of 60 minutes:
|
||||
interval = 3600
|
||||
if tdelta <= 12 * 3600:
|
||||
# For time intervals 3 hours or more, use one hour increment. Else, 15 minutes.
|
||||
interval = 3600 if tdelta > 3*3600 else 900
|
||||
# Get to the one hour boundary below tmax:
|
||||
stop_dt = tmax_dt.replace(minute=0, second=0, microsecond=0)
|
||||
# if tmax happens to be on a one hour boundary we're done. Otherwise, round
|
||||
@@ -218,7 +203,6 @@ def scaletime(tmin_ts, tmax_ts) :
|
||||
n_hours = int((tdelta + 3599) / 3600)
|
||||
start_dt = stop_dt - datetime.timedelta(hours=n_hours)
|
||||
|
||||
|
||||
elif tdelta <= 27 * 3600:
|
||||
# A day plot is wanted. A time increment of 3 hours is appropriate
|
||||
interval = 3 * 3600
|
||||
|
||||
Reference in New Issue
Block a user