Increasing value series: Difference too small

Hi,

I have a series of ever increasing values (energy consumption). Now I want to get the consumption on a daily, weekly or monthly basis. The problem is, that the data is not stored at exactly these boundaries and I am getting small errors at the boundaries. The error is small, but as I want to get for example 30 daily values for 30 consecutive days, or 40 monthly values for 40 consecutive months, the error is getting larger and larger.

Example for one day:

2024-04-01T23:55:00Z  10
2024-04-02T00:02:00Z  13
.....
2024-04-02T23:51:00Z  39
2024-04-03T00:03:00Z  44

I want to get the daily consumption for 2024-04-02. This is not 44 - 13 = 31 nor any other operation on the values above. I think that I need a linear interpolation for the values around midnight, so that I would get some values like:

2024-04-02T00:00:00Z:  12.1
...
2024-04-03T00:00:00Z:  42.75

so that the consumption for this day resolves to 42.75 - 12.1 = 30.65.

Can this be done with Flux? Or how can I get these values?

It is not so important that the interpolation reflects the real world usage (it is not important if it was 12.1 or 12.3 in reality at midnight), but I need a solution so that the error is not getting larger and larger, when I get the daily values for 100 consecutive days.

Without interpolation, the following looks quite good as it does not introduce those small errors:

from(bucket: "default")
  |> range(start: 2024-04-01T00:00:00Z, stop: 2024-04-03T23:59:59Z)
  |> filter(fn: (r) => r["_measurement"] == "Measurement")
  |> aggregateWindow(every: 1d, fn: max)

will output

2024-04-01T00:00:00Z:  10
2024-04-02T00:00:00Z:  39

Taken from: Flux: Get total energy by month with an ever-increasing value - #8 by grant1

1 Like

@_Martin thanks for sharing your solution with the community!