Hartmut, on reflection, I recall the discussion in the forum about being
able to use simple expressions in aggregates.

I will try to modify the xtypes facility to accommodate this.

Thanks for reminding me.

-tk

On Sat, Nov 23, 2019 at 9:41 AM Thomas Keffer <[email protected]> wrote:

> Unfortunately, the ImageGenerator does not allow you to use an expression
> as a data type; only type that appear in the schema, or as an xtype.
>
> Defining a new xtype is not terribly hard. It would look something like
> this (NOT TESTED):
>
> File *user/rainet.py*:
>
> import weewx.units
> import weewx.xtypes
>
> class RainET(weewx.xtypes.XType):
>
>     @staticmethod
>     def get_scalar(obs_type, record, db_manager=None):
>
>         if obs_type != 'rain-ET':
>             raise weewx.UnknownType
>
>         rain = record.get('rain')
>         ET = record.get('ET')
>
>         if rain is not None and ET is not None:
>             record['rain-ET'] = rain - ET
>
>     @staticmethod
>     def get_aggregate(obs_type, timespan, aggregate_type, db_manager,
> **option_dict):
>
>         if obs_type != 'rain-ET':
>             raise weewx.UnknownType
>         if aggregate_type != 'sum':
>             raise weewx.UnknownAggregation
>
>         sql = "SELECT SUM(rain - ET) FROM %s WHERE dateTime>? AND
> dateTime<=?;" % db_manager.table_name
>
>         row = db_manager.getSql(sql, timespan)
>
>         if row is not None:
>             value = row[0]
>         else:
>             value = None
>
>         # There is probably a more elegant way of doing this:
>         if db_manager.std_unit_system == weewx.US:
>             unit = 'inch'
>         elif db_manager.std_unit_system == weewx.METRIC:
>             unit = 'cm'
>         else:
>             unit = 'mm'
>
>         vt = weewx.units.ValueTuple(value, unit, 'group_rain')
>         return vt
> # Insert my new class into the xtypes system:
> weewx.xtypes.xtypes.append(RainET())
>
> The final detail is that you have to make sure this file gets run, so that
> the new type will get inserted into the xtypes system. The easiest is to
> import it from a file that you know will get executed before the reporting
> happens.
>
> import user.rainet
>
> -tk
>
>
> On Sat, Nov 23, 2019 at 8:54 AM Hartmut Schweidler <[email protected]>
> wrote:
>
>> this is not a datentype
>> it is an operation rain minus ET
>>
>> At some point here was reported in the forum about it
>>
>> I have graphically compared the two different calculations
>> rain sum minus evaporation water balance
>>
>> but has no relevance anymore
>>
>> gruss Hartmut
>>
>> Am Samstag, 23. November 2019 17:15:56 UTC+1 schrieb Tom Keffer:
>>>
>>> What is type 'rain-ET'? Is it defined in the schemas for bindings
>>> wx_binding and wd_binding?
>>>
>>> If it is not defined, you will get this error. With beta 3, I've
>>> improved the error message.
>>>
>>> -tk
>>>
>>> On Sat, Nov 23, 2019 at 6:15 AM Hartmut Schweidler <[email protected]>
>>> wrote:
>>>
>>>> supplement
>>>>
>>>> Die Auswertung aus zwei Datenbanken scheint so nicht mehr möglich
>>>>
>>>> The evaluation of two databases seems no longer possible
>>>>
>>>> i had in skin.conf
>>>>
>>>>         [[[monthET_rain]]]
>>>>             data_binding = wd_binding
>>>>             [[[[rain_ET]]]]
>>>>                 aggregate_type = cumulative
>>>>                 aggregate_interval = 10800
>>>>                 label = 'Wasser-Verdunstung /'
>>>>             [[[[data]]]]
>>>>                 data_binding = wx_binding
>>>>                 *data_type = rain-ET*
>>>>                 aggregate_type = cumulative
>>>>                 aggregate_interval = 10800
>>>>                 label = 'Wasserbilanz ges.'
>>>>
>>>>
>>>> also the following error  "weewx.UnknownAggregation: sum"  found like
>>>> here
>>>>
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>> reportengine: Caught unrecoverable exception in generator
>>>> 'weewx.imagegenerator.ImageGenerator'
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****  sum
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****  Traceback (most recent call last):
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/reportengine.py", line 202, in
>>>> run
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      obj.start()
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/reportengine.py", line 285, in
>>>> start
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      self.run()
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/imagegenerator.py", line 41, in
>>>> run
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      self.genImages(self.gen_ts)
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/imagegenerator.py", line 180,
>>>> in genImages
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      aggregate_interval=aggregate_interval)
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/xtypes.py", line 77, in
>>>> get_series
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      return xtype.get_series(obs_type, timespan, db_manager,
>>>> aggregate_type, aggregate_interval)
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/xtypes.py", line 126, in
>>>> get_series
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      agg_vt = get_aggregate(obs_type, stamp, do_aggregate,
>>>> db_manager)
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****    File "/home/weewx/bin/weewx/xtypes.py", line 94, in
>>>> get_aggregate
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****      raise weewx.UnknownAggregation(aggregate_type)
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****  weewx.UnknownAggregation: sum
>>>> Nov 21 06:46:33 wetter weewx-weewx[6777] ERROR weewx.reportengine:
>>>>     ****  Generator terminated
>>>>
>>>> --
>>>> 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/5f89788c-37d5-46f2-8750-41b25b2b99fa%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/weewx-development/5f89788c-37d5-46f2-8750-41b25b2b99fa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> 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/1672886f-7237-4e29-95b8-3bf39e5e30b4%40googlegroups.com
>> <https://groups.google.com/d/msgid/weewx-development/1672886f-7237-4e29-95b8-3bf39e5e30b4%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/CAPq0zECt8U676Xgk8dk1w0X-JinujqH%3D3EvjGdwEU3O-5pNVCQ%40mail.gmail.com.

Reply via email to