It's a little more subtle than that.

Most templates, such as index.html.tmpl, are "To Date," or for the present
time. For these, the value for timespan is the entire database: the start
time is the first record in the database, the ending time is the last
record. In this case, the tag "$day" refers to the last day in the
database, which is normally "today."

However, the "NOAA" reports are different. They are generated for specific
time intervals. For example, the May 2017 report uses only database records
from 2017-05-01 inclusive through 2017-06-01 exclusive. In this case, the
timespan would cover just that interval, so the tag $day refers to the last
day in May.

So, looking again at the tag $day.outTemp.last, its value depends on the
context of "$day." For the normal "To Date" reports, it would, as you say,
refer to the very last value in the database. However, for the NOAA-style
reports it would refer to the very last record for the specific time
interval used by the report, or 2017-05-31 in our example.

Finally, look at the NOAA templates. They include iterations that look
something like:

#for $day in $month.days
  $day.dateTime $day.outTemp.avg $day.outTemp.min $day.outTemp.max
#end for

In this example, the context of $day changes with each iteration! It refers
to 2017-05-01, then 2017-05-02, then 2017-05-03, and so on. So, a loop that
looks like

#for $day in $month.days
  $day.outTemp.last
#end for

would print the temperature for the very last record of each day of the
month.

Hope this helps.

-tk



On Fri, Jun 30, 2017 at 6:52 PM, Thomas Carlin <[email protected]>
wrote:

> Is last not always valid? I assumed it would give the last value, whether
> it was 10 seconds ago, or 2 hours ago.
>
> On Jun 30, 2017 7:50 PM, "Thomas Keffer" <[email protected]> wrote:
>
>> There must not have been a valid value for outTemp for the given value
>> of timespan in the first call. You can check for yourself by printing
>> out timespan, then looking in your database for the day starting with
>> the printed starting time.
>>
>> -tk
>>
>> On Fri, Jun 30, 2017 at 6:45 PM, Thomas Carlin <[email protected]>
>> wrote:
>>
>>> I am specifically wondering why it gets N/A the first time, and I have
>>> seen it for up to the first 3 results, and never get a value the first
>>> time.  Why does the query not report the first time it is run?
>>>
>>> On Friday, June 30, 2017 at 7:36:07 PM UTC-6, Tom Keffer wrote:
>>>>
>>>> I'm not sure what you're asking. Why did it print 44.1°F six times? If
>>>> so, this is exactly what Gary and I were discussing earlier: your extension
>>>> gets loaded once *for each template*. So, that's six calls to
>>>> get_extension_list() and six prints of 44.1°F.
>>>>
>>>> How often the extension gets used in the template is an entirely
>>>> different matter.
>>>>
>>>> For example, if you take out your line stats.day().outTemp.last, but
>>>> put a print statement in, say, TimespanBinder.__getattr__, nothing
>>>> will get printed unless the tag appears in your template.
>>>>
>>>> Does that help?
>>>>
>>>> -tk
>>>>
>>>>
>>>>
>>>> On Fri, Jun 30, 2017 at 5:38 PM, Thomas Carlin <[email protected]>
>>>> wrote:
>>>>
>>>>> Okay, so I distilled the code down to the bare minimum, and still get
>>>>> the same results, (returning N/A the first time it runs for each report
>>>>> cycle), and have included it below.  I know that this SLE doesn't actually
>>>>> add anything, but since it has the same symptoms I am trying to diagnose,
>>>>> it should be a bit easier.
>>>>>
>>>>> from weewx.cheetahgenerator import SearchList
>>>>>
>>>>> from weewx.tags import TimespanBinder
>>>>> from weeutil.weeutil import TimeSpan
>>>>> import weeutil.weeutil
>>>>> import weewx.tags
>>>>>
>>>>>
>>>>> class GarageDoorAnalyzer(SearchList):
>>>>>     def __init__(self, generator):
>>>>>         SearchList.__init__(self, generator)
>>>>>
>>>>>         self.search_list_extension = {}
>>>>>
>>>>>     def get_extension_list(self, timespan, db_lookup):
>>>>>
>>>>>         garagedoor_options = {'outTemp' : 'outTemp'}
>>>>>
>>>>>         stats = weewx.tags.TimeBinder(
>>>>>             db_lookup,
>>>>>             timespan.stop,
>>>>>             formatter=self.generator.formatter,
>>>>>             converter=self.generator.converter)
>>>>>
>>>>>         latest = stats.day().outTemp.last
>>>>>
>>>>>         print latest
>>>>>
>>>>>         return [self.search_list_extension]
>>>>>
>>>>>
>>>>> This little bit of code produces the output, It is essentially the
>>>>> same run though the main engine, just intertwined with loop packet output:
>>>>> sudo wee_reports /etc/weewx/weewx.conf
>>>>> Using configuration file /etc/weewx/weewx.conf
>>>>> Generating for all time
>>>>>    N/A
>>>>> 44.1°F
>>>>> 44.1°F
>>>>> 44.1°F
>>>>> 44.1°F
>>>>> 44.1°F
>>>>> 44.1°F
>>>>>
>>>>>
>>>>> There is nothing in syslog or messages during this time. This 'server'
>>>>> this is running on is a Raspberry Pi 1, could it be lack of resources?
>>>>>
>>>>> Gary, your getattr code was exactly what I needed, and worked
>>>>> perfectly.
>>>>>
>>>>> Thank you all!
>>>>>
>>>>> Thomas
>>>>>
>>>>>
>>>>> On Friday, June 30, 2017 at 2:01:52 PM UTC-6, gjr80 wrote:
>>>>>>
>>>>>> Seeing the code and the context in which it is used is probably a
>>>>>> good starting point.
>>>>>>
>>>>>> Gary
>>>>>>
>>>>> --
>>>>> 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 a topic in the
>> Google Groups "weewx-user" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/weewx-user/P0emh6GW40I/unsubscribe.
>> To unsubscribe from this group and all its topics, 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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to