I’ve created the following flux query to try and build many percentiles into one table stream:
import "experimental/array"
// Grab all the wind direction data for the given range
data = from(bucket: "fallen-leaf")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["entity_id"] == "ws2032_28817_wd")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["_measurement"] == "°")
// The percentiles I want to calculate
p = [1,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,99]
// for each percentile, create a table that aggregate the given percentile into one hour windows
percentileTables = p
|> array.map(fn: (x) => {
return (
data
|> aggregateWindow(
column: "_value",
every: 1h,
fn: (column, tables=<-) => tables |> quantile(q: float(v: x)/100.0),
)
|> set(key: "_field", value: "p${x}")
)
})
// Combine the percentiles and pivot them into a column for each percentile
union(tables: percentileTables)
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
When I try to run this query in a Notebook I get the following error:
error calling function "map" @38:12-50:10: pipe parameter value provided to function with no pipe parameter defined
If I change the fn
that is passed to aggregateWindow
to just fn: mean
, the query works, though the data isn’t what I’m looking for. I believe there might be a bug with how the custom function and in-piped argument named tables
is behaving.
Also, I’m open to suggestions if there is a different way to structure this query to get the answer I’m looking for.