got a improved version, only got: Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO weewx.engine: 'pyephem' detected, extended almanac data is available Mär 22 19:39:44 raspberrypi weewxd[4803]: DEBUG weewx.engine: Finished loading service weewx.engine.StdReport Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO __main__: Starting up weewx version 5.1.0 Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO weewx.engine: Clock error is -0.10 seconds (positive is fast) Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO weewx.engine: Using binding 'wx_binding' to database 'weewx.sdb' Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO weewx.manager: Starting backfill of daily summaries Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO weewx.manager: Daily summaries up to date Mär 22 19:39:44 raspberrypi weewxd[4803]: INFO weewx.engine: Starting main packet loop. Mär 22 19:39:46 raspberrypi weewxd[4803]: DEBUG weewx.wxservices: Unknown extensible type 'snow' Mär 22 19:39:49 raspberrypi weewxd[4803]: DEBUG weewx.wxservices: Unknown extensible type 'snow' ~
bwal...@gmail.com schrieb am Samstag, 22. März 2025 um 13:34:28 UTC+1: > Hello i am trying to calculate value snow out of my measured snowDepth. > Using tag .diff gives also negative values and also cant be summed for > month or somthing else. Tried do write xtype but can`t get it running. > anybody have a hint? > > -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/weewx-user/d77ae407-a51a-4d73-b643-a287fb282885n%40googlegroups.com.
import datetime import math import weewx.xtypes import weewx.units from weewx.engine import StdService import weedb import logging log = logging.getLogger(__name__) # Register "snow" with the appropriate unit groups: class XAggsSnow(weewx.xtypes.XType): """ This xtypes extension calculates new snowfall over a fixed 6?hour period, based on the snowDepth data series from the archive. It computes the difference between the average of the last 10 data points and the average of the first 10 data points of the 6?hour interval. The aggregated value is stored under the observation type "snow", so that it can be later used in weekly, monthly, or yearly reports (e.g. $year.snow.sum). """ # Advertise that this extension supports the observation type "snow": supported_types = ['snow'] def __init__(self, engine=None, config_dict=None): # No special initialization is needed pass def get_aggregate(self, obs_type, timespan, aggregate_type, db_manager, **option_dict): fixed_interval = 6 * 3600 # 6 hours in seconds fixed_timespan = type(timespan)(timespan.start, timespan.start + fixed_interval) log.debug("Using fixed 6?hour timespan: %s to %s", fixed_timespan.start, fixed_timespan.stop) try: series = db_manager.get_series("snowDepth", fixed_timespan, aggregate_type=None, aggregate_interval=fixed_interval) except Exception as e: log.exception("Error retrieving series for snowDepth") raise weewx.UnknownType(aggregate_type) if not series or len(series) < 20: log.warning("Not enough data points for 6?hour aggregation: found %s", len(series) if series else 0) new_snow = None else: first10 = [row[1] for row in series[:10] if row[1] is not None] last10 = [row[1] for row in series[-10:] if row[1] is not None] if not first10 or not last10: log.warning("Missing valid data in the first or last 10 records") new_snow = None else: avg_first = sum(first10) / len(first10) avg_last = sum(last10) / len(last10) new_snow = avg_last - avg_first log.debug("Calculated new snow: avg_first=%.2f, avg_last=%.2f, new_snow=%.2f", avg_first, avg_last, new_snow) u, g = weewx.units.getStandardUnitType(db_manager.std_unit_system, "snow", "snow") log.debug("Units: %s, Group: %s", u, g) return weewx.units.ValueTuple(new_snow, u, g) class XAggsService(StdService): """ WeeWX service for initializing the xtypes extension for new snowfall calculation. Add this service to the xtype_services section of your weewx.conf. """ def __init__(self, engine, config_dict): super(XAggsService, self).__init__(engine, config_dict) self.xstats_snow = XAggsSnow(engine, config_dict) weewx.xtypes.xtypes.append(self.xstats_snow) def shutDown(self): weewx.xtypes.xtypes.remove(self.xstats_snow) weewx.units.obs_group_dict['snow'] = "group_rain"