mirror of
https://github.com/weewx/weewx.git
synced 2026-06-09 01:25:20 -04:00
Removed no longer needed HTML formatting routines from weewx.units.
Introduced string formats, unit labels, and unit types in the search lists. Changed some function names to be more consistent.
This commit is contained in:
@@ -73,7 +73,9 @@ class FileGenerator(weewx.reportengine.ReportGenerator):
|
||||
|
||||
def initUnits(self):
|
||||
|
||||
self.unitTypeDict = weewx.units.getUnitTypeDict(self.skin_dict)
|
||||
self.unitTypeDict = weewx.units.getUnitTypeDict(self.skin_dict)
|
||||
self.unitStringFormatDict = weewx.units.getUnitStringFormatDict(self.skin_dict)
|
||||
self.unitLabelDict = weewx.units.getUnitLabelDict(self.skin_dict)
|
||||
|
||||
def generateSummaryBy(self, by_time, start_ts, stop_ts):
|
||||
"""This entry point is used for "SummaryBy" reports, such as NOAA monthly
|
||||
@@ -164,8 +166,8 @@ class FileGenerator(weewx.reportengine.ReportGenerator):
|
||||
t1 = time.time()
|
||||
|
||||
# Get an appropriate formatter:
|
||||
self.formatter = weewx.formatter.Formatter(weewx.units.getStringFormatDict(self.skin_dict),
|
||||
weewx.units.getHTMLLabelDict(self.skin_dict),
|
||||
self.formatter = weewx.formatter.Formatter(self.unitStringFormatDict,
|
||||
self.unitLabelDict,
|
||||
self.skin_dict['Labels']['Time'])
|
||||
|
||||
self.initAlmanac(stop_ts)
|
||||
@@ -207,8 +209,11 @@ class FileGenerator(weewx.reportengine.ReportGenerator):
|
||||
# Get the stats for this timespan from the database:
|
||||
stats = weewx.stats.TimeSpanStats(self.statsdb, timespan, self.unitTypeDict)
|
||||
|
||||
search_dict = {'station' : self.station,
|
||||
'year_name' : _yr}
|
||||
search_dict = {'station' : self.station,
|
||||
'unit_type' : self.unitTypeDict,
|
||||
'unit_label' : self.unitLabelDict,
|
||||
'unit_format' : self.unitStringFormatDict,
|
||||
'year_name' : _yr}
|
||||
|
||||
if by_time == 'SummaryByMonth':
|
||||
search_dict['month'] = stats
|
||||
@@ -251,8 +256,11 @@ class FileGenerator(weewx.reportengine.ReportGenerator):
|
||||
# Get a formatted view into the statistical information.
|
||||
statsFormatter = weewx.formatter.ModelFormatter(stats, self.formatter)
|
||||
|
||||
searchList = [{'station' : self.station,
|
||||
'almanac' : self.almanac},
|
||||
searchList = [{'station' : self.station,
|
||||
'almanac' : self.almanac,
|
||||
'unit_type' : self.unitTypeDict,
|
||||
'unit_label' : self.unitLabelDict,
|
||||
'unit_format' : self.unitStringFormatDict},
|
||||
self.outputted_dict,
|
||||
statsFormatter]
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class ImageGenerator(weewx.reportengine.ReportGenerator):
|
||||
self.weewx_root = self.config_dict['Station']['WEEWX_ROOT']
|
||||
self.image_dict = self.skin_dict['ImageGenerator']
|
||||
self.title_dict = self.skin_dict['Labels']['Generic']
|
||||
self.label_dict = weewx.units.getLabelDict(self.skin_dict)
|
||||
self.label_dict = weewx.units.getUnitLabelDict(self.skin_dict)
|
||||
self.unitTypeDict = weewx.units.getUnitTypeDict(self.skin_dict)
|
||||
|
||||
def genImages(self, archive, time_ts):
|
||||
|
||||
@@ -182,35 +182,22 @@ def getLabel(config_dict, obs_type):
|
||||
label = config_dict['Units']['Labels'][getUnitType(config_dict, obs_type)]
|
||||
return label
|
||||
|
||||
def getHTMLLabel(config_dict, obs_type):
|
||||
"""Extract an HTML unit label (e.g., "°F") for a specific observation type"""
|
||||
# return weeutil.weeutil.utf8_to_html(getLabel(config_dict, obs_type))
|
||||
return getLabel(config_dict, obs_type)
|
||||
|
||||
def getStringFormatDict(config_dict):
|
||||
def getUnitStringFormatDict(config_dict):
|
||||
"""Return a dictionary of suitable string formats for all observation types."""
|
||||
stringFormatDict = {}
|
||||
for obs_type in unitGroups:
|
||||
stringFormatDict[obs_type] = getStringFormat(config_dict, obs_type)
|
||||
return stringFormatDict
|
||||
|
||||
def getLabelDict(config_dict):
|
||||
def getUnitLabelDict(config_dict):
|
||||
"""Return a dictionary of suitable generic unit labels for all observation types."""
|
||||
labelDict = {}
|
||||
for obs_type in unitGroups:
|
||||
labelDict[obs_type] = getLabel(config_dict, obs_type)
|
||||
return labelDict
|
||||
|
||||
def getHTMLLabelDict(config_dict):
|
||||
"""Return a dictionary of suitable HTML unit labels for all observation types."""
|
||||
htmlLabelDict = {}
|
||||
for obs_type in unitGroups:
|
||||
htmlLabelDict[obs_type] = getHTMLLabel(config_dict, obs_type)
|
||||
return htmlLabelDict
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
assert(convert('degrees_F', 'degrees_C', 32.0) == 0.0)
|
||||
assert(convert('degrees_F', 'degrees_C', [32.0, 212.0, -40.0]) == [0.0, 100.0, -40.0])
|
||||
assert()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user