Perfect, done! Nice documentation! And, the brultech example was very useful since it wasn't completely clear from the regular docs how to implement get_series.
In case you're up for some feedback:
- Xtype needs a capital 'T' in the "Pressure" example: "class Pressure(weewx.xtypes.XType):"
- It'd be nice if there were a bit more clarity in how to "register"
- the documentation doesn't clearly stay to edit user/extensions.py
- it'd be nice to give an example of how to import the user module ("import user.indewpoint" in my case")
- It'd be nice to give a simple example of querying the database. I used the brultech example.
- Type documentation could be a bit more precise, e.g. "obs_type is the type to be computed." Technically obs_type is a string name, not an actual type. I know this sounds picky, but it confused me at first. If there's a link to a list of normal values for obs_type, that would be helpful.
My code is below in case any of it would be useful for documentation.
Thanks!
Jason
P.S. The yearly plots started working overnight, but thanks for the reminder re: deleting---I forgot that weewx will automatically recreate.
----- user/extensions.py
import user.indewpoint
import weewx.xtypes
weewx.xtypes.xtypes.append(user.indewpoint.InsideDewpoint())
----- user/indewpoint.py
import weewx.units
import weewx.xtypes
import weewx.wxformulas
from weewx.units import ValueTuple
class InsideDewpoint(weewx.xtypes.XType):
def get_scalar(self, obs_type, record, dbmanager):
"""Calculate indoor dewpoint from temperature and humidity."""
if obs_type != 'inDewpoint':
raise weewx.UnknownType
try:
record_us = weewx.units.to_US(record)
inDewpoint = weewx.wxformulas.dewpointF(record_us['inTemp'],
record_us['inHumidity'])
return ValueTuple(inDewpoint, "degree_F", "group_temperature")
except KeyError:
# Don't have everything we need. Raise an exception.
raise weewx.CannotCalculate(obs_type)
def get_series(self, obs_type, timespan, db_manager, aggregate_type, aggregate_interval):
if obs_type != 'inDewpoint':
raise weewx.UnknownType
start_vec = list()
stop_vec = list()
data_vec = list()
if aggregate_type:
raise weewx.UnknownAggregation(aggregate_type)
for record in db_manager.genSql("select dateTime, interval, usUnits, inTemp, inHumidity from archive where dateTime > %(start)s and dateTime <= %(stop)s" % {'start': timespan[0], 'stop': timespan[1]}):
if (record[2] != 1):
raise weewx.CannotCalculate("units are not US")
start_vec.append(record[0] - record[1] * 60)
stop_vec.append(record[0])
# Calculation takes inTemp and inHumidity
data_vec.append(weewx.wxformulas.dewpointF(record[3], record[4]))
return (ValueTuple(start_vec, 'unix_epoch', 'group_time'),
ValueTuple(stop_vec, 'unix_epoch', 'group_time'),
ValueTuple(data_vec, "degree_F", "group_temperature"))