Documentation

stateCount() function

Flux 0.7.0+

The stateCount() function computes the number of consecutive records in a given state. The state is defined via the function fn. For each consecutive point that evaluates as true, the state count is incremented. When a point evaluates as false, the state count is reset. The state count is added as an additional column to each record.

stateCount(fn: (r) => r._field == "state", column: "stateCount")

If the expression generates an error during evaluation, the point is discarded and does not affect the state count.

Parameters

Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names.

fn

(Required) A single argument function that evaluates true or false to identify the state of the record. Records are passed to the function. Those that evaluate to true increment the state count. Those that evaluate to false reset the state count.

column

Name of the column added to each record that contains the incremented state count. Default is stateCount.

tables

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

Examples

The following example uses data provided by the sampledata package to show how stateCount() transforms data.

import "sampledata"

sampledata.int()
  |> stateCount(fn: (r) => r._value > 10)

View input and output


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.