5.1 KiB
title | description | aliases | menu | weight | flux/v0.x/tags | related | introduced | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
derivative() function | The `derivative()` function computes the rate of change per unit of time between subsequent non-null records. |
|
|
102 |
|
|
0.7.0 |
The derivative()
function computes the rate of change per unit
of time between subsequent non-null records.
It assumes rows are ordered by the _time
column.
The output table schema is the same as the input table.
Output data type: Float
derivative(
unit: 1s,
nonNegative: false,
columns: ["_value"],
timeColumn: "_time",
)
Parameters
unit
The time duration used when creating the derivative.
Default is 1s
.
nonNegative
Indicates if the derivative is allowed to be negative. Default is false
.
When true
, if a value is less than the previous value, it is assumed the
previous value should have been a zero.
columns
The columns to use to compute the derivative.
Default is ["_value"]
.
timeColumn
The column containing time values.
Default is "_time"
.
tables
Input data.
Default is piped-forward data (<-
).
Output tables
For each input table with n
rows, derivative()
outputs a table with n - 1
rows.
Examples
{{% flux/sample-example-intro plural=true %}}
- Calculate the rate of change per second
- Calculate the non-negative rate of change per second
- Calculate the rate of change per second with null values
Calculate the rate of change per second
import "sampledata"
sampledata.int()
|> derivative()
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample set="int" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:10Z | t1 | 1.2 |
2021-01-01T00:00:20Z | t1 | -0.3 |
2021-01-01T00:00:30Z | t1 | 1 |
2021-01-01T00:00:40Z | t1 | -0.2 |
2021-01-01T00:00:50Z | t1 | -1.1 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:10Z | t2 | -1.5 |
2021-01-01T00:00:20Z | t2 | -0.7 |
2021-01-01T00:00:30Z | t2 | 2.2 |
2021-01-01T00:00:40Z | t2 | -0.6 |
2021-01-01T00:00:50Z | t2 | -1.2 |
{{% /flex-content %}} {{< /flex >}} {{% /expand %}} {{< /expand-wrapper >}}
Calculate the non-negative rate of change per second
import "sampledata"
sampledata.int()
|> derivative(nonNegative: true)
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample set="int" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:10Z | t1 | 1.2 |
2021-01-01T00:00:20Z | t1 | |
2021-01-01T00:00:30Z | t1 | 1 |
2021-01-01T00:00:40Z | t1 | |
2021-01-01T00:00:50Z | t1 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:10Z | t2 | |
2021-01-01T00:00:20Z | t2 | |
2021-01-01T00:00:30Z | t2 | 2.2 |
2021-01-01T00:00:40Z | t2 | |
2021-01-01T00:00:50Z | t2 |
{{% /flex-content %}} {{< /flex >}} {{% /expand %}} {{< /expand-wrapper >}}
Calculate the rate of change per second with null values
import "sampledata"
sampledata.int(includeNull: true)
|> derivative()
{{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample "int" true %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:10Z | t1 | |
2021-01-01T00:00:20Z | t1 | 0.45 |
2021-01-01T00:00:30Z | t1 | |
2021-01-01T00:00:40Z | t1 | |
2021-01-01T00:00:50Z | t1 | -0.1 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:10Z | t2 | |
2021-01-01T00:00:20Z | t2 | -0.7 |
2021-01-01T00:00:30Z | t2 | 2.2 |
2021-01-01T00:00:40Z | t2 | |
2021-01-01T00:00:50Z | t2 | -0.9 |
{{% /flex-content %}} {{< /flex >}} {{% /expand %}}