SELECT 1/mean(“price”) AS “mean_price” FROM “feed”.“autogen”.“match” WHERE time > :dashboardTime: AND “pair”=‘ETH-BTC’ GROUP BY time(:interval:) FILL(null)
I believe this should give you what you’re looking for. Flux doesn’t support InfluxDB 1.x template variables, so you’ll have to hard-code the time range and window interval.
The example below queries points from the last minute, windows (groups) them in 5 second intervals, and calculates an average for each window.
It then divides 1 by the result and stores it in the _value
column.
from(bucket: "feed/autogen")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "match" and r.pair == "ETH-BTC")
|> aggregateWindow(every: 5s)
|> map(fn: (r) => ({ r with _value: 1 / r._value}))