I have a series with energy prices, and I can tell that I have two peaks and two dips in prices each day, and more specifically one pair in the hours 00:00-11:00 and one pair in the range 11:00-23:59.
How can I calculate (for example) the spread within these two, different time windows?
I am aware of the hourSelection() function | Flux Documentation
Is it the only way? so something like (untested)
raw = from(bucket: "energy")
|> range(start: _start, stop: _stop)
|> filter(fn: (r) => r._measurement == "€/kWh" and r._field == "current_price")
|> aggregateWindow(every: 1h, fn: last, createEmpty: false)
morning = raw
|> hourSelection(start: 0, stop: 11)
|> aggregateWindow(every: 1d, fn: spread)
afternoon = raw
|> hourSelection(start: 12, stop: 23)
|> aggregateWindow(every: 1d, fn: spread)
union(tables: [morning, afternoon])
However, the daily aggregateWindow
will set the timestamp to the beginning of each day, while I would like to keep the beginning of the two time ranges.
How can I do it better?