diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index cc7c236..f56ce3f 100755 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import argparse -import numpy as np +import pandas as pd from collections import OrderedDict import os.path @@ -46,39 +46,10 @@ class Power: Assumptions: - data is sorted by timestamp ascending - - for each timestamp, there is the same set of nodes and in the same order """ + df = pd.DataFrame(data, columns=['time', 'node', 'power']) + power = cls.from_pandas(df, columns={}) - idx_ts = 0; idx_node = 1; idx_value = 2 - nodes = list(OrderedDict.fromkeys([line[idx_node] for line in data])) # preserves order of nodes - power = Power(nodes) - - values = {} - for l in data: - ts = l[idx_ts] - if ts not in values: - values[ts] = [] - value = l[idx_value] - values[ts].append(value) - - epochs = values.keys() - for epoch in epochs: - power.insert_epoch(epoch, values[epoch]) - - # check implicit assumptions: 1) ts/epochs are sorted - e = list(epochs) - k = list(values.keys()) - if not e == k: - power.warnings += "# Warning: Unexpected unsorted timestamps.\n" - - # check implicit assumptions: 2) each line has #nodes values - nnodes = len(nodes) - for epoch in epochs: - actual = len(values[epoch]) - if actual != nnodes: - power.warnings += "# Warning: Unexpected number of nodes ({actual}/{expected})\n".format(actual=actual, expected=nnodes) - break - return power @classmethod @@ -124,12 +95,6 @@ class Power: fname = None return fname - - def insert_epoch(self, ts, values): - self.epochs[ts] = values - if not self.first_ts: - self.first_ts = ts - self.last_ts = ts def header(self): hd = "# all timestamp have unit miliseconds since unix epoch\n"