diff --git a/content/v2.0/reference/flux/stdlib/experimental/aggregate/_index.md b/content/v2.0/reference/flux/stdlib/experimental/aggregate/_index.md new file mode 100644 index 000000000..64720f37a --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/experimental/aggregate/_index.md @@ -0,0 +1,22 @@ +--- +title: Flux Aggregate package +list_title: Aggregate package +description: > + The Flux Aggregate package provides functions to simplify common aggregate operations. + Import the `experimental/aggregate` package. +menu: + v2_0_ref: + name: Aggregate + parent: Experimental +weight: 201 +v2.0/tags: [package] +--- + +The Flux Aggregate package provides functions to simplify common aggregate operations. +Import the `experimental/aggregate` package: + +```js +import "experimental/aggregate" +``` + +{{< children type="functions" show="pages" >}} diff --git a/content/v2.0/reference/flux/stdlib/experimental/aggregate/rate.md b/content/v2.0/reference/flux/stdlib/experimental/aggregate/rate.md new file mode 100644 index 000000000..d5034eab9 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/experimental/aggregate/rate.md @@ -0,0 +1,77 @@ +--- +title: aggregate.rate() function +description: > + The `aggregate.rate()` function calculates the rate of change per windows of time. +menu: + v2_0_ref: + name: aggregate.rate + parent: Aggregate +weight: 301 +--- + +The `aggregate.rate()` function calculates the rate of change per windows of time. + +_**Function type:** Transformation_ + +```js +import "experimental/query" + +aggregate.rate( + every: 1m, + groupColumns: ["column1", "column2"], + unit: 1s +) +``` + +## Parameters + +### every +Duration of time windows. + +_**Data type:** Duration_ + +### groupColumns +List of columns to group by. Defaults to `[]`. + +_**Data type:** Array of strings_ + +### unit +The time duration to use when calculating the rate. Defaults to `1s`. + +_**Data type:** Duration_ + +## Examples + +```js +import "experimental/aggregate" + +from(bucket: "example-bucket") + |> range(start: -1h) + |> aggregate.rate(every: 5m, unit: 1m) +``` + +## Function definition +```js +package aggregate + +import "experimental" + +rate = (tables=<-, every, groupColumns=[], unit=1s) => + tables + |> derivative(nonNegative:true, unit:unit) + |> aggregateWindow(every: every, fn : (tables=<-, column) => + tables + |> mean(column: column) + |> group(columns: groupColumns) + |> experimental.group(columns: ["_start", "_stop"], mode:"extend") + |> sum() + ) +``` + +_**Used functions:**_ +[aggregateWindow()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) +[derivative()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative/) +[experimental.group()](/v2.0/reference/flux/stdlib/experimental/group/) +[group()](/v2.0/reference/flux/stdlib/built-in/transformations/group/) +[mean()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/mean/) +[sum()](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/sum/)