makes sense - and calculating the difference in seconds was very straightforward.
Where I'm a little lost in the SLE coding is how to return the additional value 'lastrain' with the right python structure so that it plugs into weewx's unit conversion magic where folks can set their units or decimal point accuracy etc. via skin.conf and/or formatting in their cheetah template.
The weewx-wd code I'm reusing looks like this (any cut/paste/tabs errors below are mine):
if lastrain_ts is not None:
try:
_row = db_lookup().getSql("SELECT MAX(dateTime) FROM archive WHERE rain > 0 AND dateTime > ? AND dateTime <= ?", (lastrain_ts, lastrain_ts + 86400))
lastrain_ts = _row[0]
except:
lastrain_ts = None
lastrain_vt = (lastrain_ts, 'unix_epoch', 'group_time')
lastrain_vh = ValueHelper(lastrain_vt, formatter=self.generator.formatter, converter=self.generator.converter)
search_list_extension = {'last_rain' : lastrain_vh}
So to get the difference since lastrain, I added in:
# days since last rain: might be no rain in a new db so handle that too
if lastrain_ts is None:
secs_since_lastrain = None
lastrain_days = None
else:
# delta time since last rain
secs_since_lastrain = ( time.time() - lastrain_ts )
lastrain_days = secs_since_lastrain / (60*60*24.00)
lastrain_days_vt = (lastrain_days, 'unix_epoch', 'group_time')
lastrain_days_vh = ValueHelper(lastrain_days_vt, formatter=self.generator.formatter, converter=self.generator.converter)
and modified the SLE at the bottom to add my lastrain_days parameter
search_list_extension = {'last_rain' : lastrain_vh, 'lastrain_days' : lastrain_days_vh }
So.....in my index.html.tmpl file if I reference $lastrain_days I get a date that looks like 1970, but $lastrain_days.raw is correctly the fractional days since the last rain was recorded.
What I *think* it should look like is $lastrain_days should be the days since last rain (not requiring .raw in the template), and that the formatting of how many decimal points it uses should be settable via skin.conf or alternately by formatting it in the .tmpl file
Does that make sense ? Suggestions what the easiest way to accomplish that might be, or where there are examples to borrow (more) code from ? I didn't see any obvious examples of a time-offset unit / group / whatever but I might be overthinking it at this point....