Historical temperature of this moment.

143 views
Skip to first unread message

enu...@gmail.com

unread,
Oct 22, 2021, 9:27:50 AM10/22/21
to weewx-user
Would it be possible to make a graph with the historical temperature of that same day at that same time with all the data in the database?
And another would be the temperature anomaly with the current moment.
Thank you.

p q

unread,
Oct 22, 2021, 9:58:20 AM10/22/21
to weewx...@googlegroups.com
Someone wrote a search extension for "on this date" that would allow you to pull up the stats for a given date over time. I use it to show the high/low/rain for today's date for the years that I have data. Search this forum for it, if that's what you're looking for.

On This Day
Oct 22
2016
  H: 83.8°F   L: 51.0°F
2017
  H: 77.2°F   L: 47.6°F
2018
  H: 76.9°F   L: 49.4°F
2019
  H: 86.2°F   L: 49.8°F
2020
  H: 82.6°F   L: 52.4°F

--
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/61df7337-1936-43eb-b4e0-46ffaae5a6c1n%40googlegroups.com.


--
Peter Quinn
(415)794-2264

enu...@gmail.com

unread,
Oct 23, 2021, 6:38:42 AM10/23/21
to weewx-user
What is that extension?
What I want is a graph that has the current temperature and the average temperature that corresponds to all the records in the database with the same day and time.

Tom Keffer

unread,
Oct 23, 2021, 8:35:15 AM10/23/21
to weewx-user
If I understand you correctly, you want to graph the day's temperature, along with the average historical temperature for the same time of day.

The extension that Peter is referring to is the XAggs extension, but it does something slightly different. It calculates historical data (high, low, average, etc.) for the whole day, not just a particular time. It does this by offering new aggregation types, such as historical_avg, so you can request something like $day.outTemp.historical_avg and get the average temperature for today. That's not quite what you want, because you want the average for a particular time. 

Not sure how to handle that. Perhaps by defining a new type, call it outTemp_avg? Think of it as a new column in the database. although the XTypes system allows you to define new types virtually, so you don't have to actually put it in the database. Then it could be specified like any other type:

    [[day_images]]
        ...
        [[[dayhistorical]]]
            [[[[outTemp]]]]
            [[[[outTemp_avg]]]]
        
I think you can get away with just defining the XTypes function get_scalar(). Schematically, this would look something like this:

class HistoricalAvg(weewx.xtypes.XType):
    def get_scalar(self, obs_type, record, db_manage):
        if obs_type != 'outTemp_avg':
            raise weewx.UnknownType(obs_type)
        ... Get the time of day for this record ...
        ... Look through the database for the average temperature for that time ...
        ... return it as a ValueTuple...

As you can see, I've left out a lot of details! Read through the XTypes documentation and see if you want to tackle this project. 

-tk

p q

unread,
Oct 23, 2021, 9:25:32 AM10/23/21
to weewx...@googlegroups.com
Maybe it would be better to precompute the one hour (good enough? Or one minute?) historical averages and store it in the database rather than calculate it on the fly. 

Tom Keffer

unread,
Oct 23, 2021, 10:29:40 AM10/23/21
to weewx-user
To be sure, it is an expensive calculation because the whole database would have to be searched. The daily summaries cannot be used because they are aggregates over a day. 

Precalculating would speed things up.

-tk

enu...@gmail.com

unread,
Nov 2, 2021, 1:05:56 PM11/2/21
to weewx-user
the sql to do what I want would be
select avg(outtemp) from archive
where strftime("%m-%d %H", datetime,'unixepoch')=strftime('%m-%d %H','now')
where I could put that query?

Tom Keffer

unread,
Nov 2, 2021, 3:34:49 PM11/2/21
to weewx-user
In an XTypes extension. See the 4th message in this thread.

Reply all
Reply to author
Forward
0 new messages