Repeated calls to extension.

71 views
Skip to first unread message

Chris Davies-Barnard

unread,
Sep 8, 2020, 3:14:42 AM9/8/20
to weewx-development
Good morning all,

After an extended hiatus I am very happy to have a working and recording weather station again.  Unable to contain myself I am now tinkering with skins, extensions and data on https://davies-barnard.co.uk/

Anyway,  my install of Weewx seems to be making repeated calls to the extension I'm playing around with.  Its quite computational so I want it to run only when required to stay up to date.

skin.conf
search_list_extensions = user.xstats.ExtendedStatistics, user.celestialPatterns.CelestialPatterns
 
[[ToDate]]
...
[[[celestialpatterns]]]
template = celestialPatterns.html.tmpl

My Extension

def get_extension_list(self, timespan, db_lookup):
    print("Extension Called")
 
     #Get the seasons
    seasons = self.getSeasons()

     #Get all the sun/moon rises and sets for 12 months.
     allRiseAndSet = self.getRiseAndSet()
     ...

def getSeasons(self):
    print ("calling getSeasons")
    ....

def getRiseAndSet(self):
    print("Calling getRiseAndSet")
    ...

Is outputing:
daviesc@pecan-ubuntu:/home/weewx$ sudo ./bin/wee_reports weewx.conf
Using configuration file weewx.conf
Generating for all time
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
Extension Called
calling getSeasons
Calling getRiseAndSet
daviesc@pecan-ubuntu:/home/weewx$

I can see this could align with the number of entries under CheetahGenerator but it seems excessive or is it by design?    If someone could enlighten me I would be very grateful.

Thanks again.

Chris





Tom Keffer

unread,
Sep 8, 2020, 10:57:20 AM9/8/20
to weewx-development
I'm not exactly sure what you're asking, but that won't stop me from answering! :-)

The member function get_extension_list() will be called for each template. So, if you have 10 templates, it will get called 10 times. If there is an expensive calculation that does not depend on the timespan that needs to be done, then it is best done in the initializer ('__init__') of your extension.

There are 3 runtime options for extensions:
1. The initializer. Called once per skin.
2. In  get_extension_list(). Called once per template.
3. In the extension tag. Gets called when a '$' tag matches your extension tag.

In general, you want expensive calculations to be done farther up this list. But, if they depend on things only known farther down the list, in particular, a timespan, then you're out of luck.

Hope this helps.

-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/c904e46d-c4ec-4293-90ed-ae1a0b3fba24n%40googlegroups.com.

Chris Davies-Barnard

unread,
Sep 8, 2020, 2:05:43 PM9/8/20
to weewx-development
Hi Tom,

Hope you are well.   

Regardless of whether my question was clear (apologies) your answer is and even better its the answer I needed!   Thanks.

Follow up questions:

1)  So we can assume that any data set in the initializer is available through out the reporting process?

2) This is potentially useful - is there a way to identify which template is being processed at the time?

Thanks again.

Chris

Tom Keffer

unread,
Sep 8, 2020, 6:37:47 PM9/8/20
to Chris Davies-Barnard, weewx-development
1. If you need the data that you set up in the initializer, just assign it to 'self'. Class 'Station', in cheetahgenerator.py, is an example. In this case, the calculation is not expensive, but it's static. So, there's no reason not to bind the information early.

2. Not that I can think of. If you need to do this for some reason, you could try putting whatever logic you need in the template itself.

-tk

Reply all
Reply to author
Forward
0 new messages