hpsjakob
hpsjakob

Reputation: 1

Integral over window in influx boundary issue

I'm aggregating data of one day with Influx Flux. My data is written every 5 mins.

I realized that the sum of two 12h window integrals != one 24h integral which is not correct.

Here is my query:

    from(bucket: "my-data")
      |> range(start: 2025-01-13T00:00:00Z, stop: 2025-01-14T00:00:00Z)
      |> filter(fn: (r) => r["_measurement"] == "datapoint")
      |> filter(fn: (r) => r["_field"] == "test")
      //|> interpolate.linear(every: 1s)
      |> window(every: 12h, offset: 0s)
      |>integral(unit: 1h)

I believe the problem are the gaps that are created by the window method. To illustrate that I only run the window function:

    from(bucket: "my-data")
      |> range(start: 2025-01-13T00:00:00Z, stop: 2025-01-14T00:00:00Z)
      |> filter(fn: (r) => r["_measurement"] == "datapoint")
      |> filter(fn: (r) => r["_field"] == "test")
      |> window(every: 12h, offset: 0s)

In the result you see a gap between the two series.

You can find the graph here: https://ibb.co/fdV56V3x

That is cause because my data only has a 5 min resolution.

To confirm this theory, I up sampled my data:

    import "interpolate"
    from(bucket: "my-data")
      |> range(start: 2025-01-13T00:00:00Z, stop: 2025-01-14T00:00:00Z)
      |> filter(fn: (r) => r["_measurement"] == "datapoint")
      |> filter(fn: (r) => r["_field"] == "test")
      |> interpolate.linear(every: 1s)
      |> window(every: 12h, offset: 0s)
      |>integral(unit: 1h)

That minimizes the gap. Now the sum of the two integrals match the 24h integral.

However, I don't like the solution as it seems inefficient to me. Does someone know a better way to solve this?

I think it would be ideal to have an window function that interpolates a datapoint at the window borders.

Upvotes: 0

Views: 9

Answers (0)

Related Questions