I've been thinking a bit about how to support new types, such as those used by weewx-WD.
If we're willing to settle for one constraint, it does not have to be too complicated: if it's in a database, then you can plot it or show statistics about it. It does not have to be in one of the two existing databases, the archive and stats database, just some database.
If it's not, well, you'll have to come up with some clever search list extension to support it. Although there are already two "virtual" stats types in weewx (cooling and heating degree-days), allowing them to be added in a general, extensible way is complicated.
Plots
When it comes to plots, this ability is already there.
- First, make sure your database is declared in section [Databases] of weewx.conf
- Then just specify the option archive_database for the database you want. The default is whatever is set in the [StdArchive] stanza of weewx.conf, but it can be overridden.
Example skin.conf excerpt:
[[myspecial_widget]]
archive_database = my_database
[[[widgets]]]
[[[gadgets]]]
where widgets and gadgets are columns in the database my_database.
Templates
For the template tag substitution, it's more complicated.
For current records (using a weewx-WD example, this would be a tag like $current.humidex) there are two approaches that I can think of:
- Pass in the record that triggered the reporting process to CheetahGenerator. This would presumably be augmented with everything you need. Although this breaks my rule "it's gotta be in the database," it's the simplest. There is a mild risk of a thread race condition if some other service changes the record while cheetahgenerator is using it.
- Have the code in cheetahgenerator search a list of archive databases, looking for one with humidex in its schema. This would be the most general, but the most complicated.
For approach #2, as well as the aggregated statistics, things like $week.outTempDay, it will require yet another modification to the search list machinery, but I think it can be done in a backwards compatible way.
Right now, the base class SearchList looks like this:
class SearchList(object)
...
def get_extension(self, timespan, archivedb, statsdb):
...
we add another method:
def get_extension_extended(self, timespan, archive_dict, stats_dict):
...
where archive_dict and stats_dict are Python dictionaries. Their keys are a symbolic name (such as the existing 'archive_database') and the values are an instance of weewx.archive.Archive or weewx.stats.StatsDb, respectively.
Right now, the code in weewx.stats assumes that all stats data is coming from the stats database with symbolic name stats_database. This allows other databases to be included.
So, how does weewx know which database to use?
In retrospect, I wish I had made the aggregation tags
$outTempDay.week.max
instead of
$week.outTempDay.max
That's because Cheetah could then just search a list of search list extensions, each bound to a different stats database, looking for a hit on "outTempDay" in a schema.
But, all is not lost. With the latter syntax ($week.outTempDay.max), we would have to add some additional code in weewx.stats that would have the job of binding type to the appropriate stats database. It would have the dictionary stats_dict passed into it. Once it knows what the type is, it can then try each stats database in the dictionary, looking for a hit on that type. Basically, it has to reproduce what Cheetah would have done.
Hope this all makes sense.
-tk