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 <thomas...@gmail.com > <javascript:>> 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 <thomas...@gmail.com> >>> 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 weewx-user+...@googlegroups.com. >>>> 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 weewx-user+...@googlegroups.com <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 weewx-user+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.