new here. I have data from all the different states and want to display the total usage in a weekly overview. Here I encounter 2 problems:
- the Sunday is showing 2 times and the data of Thursday is showing on Friday
- Friday shows a usage of 3 days, but if I apply the timerange only on Friday, it shows 1 hour which is correct.
import "array"
import "contrib/tomhollingworth/events"
import "date"
data = from(bucket: "otiv.one_tablet_states")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "tablet_states")
|> filter(fn: (r) => r.client == "${client}" and r.site == "${site}" and r.loc == "${loc}" and r.unit == "${unit}")
|> group(columns: ["client", "site", "loc"])
|> events.duration(unit: 1ms)
|> map(fn: (r) => ({
r with
total_usage: if (contains(value: r._value, set: ["Playing", "WaitingForFirstFrame", "Interrupted", "RouterSubState"])) then float(v: r.duration) else 0.0,
}))
|> filter(fn: (r) => r.total_usage > 0)
|> aggregateWindow(every: 1d, fn: sum, column: "total_usage", createEmpty: true, offset: -2h)
|> keep(columns: ["_time", "total_usage"])
|> rename(columns: {total_usage: "Usage"})
|> yield()