I collect kW data with peak measurements around every 1-5 seconds.
My current solution is, to “mean” aggregate hourly (in order to come up with a meaningful representation of kWh (for the hour).
I now aim to representing accumulated “positive” kWh values from that aggregation,
but the cumulated sum needs to reset to 0 at midnight.
here is what I have so far:
from(bucket: “default”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “power”)
|> filter(fn: (r) => r[“tag”] == “isv”)
|> filter(fn: (r) => r[“_field”] == “p1” or r[“_field”] == “p2” or r[“_field”] == “p3” or r[“_field”] == “p4” or r[“_field”] == “p6” or r[“_field”] == “p5”)
|> drop(columns: [“tag”, “topic”, “host”, “_measurement”, “result”])
|> map(fn: (r) => ({r with _value: r._value * -1.0}))
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
// group by time to isolate the values you want to sum together
|> group(columns: [“_time”], mode:“by”)
|> sum(column: “_value”)
// to ungroup your data, provide a group without any columns
|> group()
|> yield(name: “grid difference”)