timeWeightedAvg() function
The timeWeightedAvg()
function outputs the time-weighted average of non-null records
in a table as a float.
Time is weighted using the linearly interpolated integral of values in the table.
Function type: Aggregate
Output data type: Float
timeWeightedAvg(unit: "_value")
Parameters
unit
Time duration used when computing the time-weighted average.
Data type: Duration
Examples
from(bucket: "example-bucket")
|> range(start: -5m)
|> filter(fn: (r) =>
r._measurement == "cpu" and
r._field == "usage_system"
)
|> timeWeightedAvg(unit: 1m)
Function definition
timeWeightedAvg = (tables=<-, unit) => tables
|> integral(
unit: unit,
interpolate: "linear"
)
|> map(fn: (r) => ({
r with
_value: (r._value * float(v: uint(v: unit))) / float(v: int(v: r._stop) - int(v: r._start))
}))
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, the following resources are available:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.