Hi,
I’m collecting a machines runtime by recording “start” and “stop” events, each resulting in a single record. I looking for way to transform that type of data so that I can see the daily and hourly runtimes.
I’m currently using events.duration
for converting the start / stop events into rows representing the runtime (a duration) and aggregateWindow
to aggregate on an hourly basis like so:
import "contrib/tomhollingworth/events"
from(bucket: "Heating")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "burner")
|> filter(fn: (r) => r["_field"] == "status")
|> events.duration (unit: 1s, columnName: "duration")
|> filter(fn: (r) => r["_value"] == "running")
|> aggregateWindow(column: "duration", every: 1h, fn: sum)
This basically works but has one drawback: when the machine is running for longer than 1 hour, aggregateWindow
sees a single record for the long duration and is not able to distribute the runtime according to the time frame of 1 hour.
So my question is: is there a way to “split” a row representing a runtime into multiple rows according to some time frame? E.g. a row representing a duration of 3 and a half hour would end up in 4 individual rows, 3 of them carrying a duration of 1 hour while the 4th row has a remaining duration of 30 minutes.