Thanks Tom,

It works now with the new version of xtypes.py and the following image 
definition :

[[other_images]]
        x_label_format = %Y
        bottom_label_format = %x %X
        time_length = 220752000 # 7 years
        aggregate_interval = day
        show_daynight = false
        [[[trol10]]]
          [[[[rol10]]]]
            label = "Température : moyenne glissante sur 10 ans"
            aggregate_type = rolling_avg_years
            val = 10
            data_type = outTemp

> Le 10 oct. 2022 à 03:47, Tom Keffer <[email protected]> a écrit :
> 
> It seems that there is a bug in get_series(). It should pass the option 
> dictionary on to get_aggregate(), but it doesn't. 
> 
> Try this version of xtypes.py.
> 
> Also, note that the value will be passed in as a string. To get a numeric 
> value, you'll have to do
> 
> years = int(option_dict['val'])
> 
> -tk
> 
> 
> 
> On Sun, Oct 9, 2022 at 8:20 AM Jacques Terrettaz <[email protected] 
> <mailto:[email protected]>> wrote:
> :(. it is not working. In that case, in my get_aggregate function,  
> option_dict.get('val') is None 
> 
> 
> 
>> Le 9 oct. 2022 à 17:00, Tom Keffer <[email protected] 
>> <mailto:[email protected]>> a écrit :
>> 
>> Try:
>> 
>>  [[other_images]]
>>         x_label_format = %Y
>>         bottom_label_format = %x %X
>>         time_length = 220752000 # 7 years
>>         aggregate_interval = day
>>         show_daynight = false
>>         [[[trol10]]]
>>           [[[[rol10]]]]
>>             label = "Température : moyenne glissante sur 10 ans"
>>             aggregate_type = rolling_avg_years
>>             val = 10
>>             data_type = outTemp
>> 
>> Although, to tell you the truth, I've never tried this!
>> 
>> -tk
>> 
>> On Sun, Oct 9, 2022 at 6:48 AM Jacques Terrettaz <[email protected] 
>> <mailto:[email protected]>> wrote:
>> Thanks Tom, 
>> 
>> I have modified my extension, and when the aggregate type is used within a 
>> tag such as $day.outTemp.rolling_avg_years(10) it works.
>> 
>> But it is not working with the ImageGenerator.
>> In my extension, I am checking that the aggregate type is 
>> "rolling_avg_year", and if not it will raise a 
>> weewx.UnknownAggregationexception
>> 
>> When using the aggregate type without parameter, with this ImageGenerator 
>> definition :
>> 
>>  [[other_images]]
>>         x_label_format = %Y
>>         bottom_label_format = %x %X
>>         time_length = 220752000 # 7 years
>>         aggregate_interval = day
>>         show_daynight = false
>>         [[[trol10]]]
>>           [[[[rol10]]]]
>>             label = "Température : moyenne glissante sur 10 ans"
>>             aggregate_type = rolling_avg_years10
>>             data_type = outTemp
>> 
>> The image is generated :
>> <trol10_OK.png>
>> 
>> But when using the modified extension accepting a parameter :
>> 
>>  [[other_images]]
>>         x_label_format = %Y
>>         bottom_label_format = %x %X
>>         time_length = 220752000 # 7 years
>>         aggregate_interval = day
>>         show_daynight = false
>>         [[[trol10]]]
>>           [[[[rol10]]]]
>>             label = "Température : moyenne glissante sur 10 ans"
>>             aggregate_type = rolling_avg_years(10)
>>             data_type = outTemp
>> 
>> 
>> I have the following error :
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine: Caught 
>> unrecoverable exception in generator 'weewx.imagegenerator.ImageGenerator'
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****  
>> 'outTemp' or 'rolling_avg_years(10)'
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****  
>> Traceback (most recent call last):
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****    
>> File "/usr/share/weewx/weewx/reportengine.py", line 197, in run
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****     
>>  obj.start()
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****    
>> File "/usr/share/weewx/weewx/reportengine.py", line 385, in start
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****     
>>  self.run()
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****    
>> File "/usr/share/weewx/weewx/imagegenerator.py", line 42, in run
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****     
>>  self.gen_images(self.gen_ts)
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****    
>> File "/usr/share/weewx/weewx/imagegenerator.py", line 109, in gen_images
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****     
>>  self.image_dict[timespan][plotname])
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****    
>> File "/usr/share/weewx/weewx/imagegenerator.py", line 249, in gen_plot
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****     
>>  **option_dict)
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****    
>> File "/usr/share/weewx/weewx/xtypes.py", line 116, in get_series
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****     
>>  raise weewx.UnknownType(msg)
>> 
>> 2022-10-09 15:30:24  weewx[22095] ERROR weewx.reportengine:         ****  
>> weewx.UnknownType: 'outTemp' or 'rolling_avg_years(10)'
>> 
>> 
>> When called by the ImageGenerator, it appears that  the aggregate type 
>> parameter of the get_aggregate function is the full value 
>> "rolling_avg_years(10)" and not the value " "rolling_avg_years". So in that 
>> case it is considered as an unknown aggregation because it is not 
>> "rolling_avg_years" and rejected by my extension.
>> 
>> Is there a special syntax to be used when defining an aggregate type with a 
>> parameter for the ImageGenerator ?
>> 
>> 
>> 
>> 
>>> Le 9 oct. 2022 à 15:07, Tom Keffer <[email protected] 
>>> <mailto:[email protected]>> a écrit :
>>> 
>>> You're on the right track. If you pass in a parameter to an aggregation, it 
>>> appears in "option_dict" in the corresponding get_aggregate() call. If you 
>>> don't name that parameter, it shows up as key "val". So, in your example, 
>>> 
>>> $day.outTemp.rolling_avg_years(10)
>>> 
>>> would result in a call to get_aggregate() that looks like:
>>> 
>>> get_aggregate('outTemp', timespan, 'rolling_avg_years', db_manager, val=10)
>>> 
>>> The value 'val' will contain the appropriate number of years to do the 
>>> rolling average. 
>>> 
>>> Hope that helps.
>>> 
>>> -tk
>>> 
>>> On Sun, Oct 9, 2022 at 5:54 AM [email protected] 
>>> <mailto:[email protected]> <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> Hello,
>>> 
>>> I am writing a Xtype extension providing  a new aggregate type that 
>>> calculates a rolling average of a parameter over years.  
>>> 
>>> I started by defining several different aggregate type for different number 
>>> of years, such as :
>>> 
>>> rolling_avg_years1
>>> 
>>> rolling_avg_years5
>>> 
>>> rolling_avg_years10
>>> 
>>> rolling_avg_years15
>>> 
>>> For exemple :  $day.outTemp.rolling_avg_years10 returns the average 
>>> temperature of the last 3650 days (i.e. 10 years).
>>> 
>>> And it works.
>>> 
>>> But, to allow more flexibility,  I would prefer, if possible,  to have the 
>>> number of years as parameter, such as 
>>> 
>>> rolling_avg_years(10)
>>> 
>>> but I don't know how I could retrieve the parameter in the get_aggregate 
>>> function of my extension.
>>> 
>>> Any help is appreciated,
>>> Thanks
>>> 
>>> -- 
>>> 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 [email protected] 
>>> <mailto:[email protected]>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/weewx-development/c17fbd97-4547-4a36-bfc0-35b10aa3b68bn%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/weewx-development/c17fbd97-4547-4a36-bfc0-35b10aa3b68bn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>> 
>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "weewx-development" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/weewx-development/RyO1T4UFFBk/unsubscribe 
>>> <https://groups.google.com/d/topic/weewx-development/RyO1T4UFFBk/unsubscribe>.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] 
>>> <mailto:[email protected]>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/weewx-development/CAPq0zECGbOo6rT7mNdRFvRQAq6TNmWKZO6NZ7evDA6mvUz925g%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/weewx-development/CAPq0zECGbOo6rT7mNdRFvRQAq6TNmWKZO6NZ7evDA6mvUz925g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>> 
> 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "weewx-development" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/weewx-development/RyO1T4UFFBk/unsubscribe 
> <https://groups.google.com/d/topic/weewx-development/RyO1T4UFFBk/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/weewx-development/CAPq0zEAdazMEO%3DbR1%2BXYEDYm7ccaucL746gjA6zjtyM1iDyvWg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/weewx-development/CAPq0zEAdazMEO%3DbR1%2BXYEDYm7ccaucL746gjA6zjtyM1iDyvWg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> <xtypes.py>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-development/7C47456A-C79F-4240-A0AB-7F67EF76DA36%40gmail.com.

Reply via email to