See also https://groups.google.com/g/weewx-user/c/7N-1L10kV8Y/m/qFZbPMA5BgAJ
Karen K schrieb am Samstag, 19. Dezember 2020 um 11:50:17 UTC+1: > I have tried to program for myself for the last few days. And I included > the function into the uploader that needs the value. So, when the new year > starts, we will see, wether it works. > > At the start of weewx the value ist calculated up to the actual day. It is > saved within the thread class of the uploader. After that, once a day the > value is updated according to the temperature average of the last day. > > def calc_gts(self,time_ts,dbmanager): > """calculate Grünlandtemperatursumme GTS""" > > # needed timestamps > _sod_ts = weeutil.weeutil.startOfDay(time_ts) # start of day > _soy_ts = weeutil.weeutil.archiveYearSpan(time_ts)[0] # start of year > _feb_ts = _soy_ts + 2678400 # Feb 1 > _mar_ts = _feb_ts + 2419200 # Mar 1 (or Feb 29 in leap year) > _end_ts = _mar_ts + 7948800 # Jun 1 (or May 31 in leap year) > > # initialize if program start or new year > if self.last_gts_date is None or self.last_gts_date < _soy_ts: > self.last_gts_date = _soy_ts > self.gts_value = None > self.gts_date = None > loginf("GTS initialized %s" % > time.strftime("%Y-%m-%d", > time.localtime(_soy_ts))) > > # calculate > # This runs one loop for every day since New Year at program > # start and after that once a day one loop, only. After May 31th > # no loop is executed. > _loop_ct=0 > while self.last_gts_date < _sod_ts and self.last_gts_date < _end_ts: > # the day the average is calculated for > _today = TimeSpan(self.last_gts_date,self.last_gts_date+86400) > # calculate the average of the outside temperature > _result = > weewx.xtypes.get_aggregate('outTemp',_today,'avg',dbmanager) > # convert to centrigrade > if _result is not None: > _result = weewx.units.convert(_result,'degree_C') > # check condition and add to sum > if _result is not None and _result[0] is not None: > if self.gts_value is None: > self.gts_value=0 > _dayavg = _result[0] > if _dayavg > 0: > if self.last_gts_date < _feb_ts: > _dayavg *= 0.5 > elif self.last_gts_date < _mar_ts: > _dayavg *= 0.75 > self.gts_value += _dayavg > if self.gts_value >= 200 and self.gts_date is None: > self.gts_date = self.last_gts_date > > # next day > self.last_gts_date += 86400 > _loop_ct+=1 > > loginf("GTS %s, %s loops" % (self.gts_value,_loop_ct)) > > >>> -- 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 on the web visit https://groups.google.com/d/msgid/weewx-user/8b764974-5a2e-4e3c-a4ca-435080d3833dn%40googlegroups.com.