Grünlandtemperatursumme (GTS)

212 views
Skip to first unread message

Karen K

unread,
Feb 13, 2021, 4:01:38 PM2/13/21
to weewx-development
This refers to 

I tried to write an XType extension for that. There are no error messages, but the value is not known to the record. The loop and archive record do not include a value called "GTS" or "GTSdate".

I created a skin for testing, that includes the some simpley values, only. The result is shown in "index.html". I do not understand the result. 

The log says:
Feb 13 20:45:32 LokalWiki weewx[541598] DEBUG weewx.engine: Loading service user.GTS.GTSType
Feb 13 20:45:32 LokalWiki weewx[541598] DEBUG weewx.engine: Finished loading service user.GTS.GTSType

It seems to me, that the extension is not called at all. I have no clue so far.
GTS.py

Karen K

unread,
Feb 13, 2021, 4:03:23 PM2/13/21
to weewx-development
test skin

skin.conf

Karen K

unread,
Feb 13, 2021, 4:04:36 PM2/13/21
to weewx-development
test skin index.html.tmpl

index.html.tmpl.txt

Karen K

unread,
Feb 13, 2021, 4:05:29 PM2/13/21
to weewx-development
And the cheetah generator's result is

Karen K schrieb am Samstag, 13. Februar 2021 um 22:04:36 UTC+1:
test skin index.html.tmpl

index.html

Tom Keffer

unread,
Feb 13, 2021, 5:37:58 PM2/13/21
to Karen K, weewx-development
Good start! 

I can see a few issues here.

1. All xtype extensions must be registered, otherwise the system has no way of knowing of their existence. See the section Registering your subclass for how to register your xtype.

2. From what I can tell, your extension only returns a value for 'GTSdate', never for 'GTS'.

3. I don't quite follow the logic of the loop in get_scalar(), but it looks like it is trying to keep a running total of something. Just a warning: this could be very inefficient because an xtype can potentially get called many times in a template. Would it be possible to refactor into a database query?



--
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/1f9090b4-308a-4029-9d84-fcfba0229171n%40googlegroups.com.

Karen K

unread,
Feb 14, 2021, 1:29:25 PM2/14/21
to weewx-development
Oh, so I mixed it up some way. I registered the XType as a service. 

Now there are two different classes, and that looks a lot better. The extension calculates the values and draws a graph. Thank you for your advice. It saved a lot of time.

$current.GTS displays a value now. $day.GTS and $yesterday.GTS do not. 
monthGTS.png
GTS.py

Tom Keffer

unread,
Feb 14, 2021, 1:33:00 PM2/14/21
to Karen K, weewx-development
To show a value for yesterday, the value would have to be in the database. 

Karen K

unread,
Feb 14, 2021, 3:55:10 PM2/14/21
to weewx-development
"Mostly the problem is situated between the chair and the screen." I should read the documentation more carefully.

$day and $yesterday need some aggregation. So it is not possible to write $day.GTS or $yesterday.GTS because the aggregation type is missing. Instead it is necessary to write $day.GTS.last or $yesterday.GTS.last or something. And then there is a value, even without having the values in the database. Providing the get_aggregate() function is sufficient.

And in this extension all the values are based on outTemp, and outTemp is included in the database.

Karen K

unread,
Feb 16, 2021, 4:26:11 PM2/16/21
to weewx-development
Another question: Is it possible that cheetah generator and image generator call the XType extension in parallel from different threads?

If so, I guess, locking would be needed for code that alters class attributes.

Tom Keffer

unread,
Feb 16, 2021, 4:45:42 PM2/16/21
to Karen K, weewx-development
Yes, this is a concern if attributes are not read-only. The wiki article on xtypes has a section about this: https://github.com/weewx/weewx/wiki/WeeWX-V4-user-defined-types#subtlety

Karen K

unread,
Feb 17, 2021, 2:31:21 AM2/17/21
to weewx-development
Thank you for clarification. I tried:

try:
    self.lock.acquire()
    [... (some code to calculate and change class attributes)]
finally:
    self.lock.release()

And I hope, that deals with that problem.

Karen K

unread,
Feb 18, 2021, 11:38:58 AM2/18/21
to weewx-development
My XType extension is working in principle now. It calculates, and it delivers values, if there is $current.GTS, $latest.GTS, $day.GTS or $yesterday.GTS included in the skin definition. Also, images are generated showing the value over time. All is fine so far.

Then I included the value in the Belchertown skin observation list. And I got an error message. It turned out, that it is possible that get_scalar() is called with record is None. From documentation I thought otherwise. That was confusing.

As I included "if record is None: raise weewx.CannotCalculate(obs_type)" into get_scalar() no error message was logged any more. But no value was displayed in Belchertown skin. Again: if I include "$current.GTS" into the skin, the value is displayed. If I include the value in the observation list in skin.conf, it is not. I looked around and found out that Belchertown skin gets the value from calling weewx.tags.CurrentObj()within their special extension "belchertown.py" That seems to not include GTS value.

So I am not sure what to do next.

Tom Keffer

unread,
Feb 18, 2021, 11:51:45 AM2/18/21
to weewx-development
Hi, Karen. Looks like you are making steady progress.

This is a bug in the Belchertown skin that I alluded to in another thread.

In a convoluted way, the skin is asking for a value from xtypes using the call 

xtype.get_scalar(obs_type, record, db_manager)

(Side note: the actual request is done through a getattr() query of a weewx.tags.CurrentObj object). 

Unfortunately, the value for record as provided by the Belchertown skin is None. In theory, the xtypes extension could look up the values it needs from the database, but that would require knowing the time, but with record equal to None, that's not possible either.

The Belchertown skin needs to provide the current record.





--
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.

Karen K

unread,
Feb 18, 2021, 1:18:14 PM2/18/21
to weewx-development
Thank you for your extensive support! 

Could it be, that get_scalar() in other classes (especially in the basic ones) simply provide the last available value, if record is None?

I could code it that way, but I am not sure, whether it is a good idea or not.

Tom Keffer

unread,
Feb 18, 2021, 1:25:48 PM2/18/21
to Karen K, weewx-development
That's one solution, but it has lots of dangers. The record could be hours old.

NB: if you want to do that, it's easy enough to code up a custom version of get_scalar() that does this. If it detects a record of None, it gets the latest record from the database, then calls weewx.xtypes.get_scalar() with that.


Karen K

unread,
Feb 18, 2021, 3:42:24 PM2/18/21
to weewx-development
Hi Tom, you are right. I changed the code that it returns the last value if record is None, and immediately Belchertown skin shows the value.

I considered your comments about dangers by comparing the timestamp of the last value with the actual time time.time(). If the value is too old an error is raised rather than a value returned. And I let the program complain to the log, that record is None.

Karen K

unread,
Feb 18, 2021, 4:31:27 PM2/18/21
to weewx-development
I filed an issue for the record-is-None-problem there: #583

Karen K

unread,
Feb 20, 2021, 11:08:47 AM2/20/21
to weewx-development
That is, how it is now (install.py not tested by now): https://github.com/roe-dl/weewx-GTS

Karen K

unread,
Feb 22, 2021, 11:42:43 AM2/22/21
to weewx-development
Hallo Tom, to give the user some instructions I wrote a README file describing how to install and include the extension in skins. Do you think it is enough and to understand?

Karen K

unread,
Feb 25, 2021, 3:20:41 PM2/25/21
to weewx-development
There was a problem with an umlaut in install.py. I replaced 'ü' by 'ue' and hope that helps. See issue #1
Reply all
Reply to author
Forward
0 new messages