Interpolate counter measurements (manual inputs)

Hi there,

I have some monthly counter measurements stored inside an InfluxDB instance, e.g. data like this (in line protocol):

readings,location=xyz,medium=Electricity,meter=mainMeter energy=13660 1625322660000000000
readings,location=xyz,medium=Electricity,meter=mainMeter energy=13810 1627839610000000000

These are monthly readings, not sharp to the beginning of a month (one is at 3rd of July, the other on 1st of August).

My goal it to interpolate these readings on a daily basis, so I stumbled upon the interpolate.linear function from Flux (https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/interpolate/linear/).

But the only output I can generate with my function returns me the two given data values from my input.

import "interpolate"
from(bucket: "ManualInput")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "readings")
  |> filter(fn: (r) => r["_field"] == "energy")
  |> interpolate.linear(every: 1d)

Am I missing something here? I’ve expected to have a linear interpolated value on each day… or is this not possible with Flux? (I’m using V 2.0.7)

Hello @ralphp,
Welcome! Thanks for your question.
The following worked for me:

import "array"

array.from(rows: [
  {_time: time(v: 1625322660000000000), _field: "exampleField", _value: 3, foo: "bar"},

  {_time: time(v: 1627839610000000000), _field: "exampleField", _value: 4, foo: "bar"}
])
  |> group(columns: ["_field", "foo"], mode:"by")
  |> toFloat()
  |> interpolate.linear(every: 1d)

Using your timestamps. It looks like there some requirements around the type “_value” type and what’s in the group key.

Hello @Anaisdg,

thanks for your answer. From your suggestion I’ve added the “toFloat()” line. This works for me now! I have to double check my datatype, but from the gui it looks like the raw data is of type double.

1 Like

@ralphp,
Great! I’m happy it’s working for you now :slight_smile: