That makes sense. I feel like we are making progress. At least the error
keeps changing. Now I am getting a KeyError: 'latest' on the same line. I
get the same thing when I use 'current()' or 'latest' without ().
Traceback below:
Traceback (most recent call last):
File "/usr/share/weewx/weewx/reportengine.py", line 239, in run
obj.start()
File "/usr/share/weewx/weewx/reportengine.py", line 273, in start
self.run()
File "/usr/share/weewx/weewx/cheetahgenerator.py", line 157, in run
ngen = self.generate(gen_dict[section_name], self.gen_ts)
File "/usr/share/weewx/weewx/cheetahgenerator.py", line 231, in generate
ngen += self.generate(section[subsection], gen_ts)
File "/usr/share/weewx/weewx/cheetahgenerator.py", line 231, in generate
ngen += self.generate(section[subsection], gen_ts)
File "/usr/share/weewx/weewx/cheetahgenerator.py", line 319, in generate
default_binding)
File "/usr/share/weewx/weewx/cheetahgenerator.py", line 371, in
_getSearchList
searchList += obj.get_extension_list(timespan, db_lookup)
File "/usr/share/weewx/user/gdanalyzer.py", line 66, in get_extension_list
latest = stats.day().outTemp.latest()
File "/usr/share/weewx/weewx/tags.py", line 326, in __getattr__
return self._do_query(aggregate_type)
File "/usr/share/weewx/weewx/tags.py", line 340, in _do_query
val=val, **self.option_dict)
File "/usr/share/weewx/weewx/wxmanager.py", line 60, in getAggregate
return weewx.manager.DaySummaryManager.getAggregate(self, timespan,
obs_type, aggregateType, **option_dict)
File "/usr/share/weewx/weewx/manager.py", line 1270, in getAggregate
_row = self.getSql(DaySummaryManager.sqlDict[aggregate_type] % interDict
)
KeyError: 'latest'
On Sunday, June 25, 2017 at 2:34:42 PM UTC-6, Tom Keffer wrote:
>
> Sorry. Forgot that "day
> <https://github.com/weewx/weewx/blob/v3.7.1/bin/weewx/tags.py#L69>" is
> actually a function. If Cheetah gets this error it swallows it, then
> silently tries the attribute again, this time as a function, using default
> arguments. You, programming in plain old Python, have no such luxury, so
> you have to call it as a function the first time. I should note that "
> latest <https://github.com/weewx/weewx/blob/v3.7.1/bin/weewx/tags.py#L364>"
> is also a function, so it will also have to be called as one. The
> expression becomes
>
> stats.day().outTemp.latest()
>
>
> If you follow the links for day and latest, you can see what optional
> arguments they can take.
>
> -tk
>
>
>
>
>
> On Sun, Jun 25, 2017 at 1:06 PM, Thomas Carlin <[email protected]
> <javascript:>> wrote:
>
>> Thanks again Tom,
>>
>> Hopefully the last question for today!
>>
>> I currently have (truncated for brevity)
>>
>> from weewx.cheetahgenerator import SearchList
>> import weewx.tags
>>
>>
>> class GarageDoorAnalyzer(SearchList):
>> def __init__(self, generator):
>> SearchList.__init__(self, generator)
>>
>>
>> def get_extension_list(self, timespan, db_lookup):
>>
>> stats = weewx.tags.TimeBinder(
>> db_lookup,
>> timespan.stop,
>> formatter=self.generator.formatter,
>> converter=self.generator.converter)
>>
>>
>> latest = stats.day.outTemp.latest
>> print latest
>>
>> self.search_list_extension[tag_name] = self.
>> _DoSomethingWithLatest(latest)
>> return[self.search_list_extension]
>>
>>
>>
>> When I run this, i get the following traceback:
>>
>> , line 67, in get_extension_list
>> latest = stats.day.outTemp.latest
>> AttributeError: 'function' object has no attribute 'outTemp'
>>
>>
>>
>>
>>
>>
>> On Sunday, June 25, 2017 at 11:37:55 AM UTC-6, Tom Keffer wrote:
>>
>>> I cut-and-paste from the definition for function
>>> Stats.get_extension_list()
>>> <https://github.com/weewx/weewx/blob/v3.7.1/bin/weewx/cheetahgenerator.py#L537>.
>>>
>>> You can see where trend_dict came from there. However, unless you plan
>>> to use something like stats.trend in your search list extension
>>> (unlikely), it, and several other parameters, can be safely left out. A
>>> more minimal assignment for stats would look like:
>>>
>>> stats = weewx.tags.TimeBinder(
>>> db_lookup,
>>> timespan.stop,
>>> formatter=self.generator.formatter,
>>> converter=self.generator.converter)
>>>
>>> As for how often an SLE gets called, that depends on the usage pattern.
>>> Without seeing the exact pattern you are using it's hard to say, but
>>> something I see quite often is Cheetah expressions that look something like
>>> this (this came up today):
>>>
>>> #if $day.UV.has_data
>>> <tr>
>>> <td class="stats_label">UV</td>
>>> #if $current.UV.raw <= 2.4
>>> <td class="stats_data" style="background-color:
>>> limegreen">$current.UV</td>
>>> #else if $current.UV.raw >= 2.5 and $current.UV.raw <= 5.4
>>> <td class="stats_data" style="background-color: yellow">$current.UV</td>
>>> #else if $current.UV.raw >= 5.5 and $current.UV.raw <= 7.4
>>> <td class="stats_data" style="background-color: orange">$current.UV</td>
>>> #else if $current.UV.raw >= 7.5 and $current.UV.raw <= 10.4
>>> <td class="stats_data" style="background-color: red">$current.UV</td>
>>> #else if $current.UV.raw > 10.5
>>> <td class="stats_data" style="background-color: violet">$current.UV</td>
>>> #end if
>>> </tr>
>>> #end if
>>>
>>>
>>> This snippet will use the Current SLE up to eight times, just to get the
>>> UV value. If the UV value is not available in the current record, that
>>> means up to 8 SQL queries! A more efficient pattern is:
>>>
>>> #if $day.UV.has_data
>>> #set $current_UV = $current.UV.raw
>>> <tr>
>>> <td class="stats_label">UV</td>
>>> #if $current_UV <= 2.4
>>> <td class="stats_data" style="background-color:
>>> limegreen">$current.UV</td>
>>> #else if $current_UV >= 2.5 and $current_UV <= 5.4
>>> <td class="stats_data" style="background-color: yellow">$current.UV</td>
>>> #else if $current_UV >= 5.5 and $current_UV <= 7.4
>>> <td class="stats_data" style="background-color: orange">$current.UV</td>
>>> #else if $current_UV >= 7.5 and $current_UV <= 10.4
>>> <td class="stats_data" style="background-color: red">$current.UV</td>
>>> #else
>>> <td class="stats_data" style="background-color: violet">$current.UV</td>
>>> #end if
>>> </tr>
>>> #end if
>>>
>>> -tk
>>>
>>>
>>>
>>> On Sun, Jun 25, 2017 at 9:49 AM, Thomas Carlin <[email protected]>
>>> wrote:
>>>
>>>> Thanks Tom, that looks like exactly what I need. Doing some testing
>>>> this morning, I get an error on
>>>> trend=trend_dict,
>>>>
>>>> NameError: global name 'trend_dict' is not defined
>>>>
>>>> Where does this dictionary originate?
>>>>
>>>> Unrelated to the original question, I noticed that my extension runs
>>>> several times (7 i think) for each report generation. It's trivial to
>>>> write a catch in so it only runs once, but i'm curious why this is. Could
>>>> you shed any light on this?
>>>>
>>>> -Thomas
>>>>
>>>>
>>>> On Saturday, June 24, 2017 at 8:25:07 PM UTC-6, Tom Keffer wrote:
>>>>>
>>>>> Not a simple question at all!
>>>>>
>>>>> Generally, yes, you can use something similar to the tags in your code
>>>>> by following the same path through the objects. For example,
>>>>>
>>>>> $day.outTemp.latest
>>>>>
>>>>> can be obtained by using
>>>>>
>>>>> stats = weewx.tags.TimeBinder(
>>>>> db_lookup,
>>>>> timespan.stop,
>>>>> formatter=self.generator.formatter,
>>>>> converter=self.generator.converter,
>>>>> week_start=self.generator.stn_info.week_start,
>>>>> rain_year_start=self.generator.stn_info.rain_year_start,
>>>>> trend=trend_dict,
>>>>> skin_dict=self.generator.skin_dict)
>>>>>
>>>>> latest = stats.day.outTemp.latest
>>>>>
>>>>> This is basically all Cheetah is doing!
>>>>>
>>>>> Hope this helps.
>>>>>
>>>>> -tk
>>>>>
>>>>>
>>>>> On Sat, Jun 24, 2017 at 8:39 AM, Thomas Carlin <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Good morning everyone,
>>>>>>
>>>>>> I have a custom search list extension that I am working on to do some
>>>>>> analysis on my collected data, and I have it to the point that I am
>>>>>> pulling
>>>>>> the data out, and can manipulate it, but to do so, I had to define my
>>>>>> own
>>>>>> timespan/binder inside my script. (The historygenerator extension does
>>>>>> the
>>>>>> same thing).
>>>>>>
>>>>>> Is there any way to use the weewx defined 'latest' or 'current'
>>>>>> timespan inside my python extension? Please forgive me if this is a
>>>>>> simple
>>>>>> question, the only programing experience that I have is self-inflicted,
>>>>>> and
>>>>>> far from complete.
>>>>>>
>>>>>> Thank you!
>>>>>>
>>>>>> --
>>>>>> 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 [email protected].
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> --
>>>> 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 [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.