influxdata / influxdata/influxdb
Integral with timeWeightedAvg and stepped line
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
### Discussed in https://github.com/influxdata/influxdb/discussions/24437
Originally posted by **thkoinje** October 31, 2023
I would need to calculate the stepped integrated average of a timerange for compressing data.
In the picture there are several measurements shown as red points.
The orange line I guess is the line used to calculate the timeWeightedAverage of the timerange between 0 and 10.
The green line is the needed line for the calculation.

Calculation:
Timeinterval | Value orange | Value green
-- | -- | --
0-1 | 1,25 | 2
1-2 | 2 | 1
2-3 | 2 | 1
3-4 | 2,5 | 3
4-5 | 3,5 | 2
5-6 | 3,5 | 2
6-7 | 3,5 | 2
7-8 | 4,375 | 5
8-9 | 4,375 | 5
9-10 | 4,375 | 5
Total | 31,375 | 28
Average | 3,1375 | 2,8
Can you please help me to set this up right?
Up to now it is something like:
`
|> aggregateWindow(
every: 1s,
fn: (column, tables=<-) => tables |> timeWeightedAvg(unit: 1s),
createEmpty: false)`
Contributor guide
Research direction
The issue provides a discussion link, a chart, sample values, and an aggregateWindow/timeWeightedAvg snippet, but names no source file or test. Start by reviewing discussion 24437 and reproducing the current query behavior; define the stepped-line semantics and expected result before implementation, with completion shown by a reproducible query and test.
Written by the indexing model from the issue text.
Assessment
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100