mazzy
1
I have a time series that increase monotonically that spans an entire day.
During the day this time series is reset.
I would need to get the max value before each reset and the last max value before the end of the day.
I could figure out a function for such task but I’m wondering whether there is something easier or quicker using Flux.
scott
2
There isn’t anything built into Flux currently that will do what you’re looking for, but it’s something that could be done with Flux:
getResets = (tables=<-) => {
resets = tables
|> sort(columns: ["_time"], desc: true)
|> duplicate(column: "_value", as: "tmp")
|> difference(columns: ["tmp"])
|> map(fn: (r) => ({ r with reset: if r.tmp > 0 then true else false }))
|> filter(fn: (r) => r.reset )
|> drop(columns: ["reset", "tmp"])
last = tables |> last()
return union(tables: [resets, last])
|> sort(columns: ["_time"])
}
data |> getResets()