This commit is contained in:
mantaohuang 2020-07-28 15:04:27 -04:00
parent d914f15957
commit 02bfc93351
2 changed files with 3 additions and 3 deletions

View File

@ -113,7 +113,7 @@ class OManager:
prev_value = value prev_value = value
ping_stat = i["op"].get_ping_stat(lines=lines) ping_stat = i["op"].get_ping_stat(lines=lines)
ping_tas = TimeSeriesAccumulator( ping_tas = TimeSeriesAccumulator(
start_time=now-timedelta(minutes=time_range), end_time=now, n_bins=n_bins) start_time=now-timedelta(minutes=time_range), end_time=now, n_bins=n_bins, alignment=self.monitor_interval)
for line in ping_stat: for line in ping_stat:
time, value = line.split(",") time, value = line.split(",")
time = datetime.utcfromtimestamp(float(time)) time = datetime.utcfromtimestamp(float(time))

View File

@ -23,7 +23,7 @@ class TimeSeriesAccumulator:
def add(self, time, value): def add(self, time, value):
timestamp = time.replace(tzinfo=timezone.utc).timestamp() timestamp = time.replace(tzinfo=timezone.utc).timestamp()
if time < self.start_time or time > self.end_time: if timestamp < self.start_timestamp or timestamp > self.end_timestamp:
return return
idx = int((timestamp - self.start_timestamp)/self.bin_time) idx = int((timestamp - self.start_timestamp)/self.bin_time)
self.data[idx].append(value) self.data[idx].append(value)
@ -46,7 +46,7 @@ class TimeSeriesAccumulator:
if __name__ == "__main__": if __name__ == "__main__":
tsa = TimeSeriesAccumulator(start_time=datetime( tsa = TimeSeriesAccumulator(start_time=datetime(
2020, 7, 27, 23, 0, 0), end_time=datetime(2020, 7, 28, 0, 0, 0), n_bins=2) 2020, 7, 27, 23, 0, 33), end_time=datetime(2020, 7, 28, 0, 0, 43), n_bins=2, alignment=5)
tsa.add(datetime(2020, 7, 27, 23, 15, 0), 1) tsa.add(datetime(2020, 7, 27, 23, 15, 0), 1)
tsa.add(datetime(2020, 7, 27, 23, 45, 0), 2) tsa.add(datetime(2020, 7, 27, 23, 45, 0), 2)
tsa.add(datetime(2020, 7, 27, 22, 45, 0), 3) tsa.add(datetime(2020, 7, 27, 22, 45, 0), 3)