Use tags in Python extension code?

74 views
Skip to first unread message

nfbarg...@gmail.com

unread,
Dec 17, 2023, 6:38:32 PM12/17/23
to weewx-development
This likely has everything to do with my lack of Python acuity than WeeWX.

When obtaining values for a user extension that does not have an associated skin so I am not using the Cheetah Generator, how might I call into the tag system to get the data such as 'trend.barometer'?  in cheetahgenerator.py I see the Stats class that looks like it should be what should be called but I don't see it subclassed anywhere but is part of 'default_search_list'.

Primarily I am interested in 'trend.barometer' and 'day.rain'.  The rest I am getting from the latest archive record.  I've not found any extensions that use the tag system like this that I can be inspired by so I am asking the experts.

TIA

- Nate

Tom Keffer

unread,
Dec 24, 2023, 8:39:34 PM12/24/23
to nfbarg...@gmail.com, weewx-development
In order to do this, a lot of infrastructure has to be in place. Take a look at the test file test_daily.py, function testTags (line 206).

It sets up a TimeBinder object (line 222). Once you have that, you can do things like

    print(tagStats.trend.barometer)

For many of these aggregates, you can use the xtypes system, which is a lot simpler to access. For example, to get the day's rain

    val_tuple = xtypes.get_aggregate('rain', timespan, 'sum', db_manager)

where timespan is the start/stop times over which the aggregation is to be taken, and db_manager is an open database manager object. It returns a ValueTuple.

If you're not a Python programmer, it's going to be tough. :-(

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/b4a1b9d6-2e1e-4132-8731-477c2d6018f8n%40googlegroups.com.

nfbarg...@gmail.com

unread,
Dec 25, 2023, 1:49:44 PM12/25/23
to weewx-development
Thanks, Tom.

I appreciate the tips.  Right now I am issuing SQL statements directly into the 'archive' and 'archive_day_rain' tables
for the barometer trend and day rain values.  This works as the access only occurs with each new record.

My basic understanding of Python is fine, it's all of the abstraction through the various classes where I tend to get lost.
Still this little project of mine has helped me immensely as it has given me a reason to understand the WeeWX internals
much better and the way an object oriented project ties together.

- Nate

Joel Bion

unread,
Dec 25, 2023, 3:02:06 PM12/25/23
to nfbarg...@gmail.com, weewx-development
Indeed! I share your appreciation for Weewx as a Python example. I’m retired, so didn’t have a “need” to learn Python, but did object oriented programming in Smalltalk and then C++ a long while ago, but ended up entering the management track, for good or ill. Nearing retirement, I set up WeeWX on an at-home server, and slowly used it as one of the examples to teach me Python, along with fail2ban and a couple of other things. I don’t say I am fluent in the language as I reserve that term for when I’ve built a multi-source file program “package” totaling thousands of lines, but I’ve grown quite comfortable editing source code for my particular unusual circumstances that are not generalizable - like tying in my sprinkler system to rain totals and soil moisture levels, etc. 



Sent from my iPhone
On Dec 25, 2023, at 10:49 AM, nfbarg...@gmail.com <nfbarg...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages