Preserve order of nodes

This commit is contained in:
Jose Gracia 2024-02-12 17:19:50 +01:00
parent f58a6d62ab
commit 87a0f17b28

View file

@ -43,21 +43,19 @@ class Power:
Returns a Power instance from a list of tuples (timestamp, node, value).
Assumptions:
- data is sorted by timestamp first, then by node. Both ascending.
- for each timestamp, there is the same set of nodes.
- data is sorted by timestamp ascending
- for each timestamp, there is the same set of nodes and in the same order
"""
idx_ts = 0; idx_node = 1; idx_value = 2
nodes = list(set([line[idx_node] for line in data]))
nodes = list(OrderedDict.fromkeys([line[idx_node] for line in data])) # preserves order of nodes
cls = Power(nodes)
# for now ignore order to nodes
values = {}
for l in data:
ts = l[idx_ts]
if ts not in values:
values[ts] = []
# node = l[1]
power = l[idx_value]
values[ts].append(power)