content/flux/v0/stdlib/universe/timeweightedavg.md
timeWeightedAvg() returns the time-weighted average of non-null values in
_value column as a float for each input table.
Time is weighted using the linearly interpolated integral of values in the table.
(<-tables: stream[A], unit: duration) => stream[{B with _value: float, _value: float, _stop: D, _start: C}] where A: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
({{< req >}}) Unit of time to use to compute the time-weighted average.
Input data. Default is piped-forward data (<-).
data
|> timeWeightedAvg(unit: 1s)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 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 | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |
| *_start | *_stop | _value | *tag |
|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 4.166666666666667 | t1 |
| *_start | *_stop | _value | *tag |
|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 5.416666666666667 | t2 |
{{% /expand %}} {{< /expand-wrapper >}}