There are a few things they could do.
Union and pivot two streams:
|> range(start: -1d)
|> filter(fn: (r) => r._field == "temp")
temp_mean = data |> mean() |> set(key: "_field", as: "temp_mean")
num_points = data |> count |> set(key: "_field", as: "num_points")
union(tables: [temp_mean, num_points])
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
- Use reduce to create a custom aggregate that does both at the same time:
data = from(bucket: "example-bucket")
|> range(start: -1d)
|> filter(fn: (r) => r._field == "temp")
|> reduce(
identity: {num_points: 0, sum:0.0, temp_mean:0.0}
fn: (r) => ({
num_points: accumulator.num_points + 1,
sum: r._value + accumulator.sum,
temp_mean: (accumulator.sum + r._value) / (float(v: num_points + 1))
})
)
|> drop(columns: ["sum"])