$month($months_ago=1) broken?

68 views
Skip to first unread message

Warren Gill

unread,
Apr 3, 2022, 2:13:03 PM4/3/22
to weewx-user
If I add the month aggregation to my templates, Cheetah chokes.

#for $m in $range(12)
{ "month": $month($months_ago=$m).outTemp.min },
#end for

Produces the following error:

Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: Evaluation of template /etc/weewx/skins/Seasons/curves.json.tmpl failed with exception '<type 'exceptions.TypeError'>'
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/Seasons/curves.json.tmpl
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** Reason: __call__() got an unexpected keyword argument 'months_ago'
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** Traceback (most recent call last):
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** File "/usr/share/weewx/weewx/cheetahgenerator.py", line 348, in generate
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** unicode_string = compiled_template.respond()
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** File "_etc_weewx_skins_Seasons_curves_json_tmpl.py", line 109, in respond
Apr 03 13:07:04 weather python2[21603]: wee_reports[21603] ERROR weewx.cheetahgenerator: **** TypeError: __call__() got an unexpected keyword argument 'months_ago'

However, other aggregations (days, weeks, years) work fine:

#for $m in $range(12)
{ "month": $year($years_ago=$m).outTemp.min },
#end for

No errors produced, output is as expected.

What am I doing wrong?

Tom Keffer

unread,
Apr 3, 2022, 8:58:56 PM4/3/22
to weewx-user
I just tried your snippet on my machine and it worked fine:

{ "month": -3.8°C },
{ "month": -3.7°C },
{ "month": -4.9°C },
{ "month": 5.9°C },
{ "month": 9.2°C },
{ "month": 8.5°C },
{ "month": 5.7°C },
{ "month": 0.5°C },
{ "month": -1.2°C },
{ "month": -4.0°C },
{ "month": -4.0°C },
{ "month": -7.7°C },

What is the template /etc/weewx/skins/Seasons/curves_json.tmpl? It's not part of WeeWX. Check it for errors.

-tk

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/16b67157-78d9-4af4-8241-4746023cdb66n%40googlegroups.com.

Warren Gill

unread,
Apr 3, 2022, 11:30:27 PM4/3/22
to weewx-user
curves.json.tmpl is a custom template I made to use with Chart.js
It's all working now!

{ "current" : { "datetime" : "$current.dateTime.raw"},
  "monthly": [
#for $m in $range(12)
     {
          "month": "$month($months_ago=$m).dateTime.format('%B')",
          "min": $month($months_ago=$m).outTemp.min.nolabel('%.1f'),
          "max": $month($months_ago=$m).outTemp.max.nolabel('%.1f')
#if $m < 11
     },
#else
     }
#end if
#end for
  ],
  "last24": [
#for $_span in $span($hour_delta=24).spans(interval=1200)
     { "datetime": "$_span.start.format('%r')", "temp": $_span.outTemp.avg.format(add_label=False), "dewpoint": $_span.dewpoint.avg.format(add_label=False), "humidity": $_span.outHumidity.avg.format(add_label=False), "windchill": $_span.windchill.avg.format(add_label=False), "heat_index": $_span.heatindex.avg.format(add_label=False), "barometer" : $_span.barometer.avg.format(add_label=False) },
#end for
     { "void_end" : null }
  ]
}

wechart.png

Tom Keffer

unread,
Apr 3, 2022, 11:44:41 PM4/3/22
to weewx-user
Very clever!

Be sure to check out the wiki document Tags for series. It might help you simplify some of your template.

Reply all
Reply to author
Forward
0 new messages