Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dailygen(inputdata):
"""Internal generator function"""
day_start = start
count = 0
while day_start <= stop:
count += 1
if count % 30 == 0:
logger.info("daily: %s", day_start.isoformat(' '))
else:
logger.debug("daily: %s", day_start.isoformat(' '))
day_end = day_start + DAY
if use_dst:
# day might be 23 or 25 hours long
day_end = timezone.local_replace(
day_end + HOURx3, use_dst=use_dst, hour=day_end_hour)
acc.reset()
for data in inputdata[day_start:day_end]:
acc.add_raw(data)
for data in hourly_data[day_start:day_end]:
acc.add_hourly(data)
new_data = acc.result()
if new_data:
new_data['start'] = day_start
yield new_data
day_start = day_end
daily_data.update(dailygen(calib_data))
def generate_monthly(rain_day_threshold, day_end_hour, use_dst,
daily_data, monthly_data, process_from):
"""Generate monthly summaries from daily data."""
start = monthly_data.before(datetime.max)
if start is None:
start = datetime.min
start = daily_data.after(start + SECOND)
if process_from:
if start:
start = min(start, process_from)
else:
start = process_from
if start is None:
return start
# set start to start of first day of month (local time)
start = timezone.local_replace(
start, use_dst=use_dst, day=1, hour=day_end_hour, minute=0, second=0)
if day_end_hour >= 12:
# month actually starts on the last day of previous month
start -= DAY
del monthly_data[start:]
stop = daily_data.before(datetime.max)
if stop is None:
return None
acc = MonthAcc(rain_day_threshold)
def monthlygen(inputdata):
"""Internal generator function"""
month_start = start
count = 0
while month_start <= stop:
count += 1
if count % 12 == 0:
_ = pywws.localisation.translation.ugettext
subplot_list = plot.get_children('subplot')
subplot_count = len(subplot_list)
if subplot_count < 1:
return u''
result = u''
pressure_offset = self.pressure_offset
# add some useful functions
hour_diff = self.computations.hour_diff
rain_hour = self.computations.rain_hour
rain_day = self.computations.rain_day
rain_24hr = self.computations.rain_24hr
# label x axis of last plot
if plot_no == self.plot_count - 1:
x_lo = timezone.localize(self.x_lo)
x_hi = timezone.localize(self.x_hi)
if self.duration <= timedelta(hours=24):
# TX_NOTE Keep the "(%Z)" formatting string
xlabel = _('Time (%Z)')
elif self.duration <= timedelta(days=7):
xlabel = _('Day')
else:
xlabel = _('Date')
xlabel = self.graph.get_value('xlabel', xlabel)
if sys.version_info[0] < 3:
xlabel = xlabel.encode(self.encoding[0])
xlabel = x_hi.strftime(xlabel)
if sys.version_info[0] < 3:
xlabel = xlabel.decode(self.encoding[0])
result += u'set xlabel "%s"\n' % xlabel
dateformat = '%Y/%m/%d'
dateformat = self.graph.get_value('dateformat', dateformat)
if eval(command[1]):
round_time = timedelta(seconds=30)
else:
round_time = None
elif command[0] == 'jump':
prevdata = data
idx, valid_data = jump(idx, int(command[1]))
data = data_set[idx]
elif command[0] == 'goto':
prevdata = data
time_str = command[1]
if '%' in time_str:
if local_time:
lcl = timezone.to_local(idx)
else:
lcl = timezone.to_utc(idx)
time_str = lcl.strftime(time_str)
new_idx = pywws.weatherstation.WSDateTime.from_csv(time_str)
if local_time:
new_idx = timezone.to_naive(timezone.localize(new_idx))
new_idx = data_set.after(new_idx)
if new_idx:
idx = new_idx
data = data_set[idx]
valid_data = True
else:
valid_data = False
elif command[0] == 'loop':
loop_count = int(command[1])
loop_start = tmplt.tell()
elif command[0] == 'endloop':
loop_count -= 1
elif command[0] == 'jump':
prevdata = data
idx, valid_data = jump(idx, int(command[1]))
data = data_set[idx]
elif command[0] == 'goto':
prevdata = data
time_str = command[1]
if '%' in time_str:
if local_time:
lcl = timezone.to_local(idx)
else:
lcl = timezone.to_utc(idx)
time_str = lcl.strftime(time_str)
new_idx = pywws.weatherstation.WSDateTime.from_csv(time_str)
if local_time:
new_idx = timezone.to_naive(timezone.localize(new_idx))
new_idx = data_set.after(new_idx)
if new_idx:
idx = new_idx
data = data_set[idx]
valid_data = True
else:
valid_data = False
elif command[0] == 'loop':
loop_count = int(command[1])
loop_start = tmplt.tell()
elif command[0] == 'endloop':
loop_count -= 1
if valid_data and loop_count > 0:
tmplt.seek(loop_start, 0)
else:
logger.error("Unknown processing directive: #%s#", part)
def rain_day(self, data):
calib_data = self.context.calib_data
midnight = timezone.local_midnight(data['idx'])
midnight_data = calib_data[calib_data.nearest(midnight)]
return max(0.0, data['rain'] - midnight_data['rain'])
def add_raw(self, data):
idx = data['idx']
local_hour = (idx + timezone.standard_offset).hour
wind_gust = data['wind_gust']
if wind_gust is not None and wind_gust > self.wind_gust[0]:
self.wind_gust = (wind_gust, idx)
for i in ('temp_in', 'temp_out'):
temp = data[i]
if temp is not None:
self.ave[i].add(temp)
if local_hour >= 9 and local_hour < 21:
# daytime max temperature
self.max[i].add(temp, idx)
else:
# nighttime min temperature
self.min[i].add(temp, idx)
for i in ('hum_in', 'hum_out', 'abs_pressure', 'rel_pressure'):
value = data[i]
if value is not None: