From this query, i want to
add some fields:
import "join"
first = from(bucket: "ad")
|> range(start: 2023-01-01T00:00:00Z, stop: 2023-12-31T23:59:59Z)
|> filter(fn: (r) => r["_measurement"] == "heatConsumption")
|> filter(fn: (r) => r["_field"] == "kwh")
|> first()
|> drop(columns: ["_start","_stop", "_measurement"])
last = from(bucket: "ad")
|> range(start: 2023-01-01T00:00:00Z, stop: 2023-12-31T23:59:59Z)
|> filter(fn: (r) => r["_measurement"] == "heatConsumption")
|> filter(fn: (r) => r["_field"] == "kwh")
|> last()
|> drop(columns: ["_start","_stop", "_measurement"])
join.left(
left: first,
right: last,
on: (l, r) => l.Device == r.Device,
as: (l, r) => ({_time: 2023-12-31T23:59:59Z, Device: l.Device, _field: r._field, _value: r._value - l._value}),
)
|> yield(name: "mean")
Result:
ad@lnx:/mpeg/prj/influxdb$ influx query <consumption.flux
Result: mean
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
EG kwh 2023-12-31T23:59:59.000000000Z 2788
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
G1 kwh 2023-12-31T23:59:59.000000000Z 629
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
G2 kwh 2023-12-31T23:59:59.000000000Z 1231
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
HK_EG kwh 2023-12-31T23:59:59.000000000Z 1120
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
HK_G12 kwh 2023-12-31T23:59:59.000000000Z 1869
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
KE kwh 2023-12-31T23:59:59.000000000Z 0
Table: keys: [Device, _field]
Device:string _field:string _time:time _value:float
---------------------- ---------------------- ------------------------------ ----------------------------
SUT kwh 2023-12-31T23:59:59.000000000Z 1608
Now i want to have a result table with
EG_Total = EG.kwh + HK_EG.kwh
and
G1_Total = G1.kwh + HK_G12 * 0.4
G2_Total = G2.kwh + KH_G12 * 0.6
KE_Total = KE.kwh
SUT_Total = SUT.kwh
no clue how to do that, any help really appreciated.
Thx