Hi guys,
i do this query
from(bucket: "Solaranlage-Short-Term")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Consumption")
|> filter(fn: (r) => r["host"] == "TotalSelfConsumption")
|> filter(fn: (r) => r["_field"] == "TotalSelfConsumption")
|> aggregateWindow(every: 1d, fn: (tables=<-, column) => tables
|> integral(unit: 1s),
createEmpty: false
)
|> map(fn: (r) => ({ r with _value: r._value / 3600.0 }))
|> filter(fn: (r) => exists r._stop)
|> yield(name: "daily_consumption_kWh")
I would expect to get exactly one data point. But I get two. The second value 23.2566… is the correct one.
I set the time range from 2025-02-02 00:00:00 to 2025-02-02 15:50:54 (The day so far.)
Does anyone have any idea what I am doing wrong?
Cheers
Anaisdg
February 3, 2025, 11:10pm
2
Hello @Nicolas_Lauinger ,
import "array"
data = array.from(rows: [{_time: 2025-02-02T00:00:00Z, _value: 1.0},{_time: 2025-02-02T15:50:54Z, _value: 2.0}])
data
|> range(start: 2025-02-02T00:00:00Z, stop: 2025-02-02T15:50:54Z)
|> aggregateWindow(every: 1d, fn: (tables=<-, column) => tables
|> integral(unit: 1s),
createEmpty: false
)
|> map(fn: (r) => ({ r with _value: r._value / 3600.0 }))
|> filter(fn: (r) => exists r._stop)
|> yield(name: "daily_consumption_kWh")
This worked for me. I’m not sure what’s happening.
This helps explain the behavior of aggWindow()
opened 10:12PM - 19 Aug 19 UTC
closed 01:44AM - 10 Jun 24 UTC
no-issue-activity
When using the `aggregateWindow` function, it will set all the outputted records… `_start` and `_stop` columns to the value set in the `range` function. This behavior differs from that of `window`. `window` sets the `_start`and `_stop` to the start and stop for the window for that particular record. This difference is confusing and doesn't seem like it should be the default.
I propose changing the `_start` and `_stop` values for the outputted columns to the start and stop of an individual row's window. An option can be added to `aggregateWindow` to allow the user to pass in the columns they want the final [`window` function call](https://github.com/influxdata/flux/blob/222b98ef1a9c4ffefc1acedd714c7b1f8f007446/stdlib/universe/universe.flux#L116) to output its `_start` and `_stop` to.
Can you verify that the problem is a range agg window conflict by adding:
from(bucket: "Solaranlage-Short-Term")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Consumption")
|> filter(fn: (r) => r["host"] == "TotalSelfConsumption")
|> filter(fn: (r) => r["_field"] == "TotalSelfConsumption")
|> aggregateWindow(every: 1d, fn: (tables=<-, column) => tables
|> integral(unit: 1s),
createEmpty: false
)
|> yield(name: "after aggwindow")
|> group()
|> yield(name: "after group")
|> map(fn: (r) => ({ r with _value: r._value / 3600.0 }))
|> filter(fn: (r) => exists r._stop)
|> yield(name: "daily_consumption_kWh")
And seeing if there are two tables in the after aggwindow result and if a group fixes it?
This is the result of your query.