content/flux/v0/stdlib/universe/elapsed.md
elapsed() returns the time between subsequent records.
For each input table, elapsed() returns the same table without the first row
(because there is no previous time to derive the elapsed time from) and an
additional column containing the elapsed time.
(<-tables: stream[A], ?columnName: string, ?timeColumn: string, ?unit: duration) => stream[B] where A: Record, B: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Unit of time used in the calculation. Default is 1s.
Column to use to compute the elapsed time. Default is _time.
Column to store elapsed times in. Default is elapsed.
Input data. Default is piped-forward data (<-).
import "sampledata"
sampledata.int()
|> elapsed(unit: 1s)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| _time | _value | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |
| _time | _value | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |
| _time | _value | *tag | elapsed |
|---|---|---|---|
| 2021-01-01T00:00:10Z | 10 | t1 | 10 |
| 2021-01-01T00:00:20Z | 7 | t1 | 10 |
| 2021-01-01T00:00:30Z | 17 | t1 | 10 |
| 2021-01-01T00:00:40Z | 15 | t1 | 10 |
| 2021-01-01T00:00:50Z | 4 | t1 | 10 |
| _time | _value | *tag | elapsed |
|---|---|---|---|
| 2021-01-01T00:00:10Z | 4 | t2 | 10 |
| 2021-01-01T00:00:20Z | -3 | t2 | 10 |
| 2021-01-01T00:00:30Z | 19 | t2 | 10 |
| 2021-01-01T00:00:40Z | 13 | t2 | 10 |
| 2021-01-01T00:00:50Z | 1 | t2 | 10 |
{{% /expand %}} {{< /expand-wrapper >}}