Doing calculations based on the aggregate window timeframe

Hello,
I need to do some calculations based on the UPS load to determine Watts consumed in a specific timeframe, in particular the “aggregate window”. UPS load % data are being gathered through the nut-server package, then I wanna convert this number into Watts based on:

  • UPS power rating (900W);
  • the choosen aggregate window, which could be Auto or Manual.
    The UPS load % is calculated as mean during that timeframe, then it must be converted in Watts.

I tried to do some tests before doing the Watts calculation, with the following code:

factor = float(v: int(v: v.windowPeriod) / 1000000000 )

// number of seconds in an hour
seconds_in_1h = float(v: 60 * 60)

// determine the fraction of hour based on v.windowPeriod
fraction_hour = float(v: factor / seconds_in_1h)

// UPS power rating in Watts per hour
power_rating = float(v: 900)

from(bucket: "cyberpower_ups")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "nutgraf_ups_data")
  |> filter(fn: (r) => r["_field"] == "ups.load")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({ r with _value: factor }))
  //|> map(fn: (r) => ({ r with _value: float(v: r._value * power_rating * fraction_hour / 100.0) }))
  |> yield(name: "mean")

In the data explorer, when I keep the aggregate window in AUTO, I get the right count of seconds. As seen below, the interval between data is 30 minute and the “_value” field shows 1800 (seconds). So far so good.

The 30-minute interval is based on the window time chosen (7 days). What if I choose the same window time (7 days), but I wanna aggregate in a different timeframe other than the Auto? For instance, 10 minutes instead 30 minutes? The issue kicks-in.

When I force the aggegrate window setting with a manual value, e.g. 10m, I don’t get 600 seconds in the field “_value”, but it keeps 1800 secs.

Doing so, the watts calculation will be wrong because I would calculate the avg. load % of a 10 minute timeframe for 0,5 (1800 seconds are half an hour, not 1/6 as it is 10 minutes).

I am sure to be wrong in something, could you suggest me a way to complete this task?
Many thanks.

Riccardo

Hello @Ricky99,
Hmm I’m not even able to use the window period outside of the range function.
For me it felt related to this issue:

I know that’s not very helpful but new features aren’t being added to Flux right now. Flux is in maintenance mode so I don’t know if this will be addressed.