Back to Influxdb

experimental.integral() function

content/flux/v0/stdlib/experimental/integral.md

latest6.1 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/experimental/experimental.flux#L648-L652 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

experimental.integral() computes the area under the curve per unit of time of subsequent non-null records.

The curve is defined using _time as the domain and record values as the range.

Input tables must have _start, _stop, _time, and _valuecolumns._startand_stop` must be part of the group key.

Function type signature
js
(<-tables: stream[{A with _value: B, _time: time}], ?interpolate: string, ?unit: duration) => stream[{A with _value: B}]

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

unit

Time duration used to compute the integral.

interpolate

Type of interpolation to use. Default is "" (no interpolation).

Use one of the following interpolation options:

  • empty string ("") for no interpolation
  • linear

tables

Input data. Default is piped-forward data (<-).

Examples

Calculate the integral

js
import "experimental"
import "sampledata"

data =
    sampledata.int()
        |> range(start: sampledata.start, stop: sampledata.stop)

data
    |> experimental.integral(unit: 20s)

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

*_start*_stop_time_value*tag
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:00Z-2t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:10Z10t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:20Z7t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:30Z17t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:40Z15t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:50Z4t1
*_start*_stop_time_value*tag
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:00Z19t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:10Z4t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:20Z-3t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:30Z19t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:40Z13t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:50Z1t2

Output data

*_start*_stop*tag_value
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt125
*_start*_stop*tag_value
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt221.5

{{% /expand %}} {{< /expand-wrapper >}}

Calculate the integral with linear interpolation

js
import "experimental"
import "sampledata"

data =
    sampledata.int()
        |> range(start: sampledata.start, stop: sampledata.stop)

data
    |> experimental.integral(unit: 20s, interpolate: "linear")

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

*_start*_stop_time_value*tag
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:00Z-2t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:10Z10t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:20Z7t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:30Z17t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:40Z15t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:50Z4t1
*_start*_stop_time_value*tag
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:00Z19t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:10Z4t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:20Z-3t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:30Z19t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:40Z13t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:50Z1t2

Output data

*_start*_stop*tag_value
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt124.25
*_start*_stop*tag_value
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt219

{{% /expand %}} {{< /expand-wrapper >}}