def tsa_group_by(tsa, datestring, index_keynames, group_func, interval): """ group given tsa by subkeys, and use group_func to aggregate data the individual timeseries are automatically grouped by timestamp and interval defined in configuration parameters: tsa <TimeseriesArray> datestring <str> datestring to use to aggregate data TODO: get this from tsa subkey <tuple> could also be empty, to aggregate everything group_func <func> like lambda a, b : (a + b) / 2 to get averages interval <int> interval in seconds the timeseries values should appear returns: <TimeseriesArray> """ # intermediated tsa tsa2 = TimeseriesArray(index_keynames=index_keynames, value_keynames=tsa.value_keynames, ts_key=tsa.ts_key, datatypes=tsa.datatypes) start_ts, _ = DataLogger.get_ts_for_datestring(datestring) ts_keyname = tsa.ts_key for data in tsa.export(): # align timestamp nearest_slot = round((data[ts_keyname] - start_ts) / interval) data[ts_keyname] = int(start_ts + nearest_slot * interval) tsa2.add(data, group_func) return tsa2
def test_export(self): print("testing export, add") tsa = TimeseriesArray(meta["index_keynames"], meta["value_keynames"], "ts", datatypes=meta["value_keynames"]) for entry in self.app.export(): tsa.add(entry) assert tsa == self.app
def load_tsa_raw(self): """ read data from raw input files and return TimeseriesArray object parameters: datestring <str> isodate representation of date like 2015-12-31 timedelta <int> amount second to correct raw input timestamps returns: <TimeseriesArray> object wich holds all data of this day """ tsa = TimeseriesArray(self.index_keynames, self.value_keynames, datatypes=self.datatypes) for rowdict in self.__read_raw_dict(): try: tsa.add(rowdict) except ValueError as exc: logging.exception(exc) logging.error("ValueError by adding this data to TimeseriesArray: %s", rowdict) raise exc except AssertionError as exc: logging.exception(exc) logging.error("AssertionError by adding this data to TimeseriesArray: %s", rowdict) raise exc return tsa