Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions bin/user/historygenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,17 @@ def get_extension_list(self, valid_timespan, db_lookup):
noaa = True if table == 'NOAA' else False

table_options = weeutil.weeutil.accumulateLeaves(self.table_dict[table])
dbind = None
if 'data_binding' in table_options:
dbind = table_options['data_binding']
all_stats = TimespanBinder(alltime_timespan, db_lookup, data_binding=dbind, formatter=self.generator.formatter,
converter=self.generator.converter)

# Show all time unless starting date specified
startdate = table_options.get('startdate', None)
if startdate is not None:
table_timespan = weeutil.weeutil.TimeSpan(int(startdate), db_lookup().last_timestamp)
table_stats = TimespanBinder(table_timespan, db_lookup, formatter=self.generator.formatter,
table_timespan = weeutil.weeutil.TimeSpan(int(startdate), db_lookup(dbind).last_timestamp)
table_stats = TimespanBinder(table_timespan, db_lookup, data_binding=dbind, formatter=self.generator.formatter,
converter=self.generator.converter)
else:
table_stats = all_stats
Expand All @@ -182,6 +187,7 @@ def _statsHTMLTable(self, table_options, table_stats, table_name, NOAA=False):

bgColours = zip(table_options['minvalues'], table_options['maxvalues'], table_options['colours'])

reading = None
if NOAA is True:
unit_formatted = ""
else:
Expand All @@ -200,7 +206,7 @@ def _statsHTMLTable(self, table_options, table_stats, table_name, NOAA=False):
except KeyError:
syslog.syslog(syslog.LOG_INFO, "%s: Problem with aggregate_threshold. Should be in the format: [value], [units]" %
(os.path.basename(__file__)))
return "Could not generate table %s" % table_name
threshold_value = 0

threshold_units = table_options['aggregate_threshold'][1]

Expand Down Expand Up @@ -275,10 +281,33 @@ def _statsHTMLTable(self, table_options, table_stats, table_name, NOAA=False):
htmlLine += self._NoaaCell(datetime.fromtimestamp(month.timespan[0]), table_options)
else:
if unit_type == 'count':
try:
# The binding of threshold_value and threshold_units
# are bounded in this code is a bit weird. Sadly,
# reading the value out and then initializing it if
# it fails was the only way I could figure out How
# to support group_count without breaking anything.
# (Initializing the variable in an outer scope,
# actually breaks this code.)
#
# We check if we need to intialzie threshold_value
# and threshold_units depending on if we reading
# the value out fails.
x = threshold_value
except UnboundLocalError:
threshold_value = 0
threshold_units = 'count'

# I don't get why the group needs to be passed only sometimes.
# Specifically, pass group_count only if it is a group_count,
# but do not pass a unit group if it is a different unit group.
try:
value = getattr(getattr(month, obs_type), aggregate_type)((threshold_value, threshold_units)).value_t
except:
value = [0, 'count']
try:
value = getattr(getattr(month, obs_type), aggregate_type)((threshold_value, threshold_units, 'group_count')).value_t
except Exception as e:
value = [0, 'count']
else:
value = converter.convert(getattr(getattr(month, obs_type), aggregate_type).value_t)

Expand Down