Hi,
We have been a customer of InfluxDB Cloud v2 for a few years now and have been using it for air quality IoT.
We have encountered an issue with data aggregation that is affecting many of our customers; since we have ~1,000 devices, and customers check daily or monthly numbers, this adds up very quickly.
What we’re trying to do
We want to get averages of data within a selected time window. E.g., a customer wants to see the 8-hour average of PM2.5 dust particles in the air collected from 8th March 2025 at 07:15 India Standard Time (IST) to 9th March 2025 at 07:15 IST.
Expected results
We expect to see 3 data points within the 24-hour period – one for each 8-hour window, namely:
- 8th March 2025 at 15:15 IST
- 8th March 2025 at 23:15 IST
- 9th March 2025 at 07:15 IST
Actual results
We receive the following 4 data points:
- 8th March 2025 at 10:30 IST
- 8th March 2025 at 18:30 IST
- 9th March 2025 at 02:30 IST
- 9th March 2025 at 07:15 IST
What we have tried so far
We tried using the function *timedMovingAverage(every: 8h, period: 8h)*
…
import "timezone"
option location = timezone.location(name: "Asia/Kolkata")
from(bucket:"EVIN")
|> range(start: 1741418100, stop: 1741504500)
|> filter(fn: (r) => r._measurement == "Pollutant")
|> filter(fn: (r) => r._field == "PM2_5")
|> filter(fn: (r) => r.DeviceID == "AirSENCE-062409E640561")
|> timedMovingAverage(every: 8h, period: 8h)
|> yield()
Additionally, we have unsuccessfully tried to replace timedMovingAverage
with:
// Alternate #1 (2 variants - with and w/o timeSrc)
|> aggregateWindow(every: 8h, fn: mean, createEmpty: false [, timeSrc: "_start"])
and with
// Alternate #2
|> window(every: 8h)
|> reduce(fn: (r, accumulator) => ({<get average>}), identity: {count: 0.0, avg: 0.0} )
However, none of these functions work as expected!
Could you please help us create an appropriate query to use a user-defined time window for aggregate operations?
Regards,
George