Timestamp with aggregatewindow function

I want to have the average temperature per day. But when i use the aggregation function it sets the timestamp at the end.
I dont understand why. The average temp of a day with timestamp at 0:00 at the next day doesnt seem to make any sense to me. Wouldnt it be better to have the timestamp at 12:00 because thats the middle of the day?

how do i know where the data comes from later? In my opition i need 2 timestamps. One for the beginning and one for the end.

Or do i have later to shift my axis by -12h to have the point in grafana at the middle of the day?

Hello @user642 Welcome!
Deciding how to bound windows of time is always challenging in the space and there are pros and cons to each.
Some people want a window defined by the start of the day 00:00 others want 24:00 but others also don’t like 24:00 because its techinically in the next day so they really want 23:59. You want 12:00. Every use case is different. I like your idea of having bounds.

the window() funciton gives you start and stop window times

If you query your data from the start of a day and then window() youll get start and stop columns that reflect those window start and stop times.

then you can use an empty |> group() to put all of those windows into one table if you need :slight_smile:

I hope that helps.

I have the same concern as @user642, and I find that the provided link to the window() function does not answer the question. How would I go about getting the queried values to have a timestamp equal to the start of the aggregate window?

For context, I’ve provided the image below that shows a chart with data at irregular intervals (dots), the expected values at a fixed-interval query with interpolation between points, and the results of the query that I’ve been able to cobble together in Flux. The queried points are offset by 5s (the duration of the aggregate window) when compared to the expected values.

To answer my own question, this is doable with the timeShift function:

@Francis There’s a simpler answer to your problem. aggregateWindow() includes a timeSrc parameter that lets you specify the column to use for the output timestamps. By default, this is _stop. You can set it to _start to using the starting boundary of each window as the output timestamp:

//...
    |> aggregateWindow(every: 5s, fn: first, createEmpty: false, timeSrc: "_start")

No need to use timeShift() after aggregateWindow().