I am attempting to aggregate data on a daily basis in the specific timezone of the customer. My goal is to create a single record with a time of midnight for each function (mean, min, max, etc) for the selected day, and write this to a new bucket. My plan was to query all the data for the day (or subsection of the day) by specifying the timezone offset in the range function:
baseData = from(bucket: "loradata")
|> range(start: 2021-11-28T09:00:00-05:00, stop: 2021-11-28T21:00:00-05:00 )
|> filter(fn: (r) => r.customer == 23)
Next, I dropped the _start, _stop, and _time columns in order to map all _time fields to midnight of the specified day, as well as set _start and _stop to cover the entire day:
|> drop(columns: ["_start", "_stop", "_time"])
|> map(fn: (r) => ({ r with
_time: time(v: "2021-11-28T00:00:00Z"),
_start: time(v: "2021-11-28T00:00:00Z"),
_stop: time(v: "2021-11-28T23:59:59Z"),
}))
This works as expected, and the resulting data shows with a _time of midnight. The problem I’m seeing comes from the aggregateWindow(fn: mean, every: 24h)
function, which doesn’t seem to recognize the new _time. This often results in multiple records, null values, changed dates, or other problems that prevent the |>to(...)
function from properly writing the aggregated data. I would expect the _time field to be honored, but there is obviously something else going on here. Any idea what may be happening?
Data example before aggregateWindow call
Data example after aggregateWindow call