I am quite new at flux language, and I have a question:
I have a simple dataset with just one value.
I am using a window to aggregate by a chosen interval and store the result in a table variable like this:
val=from(bucket: "myBucket") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == "myMeasurement") |> drop(columns:["_measurement"]) |> window(every: 5m)
Then, I can use significant functions for me, like min, max, mean and stddev like this:
minval=val |> min() |> set(key: "_field", value: "min") maxval=val |> max() |> set(key: "_field", value: "max") avgval=val |> mean() |> set(key: "_field", value: "avg") sdval=val |> stddev() |> set(key: "_field", value: "stddev")
And to finish, I can concatenate all of this, polish up the windowing and make a nice representation:
union(tables: [minval, maxval, avgval, sdval]) |> duplicate(column: "_stop", as: "_time") |> drop(columns:[ "_start", "_stop"]) |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
Now, I would like to calculate two different stddevs, the one above the mean, and the one under, like described there: https://jdmeducational.com/1-2-or-3-standard-deviations-above-or-below-the-mean/
It seems easy, all would need is something like this:
lowsdval=val |> filter(fn: (r) => r._value < MEAN) |> stddev()
I am very new to flux, and I did not find the way to do that (it is probably super simple).
I can do it easily with a constant like this (assuming the mean value is 50):
lowsdval=val |> filter(fn: (r) => r._value < 50) |> stddev()
Now, how can I achieve this with the value of the mean of the current window? It is even already calculated in the avgval table, so I suppose I just need to extract it from it with some syntax I missed.
Thank you in advance for any help or hint.