Swap order of query output tuple

This commit is contained in:
Jose Gracia 2024-02-07 10:20:13 +01:00
parent ae00b04bbe
commit e73f69f25e

View file

@ -38,18 +38,19 @@ class Power:
@classmethod @classmethod
def from_list(cls, data): def from_list(cls, data):
"""Assumes data is a list of tuples (timestamp, value, node)""" """Assumes data is a list of tuples (timestamp, node, value)"""
nodes = list(set([line[2] for line in data])) idx_ts = 0; idx_node = 1; idx_value = 2
nodes = list(set([line[idx_node] for line in data]))
cls = Power(nodes) cls = Power(nodes)
# for now ignore order to nodes # for now ignore order to nodes
values = {} values = {}
for l in data: for l in data:
ts = l[0] ts = l[idx_ts]
if ts not in values: if ts not in values:
values[ts] = [] values[ts] = []
# node = l[1] # node = l[1]
power = l[1] power = l[idx_value]
values[ts].append(power) values[ts].append(power)
epochs = sorted(values.keys()) epochs = sorted(values.keys())
@ -154,7 +155,7 @@ node_series as(
)] )]
where n.id = any((select nodes from _job)::int[]) where n.id = any((select nodes from _job)::int[])
) )
select a.time, a.value, ns.name from ( select a.time, ns.name, a.value from (
select select
time_bucket(extract ('epoch' from '{interval} seconds'::interval)::int*1000, cmcavg.ts) as time, time_bucket(extract ('epoch' from '{interval} seconds'::interval)::int*1000, cmcavg.ts) as time,
cmcavg.series_id::varchar, cmcavg.series_id::varchar,