From 4e2e85147f0aba6360f641df4dd202360fdd214b Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Fri, 4 Oct 2013 20:01:29 +0000 Subject: [PATCH] 'Station' information now represented by a search list extension. --- bin/weewx/cheetahgenerator.py | 45 +++++++++++++++++++---------------- bin/weewx/station.py | 23 +++++++++--------- skins/Standard/skin.conf | 2 +- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/bin/weewx/cheetahgenerator.py b/bin/weewx/cheetahgenerator.py index 73826ce4..1f7d04c4 100644 --- a/bin/weewx/cheetahgenerator.py +++ b/bin/weewx/cheetahgenerator.py @@ -101,7 +101,7 @@ class CheetahGenerator(weewx.reportengine.CachedReportGenerator): self.gen_dict = self.skin_dict['CheetahGenerator'] if self.skin_dict.has_key('CheetahGenerator') else self.skin_dict['FileGenerator'] self.outputted_dict = {'SummaryByMonth' : [], 'SummaryByYear' : [] } self.initUnits() - self.initStation() +# self.initStation() self.initExtensions() def teardown(self): @@ -113,11 +113,6 @@ class CheetahGenerator(weewx.reportengine.CachedReportGenerator): self.unitInfoHelper = weewx.units.UnitInfoHelper(self.formatter, self.converter) - def initStation(self): - self.station = weewx.station.Station(self.stn_info, - self.formatter, self.converter, - self.skin_dict) - def initExtensions(self): """figure out which search list extensions we will load""" self.extObjs = [] @@ -259,10 +254,10 @@ class CheetahGenerator(weewx.reportengine.CachedReportGenerator): timespan.stop, formatter = self.formatter, converter = self.converter, - rain_year_start = self.station.rain_year_start, + rain_year_start = self.stn_info.rain_year_start, heatbase = heatbase_t, coolbase = coolbase_t, - week_start = self.station.week_start) + week_start = self.stn_info.week_start) # If the user has supplied an '[Extras]' section in the skin # dictionary, include it in the search list. Otherwise, just include @@ -270,9 +265,7 @@ class CheetahGenerator(weewx.reportengine.CachedReportGenerator): extra_dict = self.skin_dict['Extras'] if self.skin_dict.has_key('Extras') else {} # Put together the search list: - searchList = [{'station' : self.station, -# 'almanac' : self.almanac, - 'unit' : self.unitInfoHelper, + searchList = [{'unit' : self.unitInfoHelper, 'heatbase' : heatbase_t, 'coolbase' : coolbase_t, 'Extras' : extra_dict}, @@ -443,16 +436,16 @@ class SearchList(object): self.generator = generator def get_extension(self, timespan): - """Derived classes must define this method. Return a dictionary of name- - value pairs that bind a variable name to the object that returns the - data for that name. - + """Derived classes must define this method. Should return an object + whose attributes or keys define the extension. + timespan: An instance of weeutil.weeutil.TimeSpan. This will hold the start and stop times of the domain of valid times. """ raise NotImplementedError("Function 'get_extension' not implemented") class Almanac(SearchList): + """Class that implements the 'almanac' extension.""" def __init__(self, generator): SearchList.__init__(self, generator) @@ -480,11 +473,11 @@ class Almanac(SearchList): self.moonphases = generator.skin_dict.get('Almanac', {}).get('moon_phases', weeutil.Moon.moon_phases) - altitude_vt = weewx.units.convert(generator.station.altitude_vt, "meter") + altitude_vt = weewx.units.convert(generator.stn_info.altitude_vt, "meter") self.almanac = weewx.almanac.Almanac(celestial_ts, - generator.station.latitude_f, - generator.station.longitude_f, + generator.stn_info.latitude_f, + generator.stn_info.longitude_f, altitude=altitude_vt[0], temperature=temperature_C, pressure=pressure_mbar, @@ -492,8 +485,20 @@ class Almanac(SearchList): formatter=generator.formatter) def get_extension(self, timespan): - return {'almanac' : self.almanac} - + return self + + +class Station(SearchList): + """Class that represents the 'station' extension.""" + def __init__(self, generator): + + self.station = weewx.station.Station(generator.stn_info, + generator.formatter, generator.converter, + generator.skin_dict) + + def get_extension(self, timespan): + return self + # ============================================================================= # Filters used for encoding # ============================================================================= diff --git a/bin/weewx/station.py b/bin/weewx/station.py index a83b6458..ca60f404 100644 --- a/bin/weewx/station.py +++ b/bin/weewx/station.py @@ -7,7 +7,7 @@ # $Author$ # $Date$ # -"""Defines the default station data, available for processing data.""" +"""Defines (mostly static) information about a station.""" import time import weeutil.weeutil @@ -54,23 +54,21 @@ class StationInfo(object): self.webpath = stn_dict.get('webpath', 'www.weewx.com') class Station(object): - """Formatted data about the station. Rarely changes.""" + """Formatted version of StationInfo.""" + def __init__(self, stn_info, formatter, converter, skin_dict): - """Extracts info from the config_dict and stores it in self.""" + + # Store away my instance of StationInfo + self.stn_info = stn_info + + # Add a bunch of formatted attributes: self.hemispheres = skin_dict['Labels'].get('hemispheres', ('N','S','E','W')) - self.latitude_f = stn_info.latitude_f - self.longitude_f = stn_info.longitude_f self.latitude = weeutil.weeutil.latlon_string(stn_info.latitude_f, self.hemispheres[0:2], 'lat') self.longitude = weeutil.weeutil.latlon_string(stn_info.longitude_f, self.hemispheres[2:4], 'lon') - self.location = stn_info.location - self.hardware = stn_info.hardware - self.altitude_vt = stn_info.altitude_vt self.altitude = weewx.units.ValueHelper(value_t=stn_info.altitude_vt, formatter=formatter, converter=converter) - self.rain_year_start = stn_info.rain_year_start self.rain_year_str = time.strftime("%b", (0, self.rain_year_start, 1, 0,0,0,0,0,-1)) - self.week_start = stn_info.week_start self.uptime = weeutil.weeutil.secs_to_string(time.time() - weewx.launchtime_ts) if weewx.launchtime_ts else '' self.version = weewx.__version__ # The following works on Linux only: @@ -80,4 +78,7 @@ class Station(object): except (IOError, KeyError): self.os_uptime = '' - self.webpath = stn_info.webpath + def __getattr__(self, name): + # For anything that is not an explicit attribute of me, try + # my instance of StationInfo. + return getattr(self.stn_info, name) diff --git a/skins/Standard/skin.conf b/skins/Standard/skin.conf index 602767dc..45bfe57a 100644 --- a/skins/Standard/skin.conf +++ b/skins/Standard/skin.conf @@ -225,7 +225,7 @@ encoding = html_entities # Possible encodings are 'html_entities', 'utf8', or 'strict_ascii' - search_list = weewx.cheetahgenerator.Almanac + search_list = weewx.cheetahgenerator.Almanac, weewx.cheetahgenerator.Station [[SummaryByMonth]] #