Hi, I have data of the states of my application with a timestamp of when the state starts. Some states transitions are not wanted and I want the find these. To compare the subsequent states I have to get the “next” state. Is there a way to duplicate the column with the states and shift these by 1 timestamp?
The timestamps are irregular so I cannot use TimeShift().
In this codesnippet I take the duration if it is in the Interrupted state. but if the next state is an unwanted state, the Interrupted state also needs get get dropped.
import "array"
import "contrib/tomhollingworth/events"
data = from(bucket: "tablet_states")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "tablet_states")
|> events.duration(unit: 1ms)
|> map(fn: (r) => ({
r with
data_val: if ((contains(value: r._value, set: ["Interrupted"])) and r.duration < 5000) then 1 else 0, }))
|> keep(columns: ["_time", "data_val"])
Thanks for the help
Hello @Toon_Peters,
Absolutely!
You can use these functions
And the timeShift function assuming your data is regular:
Ps what are you doing with InfluxDB? i love learning about community usecases. Thank you!
Hello @Anaisdg.
Thanks for the quick reply.
My problem is that I do not want to add a fixed timeshift to my column, but just 1 position. The intervals between each row are irregular.
I am using InlfuxDB in Grafana to get the usage of an application from a state diagram.
Hello @Toon_Peters,
Ahh yes okay…hmm there isnt a way to shift based off of position.
You could hack this though.
import "array"
data = array.from(rows: [{_time: 2020-01-01T00:00:00Z, _value: "foo"},{_time: 2020-01-02T00:00:00Z, _value: "bar"}, {_time: 2020-01-03T00:00:00Z, _value: "baz"}])
data1 = data
|> map(fn: (r) => ({ r with index: 1 }))
|> cumulativeSum(columns: ["index"])
data2 = data
|> map(fn: (r) => ({ r with index: 1 }))
|> cumulativeSum(columns: ["index"])
|> map(fn: (r) => ({ r with index: r.index + 1 }))
// |> yield()
join(tables: {key1: data1, key2: data2}, on: ["index"], method: "inner")