title |
description |
aliases |
menu |
weight |
flux/v0.x/tags |
related |
introduced |
timeWeightedAvg() function |
The `timeWeightedAvg()` function outputs the timeWeightedAvg of non-null records as a float. |
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timeweightedavg/ |
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/aggregates/timeweightedavg/ |
|
flux_0_x_ref |
name |
parent |
timeWeightedAvg |
universe |
|
|
102 |
aggregates |
transformations |
|
/flux/v0.x/stdlib/universe/integral/ |
|
0.83.0 |
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.
timeWeightedAvg()
is an aggregate function.
Output data type: Float
timeWeightedAvg(unit: 1m)
Parameters
unit
({{< req >}})
Time duration used when computing the time-weighted average.
tables
Input data.
Default is piped-forward data (<-
).
Examples
{{% flux/sample-example-intro %}}
import "sampledata"
data = sampledata.int(includeNull: true)
|> range(start: sampledata.start, stop: sampledata.stop)
|> fill(usePrevious: true)
|> unique()
data
|> timeWeightedAvg(unit: 1s)
{{< expand-wrapper >}}
{{% expand "View input and output" %}}
Input data
_start |
_stop |
_time |
tag |
_value |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:00Z |
t1 |
-2 |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:20Z |
t1 |
7 |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:50Z |
t1 |
4 |
_start |
_stop |
_time |
tag |
_value |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:00Z |
t2 |
|
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:10Z |
t2 |
4 |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:20Z |
t2 |
-3 |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:30Z |
t2 |
19 |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
2021-01-01T00:00:50Z |
t2 |
1 |
Output data
_start |
_stop |
tag |
_value |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
t1 |
4.166666666666667 |
_start |
_stop |
tag |
_value |
2021-01-01T00:00:00Z |
2021-01-01T00:01:00Z |
t2 |
5.416666666666667 |
{{% /expand %}}
{{< /expand-wrapper >}}