Showing yesterday's weather data

301 views
Skip to first unread message

Tsjakka

unread,
Nov 19, 2014, 8:37:53 AM11/19/14
to weewx-de...@googlegroups.com
I tried to add a table with the weather data for 'yesterday', by following the directions on the website and in the file bin/examples/xsearch.py.

I added the following lines to xsearch.py:

        # Now get a TimeSpanStats object for yesterday. This one we
        # will have to calculate. First, calculate the time at midnight, one
        # day ago. The variable week_dt will be an instance of datetime.date.
        yesterday_dt = datetime.date.fromtimestamp(valid_timespan.stop) - datetime.timedelta(days=1)
        today_dt = datetime.date.fromtimestamp(valid_timespan.stop)
        # Now convert it to unix epoch time:
        yesterday_ts = time.mktime(yesterday_dt.timetuple())
        today_ts = time.mktime(today_dt.timetuple())
        # Now form a TimeSpanStats object, using the time spans we just
        # calculated:
        yesterday_stats = TimeSpanStats(TimeSpan(yesterday_ts, today_ts),
                                        statsdb,
                                        formatter=self.generator.formatter,
                                        converter=self.generator.converter)

I added the following line to skin.conf in the [CheetahGenerator] section:

search_list_extensions = examples.xsearch.MyXSearch

In the file index.html.tmpl I added a table using $yesterday elements. For example:

        <div class="stats">
          <div class="stats_header">
            Yesterday
          </div>

          <table>
            <tbody>
              <tr>
                <td class="stats_label">
                  High Temperature<br/>
                  Low Temperature
                </td>
                <td class="stats_data">
                  $yesterday.outTemp.max at $yesterday.outTemp.maxtime<br/>
                  $yesterday.outTemp.min at $yesterday.outTemp.mintime
                </td>
              </tr>

The result was I got data for today and yesterday combined. I started digging and found that the TimeSpan class is "exclusive on the left, inclusive on the right". (See bin/weeutil/weeutil.py.)
I changed the TimeSpan in the last line in xsearch.py to TimeSpan(yesterday_ts, yesterday_ts), assuming it would be solved. However, the results are the same as before the change. What am I doing wrong here?

Thomas Keffer

unread,
Nov 19, 2014, 11:50:03 AM11/19/14
to Tsjakka, weewx-de...@googlegroups.com
Hello,

Yes, this is a little subtle. So subtle, it could be considered a bug.

First, a bit of background. For archive records, a record is considered to have ended at the given timestamp. So, for a stamp 0635, it records the results from just after 0630, to, and including 0635.

However, day summaries are different. The timestamp for a day summary is the time of the beginning of the day. So, a timestamp of 10-Nov-2014 0000 is for the day 10-Nov-2014. 

The TimeSpanStats object uses the day summaries, so it's expecting the starts of the days. When you gave it TimeSpan(yesterday_ts, today_ts), it used yesterday and today.

What to do? Try this:

yesterday_dt = datetime.date.fromtimestamp(valid_timespan.stop) - datetime.timedelta(days=1)
today_dt = datetime.date.fromtimestamp(valid_timespan.stop)
# Now convert it to unix epoch time:
yesterday_ts = time.mktime(yesterday_dt.timetuple())
today_ts = time.mktime(today_dt.timetuple()) - 1


A hack, I know, and definitely not very elegant. 

Let me know how that works.

-tk

 

Tsjakka

unread,
Nov 20, 2014, 11:07:29 AM11/20/14
to weewx-de...@googlegroups.com, gon...@gmail.com
Hi Thomas,

Thank you very much for your quick response. I have tried your suggestion and it works. I have to admit I forgot to stop/start weewx yesterday, so the file xsearch.py wasn't compiled when I tried 'TimeSpan(yesterday_ts, yesterday_ts)'. This code doesn't return valid values.

Best regards,

Tsjakka


Op woensdag 19 november 2014 17:50:03 UTC+1 schreef Thomas Keffer:

Thomas Keffer

unread,
Nov 20, 2014, 11:40:25 AM11/20/14
to Tsjakka, weewx-de...@googlegroups.com
Just to warn you: Version 3 will include a tag $yesterday. In fact, you'll be able to make a query for an arbitrary number of days ago. A template that includes

<p>Yesterday's max temperature was $yesterday.outTemp.max</p>
#for $i in range(3)
<p>The max temperature $i days ago was $days_ago($days_ago=$i).outTemp.max</p>
#end for

will return something like

Yesterday's max temperature was 14.7°C
The max temperature 0 days ago was 12.1°C
The max temperature 1 days ago was 14.7°C
The max temperature 2 days ago was 15.2°C

-tk

Oz Greg

unread,
Nov 20, 2014, 4:18:57 PM11/20/14
to weewx-de...@googlegroups.com, gon...@gmail.com
*swoon* :-)

Nick La Galle

unread,
Jun 19, 2015, 9:15:08 AM6/19/15
to weewx-de...@googlegroups.com, gon...@gmail.com
Is it possible to create a "yesterday" button and show all the details for yesterday (like the week and month buttons?)

Vince Skahan

unread,
Jun 19, 2015, 10:33:24 AM6/19/15
to weewx-de...@googlegroups.com
On Friday, June 19, 2015 at 6:15:08 AM UTC-7, Nick La Galle wrote:
Is it possible to create a "yesterday" button and show all the details for yesterday (like the week and month buttons?)


Sure, you can do that yourself pretty easily.   Good learning opportunity.

Nick La Galle

unread,
Jun 21, 2015, 4:15:54 AM6/21/15
to weewx-de...@googlegroups.com
I love useful comments like this... You are better off not posting at all.

Vince Skahan

unread,
Jun 21, 2015, 2:03:45 PM6/21/15
to weewx-de...@googlegroups.com
I'm sorry, you asked 'is it possible'.  The answer of course is yes. You didn't ask 'how'.

How, you (didn't) ask ?
 - copy the template of your choosing, say the 'week' one, call it yesterday.html.tmpl
 - edit $week throughout and reference $yesterday
 - similarly edit the text throughout the page to change 'week' and 'Week' to 'yesterday' and 'Yesterday'
 - add it into your skin.conf to add the file as a new template to process, copying one of the other ones as an example
 - in all your template files (index,week,month,year) find the place where the the buttons are defined and add a new one pointing to your new file
 - wait 5 minutes
 - go for victory beer

You have to work a 'little' to learn 'something'.   See the Customization guide.  Search the google group.   Work a 'little' bit and try some stuff before asking open questions and looking for your hand to be held.


 

Nick La Galle

unread,
Jun 22, 2015, 5:19:16 AM6/22/15
to weewx-de...@googlegroups.com, gon...@gmail.com
I've gotten a yesterday page working, however the only thing I am stuck on is the charts. I can't seem to work out how to make them show the stats from the previous day (i.e. 00:00-23:59). I've had a look through and can't seem to find out how to set it. I can set a time length, but that then shows 2 days.


On Friday, 21 November 2014 03:40:25 UTC+11, Tom Keffer wrote:

gjr80

unread,
Jun 22, 2015, 5:31:02 AM6/22/15
to weewx-de...@googlegroups.com
I think you will find that a limitation of the plot engine is that it can only plot the last x seconds rather than some specific time range. Doing the last 48 hours as you have is probably the best you can achieve with the current plot engine.

Gary

Reply all
Reply to author
Forward
0 new messages