docs-v2/content/flux/v0.x/stdlib/universe/integral.md

3.5 KiB
Raw Permalink Blame History

title description aliases menu weight flux/v0.x/tags related introduced
integral() function The `integral()` function computes the area under the curve per unit of time of subsequent non-null records.
/influxdb/v2.0/reference/flux/functions/transformations/aggregates/integral
/influxdb/v2.0/reference/flux/functions/built-in/transformations/aggregates/integral/
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/integral/
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/aggregates/integral/
flux_0_x_ref
name parent
integral universe
102
aggregates
transformations
/{{< latest "influxdb" "v1" >}}/query_language/functions/#integral, InfluxQL  INTEGRAL()
/flux/v0.x/stdlib/experimental/integral/
0.7.0

The integral() function computes the area under the curve per unit of time of subsequent non-null records. integral() requires _start and _stop columns that are part of the group key. The curve is defined using _time as the domain and record values as the range. integral() is an aggregate function.

Output data type: Float

integral(
    unit: 10s,
    column: "_value",
    timeColumn: "_time",
    interpolate: "",
)

Parameters

unit

({{< req >}}) Time duration used when computing the integral.

column

Column on which to operate. Defaults to "_value".

timeColumn

Column that contains time values to use in the operation. Defaults to "_time".

interpolate

Type of interpolation to use. Defaults to "".

Use one of the following interpolation options:

  • empty string for no interpolation
  • linear

tables

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

Examples

{{% flux/sample-example-intro plural=true %}}

Calculate the integral

import "sampledata"

sampledata.int()
    |> range(start: sampledata.start, stop: sampledata.stop)
    |> integral(unit:10s)

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

Input data

{{% flux/sample set="int" includeRange=true %}}

Output data
_start _stop tag _value
2021-01-01T00:00:00Z 2021-01-01T00:01:00Z t1 50.0
_start _stop tag _value
2021-01-01T00:00:00Z 2021-01-01T00:01:00Z t2 43

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

Calculate the integral with linear interpolation

import "sampledata"

sampledata.int(includeNull: true)
    |> range(start: sampledata.start, stop: sampledata.stop)
    |> integral(unit:10s, interpolate: "linear")

{{% expand "View input and output" %}}

Input data

{{% flux/sample set="int" includeNull=true includeRange=true %}}

Output data
_start _stop tag _value
2021-01-01T00:00:00Z 2021-01-01T00:01:00Z t1 25.0
_start _stop tag _value
2021-01-01T00:00:00Z 2021-01-01T00:01:00Z t2 32.5

{{% /expand %}}