Guys, it just dawned on me this morning. If the only way to get context of the row above is fill and you want a increasing delta when it is filling, you need to fill a column with the timestamp of the value you are filling! 
Fully worked out formula:
- Create null values with aggregateWindow
- Duplicate the original value to observe the filling later (just for show)
- Create a new time column to store the original value timestamp
- Fill both the value and the original time column
- Replace the filled values with null when de difference between the timestamp and the original time is greater than the threshold.
import "internal/debug"
THRESHOLD = 30m
from(bucket: "ProcessLog")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(<your filter here>)
|> keep(columns: ["_time", "_measurement","_field","_value"])
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: true)
|> duplicate(column: "_value", as: "original_value")
|> map(fn: (r) => ({ r with original_time: if exists r._value then r._time else debug.null() }))
|> fill(column: "_value", usePrevious: true)
|> fill(column: "original_time", usePrevious: true)
|> map(fn: (r) => ({ r with delta: int(v: r._time) - int(v: r.original_time) }))
|> map(fn: (r) => ({ r with timeout: if r.delta > int(v: THRESHOLD) then true else false }))
|> map(fn: (r) => ({ r with _value: if r.timeout then debug.null() else r._value }))
|> keep(columns: ["_time", "_measurement","_field","_value"])
|> yield(name: "mean")
If there were any future development on flux, this whole ordeal should be wrapped up in the builtin fill function.
|> fill(usePrevious: true, threshold: 30m)
While I am at it, might as wel make an example function:
import "internal/debug"
fillWithThreshold = (tables=<-, threshold) => tables
|> map(fn: (r) => ({ r with original_time: if exists r._value then r._time else debug.null() }))
|> fill(column: "_value", usePrevious: true)
|> fill(column: "original_time", usePrevious: true)
|> map(fn: (r) => ({ r with _value: if int(v: r._time) - int(v: r.original_time) > int(v: threshold) then debug.null() else r._value }))
|> drop(columns: ["original_time"])
Usage:
|> fillWithThreshold(threshold: 5m)
Can I store this function on my server so I can reuse in each query?
Many thanks @Anaisdg and @scott to think with me on this topic!