influxdbinfluxdb-2flux-influxdb

Calculate daily average on a sparse data in Flux


I manually enter data every ~1 month into a bucket. I'd like to calculate daily change between the entered numbers and display it on the graph. Seems all the operators are dependent on the data density, so the calculated values are no different than simple difference() between monthly entered values.

Is there a good way to calculate per day difference (daily change) of the entered values? Or in other words the average daily? So basically take difference of two entered values and divide it by number of days between?

enter image description here

This is how yellow line is calculated

from(bucket: "manual-data")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "meter")
  |> filter(fn: (r) => r["_field"] == "value")
  |> difference()

Solution

  • Hmmm... I would try to compute cumulative sum and then calculate derivative. Something like that:

      |> cumulativeSum(columns: ["_value"])
      |> derivative(unit: 1d, nonNegative: true, columns: ["_value"], timeColumn: "_time")