I installed the xstats extension into weewx v3.6.2 on Xubuntu.

I want to output the total heating degree days over the last seven days; so 
I put $seven_day.heatdeg.sum in my tmpl file. The template is not processed 
and I find the following in syslog:

Mar  8 02:10:16 localhost weewx[1100]: cheetahgenerator: Generate failed 
with exception '<type 'exceptions.KeyError'>'
Mar  8 02:10:16 localhost weewx[1100]: cheetahgenerator: **** Ignoring 
template /etc/weewx/skins/Standard/week.html.tmpl
Mar  8 02:10:16 localhost weewx[1100]: cheetahgenerator: **** Reason: 
'skin_dict'
Mar  8 02:10:16 localhost weewx[1100]: ****  Traceback (most recent call 
last):
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 315, in generate
Mar  8 02:10:16 localhost weewx[1100]: ****      print >> _file, text
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1005, in 
__str__
Mar  8 02:10:16 localhost weewx[1100]: ****      rc = getattr(self, 
mainMethName)()
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"cheetah__etc_weewx_skins_Standard_week_html_tmpl_1488957016_4_67084.py", 
line 1115, in respond
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"cheetah__etc_weewx_skins_Standard_week_html_tmpl_1488957016_4_67084.py", 
line 469, in __errorCatcher58
Mar  8 02:10:16 localhost weewx[1100]: ****    File "<string>", line 1, in 
<module>
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"/usr/share/weewx/weewx/tags.py", line 323, in __getattr__
Mar  8 02:10:16 localhost weewx[1100]: ****      return 
self._do_query(aggregate_type)
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"/usr/share/weewx/weewx/tags.py", line 337, in _do_query
Mar  8 02:10:16 localhost weewx[1100]: ****      val=val, 
**self.option_dict)
Mar  8 02:10:16 localhost weewx[1100]: ****    File 
"/usr/share/weewx/weewx/wxmanager.py", line 67, in getAggregate
Mar  8 02:10:16 localhost weewx[1100]: ****      units_dict = 
option_dict['skin_dict'].get('Units', {})
Mar  8 02:10:16 localhost weewx[1100]: ****  KeyError: 'skin_dict'

The same thing happens for $seven_day.cooldeg.sum, $seven_day.heatdeg.avg, 
and $seven_day.cooldeg.avg. It also fails for $thirty_day.

If I use $week.heatdeg.sum it works just fine. Everything else I've tried 
with $seven_day works finee.

I don't think I changed anything in xstats.py, but attached is the 
xstats.py installed in /usr/share/weewx/user.

Is there something missing from xstats.py needed to support heatdeg/cooldeg?



-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#
#    Copyright (c) 2009-2015 Tom Keffer <tkef...@gmail.com>
#
#    See the file LICENSE.txt for your full rights.
#
"""Extended stats based on the xsearch example

This search list extension offers extra tags:

  'alltime':    All time statistics.

  'seven_day':  Statistics for the last seven days. 

  'thirty_day': Statistics for the last thirty days.

You can then use tags such as $alltime.outTemp.max for the all-time max
temperature, or $seven_day.rain.sum for the total rainfall in the last seven
days, or $thirty_day.wind.max for maximum wind speed in the past thirty days.
"""
import datetime
import time

from weewx.cheetahgenerator import SearchList
from weewx.tags import TimespanBinder
from weeutil.weeutil import TimeSpan

class ExtendedStatistics(SearchList):
    
    def __init__(self, generator):
        SearchList.__init__(self, generator)
  
    def get_extension_list(self, timespan, db_lookup):
        """Returns a search list extension with additions.

        timespan: An instance of weeutil.weeutil.TimeSpan. This holds
                  the start and stop times of the domain of valid times.

        db_lookup: Function that returns a database manager given a
                   data binding.
        """

        # First, create a TimespanBinder object for all time. This one is easy
        # because the object timespan already holds all valid times to be
        # used in the report.
        all_stats = TimespanBinder(timespan,
                                   db_lookup,
                                   context='alltime',
                                   formatter=self.generator.formatter,
                                   converter=self.generator.converter)
        
        # Now create a TimespanBinder for the last seven days. This one we
        # will have to calculate. First, calculate the time at midnight, seven
        # days ago. The variable week_dt will be an instance of datetime.date.
        week_dt = datetime.date.fromtimestamp(timespan.stop) - datetime.timedelta(weeks=1)
        # Now convert it to unix epoch time:
        week_ts = time.mktime(week_dt.timetuple())
        # Now form a TimeSpanStats object, using the time span just calculated:
        seven_day_stats = TimespanBinder(TimeSpan(week_ts, timespan.stop),
                                         db_lookup,
                                         context='seven_day',
                                         formatter=self.generator.formatter,
                                         converter=self.generator.converter)

        # Now use a similar process to get statistics for the last 30 days.
        days_dt = datetime.date.fromtimestamp(timespan.stop) - datetime.timedelta(days=30)
        days_ts = time.mktime(days_dt.timetuple())
        thirty_day_stats = TimespanBinder(TimeSpan(days_ts, timespan.stop),
                                          db_lookup,
                                          context='thirty_day',
                                          formatter=self.generator.formatter,
                                          converter=self.generator.converter)

        return [{'alltime': all_stats,
                 'seven_day': seven_day_stats,
                 'thirty_day': thirty_day_stats}]

# For backwards compatibility:
ExtStats = ExtendedStatistics

Reply via email to