influxdata / flux

Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.
https://influxdata.com
MIT License
769 stars 153 forks source link

[Fix]: Integral calculation #5468

Closed Nocccer closed 7 months ago

Nocccer commented 8 months ago

Description

The current integral function with interpolate is not working if points are in between the time range. The first point and the last point are wrong calculated. This is a big problem in the IoT world where devices send data based on events and not in a defined time interval. Even if they send it in an interval, this time is mostly not realtime, so timestamp have some time difference to the actual configured interval.

Lets asume we have two points:

And a time Range:

With the current integral and interpolate: true this leads to false calculations especially if you use the timeWeightedAvg which is based on integral. Interpolate und Time old

By stretching the first point to the start of the time range and the last point to the stop of the time range, we get a more precized integral: Interpolate und Time

With interpolate:false we get the following: Step und Time

This PR adds this solution to the integral function.

Open Discussion:

Checklist

Dear Author :wave:, the following checks should be completed (or explicitly dismissed) before merging.

Dear Reviewer(s) :wave:, you are responsible (among others) for ensuring the completeness and quality of the above before approval.

Nocccer commented 8 months ago

Related tickets:

helenosheaa commented 7 months ago

Thank you for your contribution! There is a community owned fork of Flux that would be a great place to open this PR. More context:

We are still supporting Flux, but are not doing active development on it or adding any new features to it. We still do security patches and will address any critical defects through the maintenance period. Our focus now is on features related to our latest database engine, InfluxDB 3.0, and its associated products (Cloud Serverless, Cloud Dedicated, Clustered, Edge).

default-student commented 2 months ago

I would argue that this is a critical defect with the integral function...