Got rid of no-longer-needed class ValueTupleDict.

This commit is contained in:
Tom Keffer
2014-11-01 16:39:58 +00:00
parent 604ed09594
commit aaf9abc0ff
2 changed files with 7 additions and 52 deletions

View File

@@ -430,16 +430,10 @@ class Almanac(SearchList):
# Look for the record closest in time. Up to one hour off is fine:
rec = archive.getRecord(celestial_ts, max_delta=3600)
if rec is not None:
# Wrap the record in a ValueTupleDict. This makes it easy to do
# unit conversions.
rec_vtd = weewx.units.ValueTupleDict(rec)
if rec_vtd.has_key('outTemp'):
temperature_C = weewx.units.convert(rec_vtd['outTemp'], 'degree_C')[0]
if rec_vtd.has_key('barometer'):
pressure_mbar = weewx.units.convert(rec_vtd['barometer'], 'mbar')[0]
if 'outTemp' in rec:
temperature_C = weewx.units.convert(weewx.units.as_value_tuple(rec, 'outTemp'), "degree_F")[0]
if 'barometer' in rec:
pressure_mbar = weewx.units.convert(weewx.units.as_value_tuple(rec, 'barometer'), "mbar")[0]
self.moonphases = generator.skin_dict.get('Almanac', {}).get('moon_phases', weeutil.Moon.moon_phases)

View File

@@ -665,18 +665,15 @@ class Converter(object):
>>> print target_dict
{'outTemp': 68.0, 'interval': 15, 'barometer': 30.0, 'dateTime': 194758100}
"""
# Wrap the source dictionary in a ValueTupleDict. This will cause
# keyed values to be returned as ValueTuples:
obs_vdt = ValueTupleDict(obs_dict)
target_dict = {}
for obs_type in obs_vdt:
for obs_type in obs_dict:
if obs_type == 'usUnits': continue
# Do the conversion, but keep only the first value in
# the ValueTuple:
target_dict[obs_type] = self.convert(obs_vdt[obs_type])[0]
target_dict[obs_type] = self.convert(as_value_tuple(obs_dict, obs_type))[0]
return target_dict
def getTargetUnit(self, obs_type, agg_type=None):
"""Given an observation type and an aggregation type, return the
target unit type and group, or (None, None) if they cannot be determined.
@@ -845,42 +842,6 @@ class ValueHelper(object):
return self.exists() and self.value_t[0] is not None
#==============================================================================
# class ValueTupleDict
#==============================================================================
class ValueTupleDict(dict):
"""A dictionary like any other dictionary, except that when keyed, it
returns its results as a ValueTuple.
Example:
>>> vtd = ValueTupleDict({'usUnits' : 1, 'outTemp' : 68.0})
>>> print vtd['outTemp']
(68.0, 'degree_F', 'group_temperature')
>>> print vtd.get('outTemp')
(68.0, 'degree_F', 'group_temperature')
>>> print vtd.get('foo', 100.0)
100.0
"""
def __getitem__(self, key):
# Get the standard unit system from the underlying dictionary:
std_unit_system = dict.__getitem__(self, 'usUnits')
# Get the unadorned value from the underlying dictionary:
val = dict.__getitem__(self, key)
# Given this standard unit system, what is the unit type of this
# particular observation type?
(unit_type, unit_group) = StdUnitConverters[std_unit_system].getTargetUnit(key)
# Form the value-tuple and return it
return ValueTuple(val, unit_type, unit_group)
def get(self, key, default=None):
if self.has_key(key):
return self[key]
else:
return default
#==============================================================================
# class UnitInfoHelper
#==============================================================================