From ef0708f7573f4de95b5ed14eca9d2bd92e22a7d4 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 11 Jul 2019 08:08:32 -0600 Subject: [PATCH 01/11] added flux-0.36 to the changelog --- content/v2.0/reference/release-notes/flux.md | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/content/v2.0/reference/release-notes/flux.md b/content/v2.0/reference/release-notes/flux.md index c4bf927c9..3e1e82d30 100644 --- a/content/v2.0/reference/release-notes/flux.md +++ b/content/v2.0/reference/release-notes/flux.md @@ -11,11 +11,40 @@ aliases: --- {{% note %}} -_The latest release of InfluxDB v2.0 alpha includes **Flux v0.35.1**. +_The latest release of InfluxDB v2.0 alpha includes **Flux v0.36.1**. Though newer versions of Flux may be available, they will not be included with InfluxDB until the next InfluxDB v2.0 release._ {{% /note %}} +## v0.36.1 [2019-07-10] + +### Bug fixes +- Add `range` call to some end-to-end tests. +- Fix implementation of `strings.replaceAll`. + +--- + +## v0.36.0 [2019-07-09] + +### Features +- Refactored `movingAverage()`. +- `elapsed()` function. +- `mode()` function. +- `sleep()` function. +- Modify error usage in places to use the new enriched errors. +- Enriched error interface. +- End-to-end tests that show how to mimic pandas functionality. +- End-to-end tests for string functions. + +### Bug fixes +- Fix `difference()` so that it returns an error instead of panicking when given a `_time` column. +- Added end-to-end tests for type conversion functions. +- Make `map()` error if return type is not an object. +- Fixed miscounted allocations in the `ColListTableBuilder`. +- Support formatting `with`. + +--- + ## v0.35.1 [2019-07-03] ### Bug fixes From 860ee180c1f0b9cd7ce845c5eeebc6194d927941 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 11 Jul 2019 10:35:28 -0600 Subject: [PATCH 02/11] refactored movingAverage and added timedMovingAverage, resolves #311 --- .../aggregates/movingaverage.md | 95 +++++++++---------- .../aggregates/timedmovingaverage.md | 69 ++++++++++++++ content/v2.0/reference/release-notes/flux.md | 2 +- layouts/partials/article/related.html | 2 +- 4 files changed, 114 insertions(+), 54 deletions(-) create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage.md diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage.md b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage.md index d4f2c92f8..038f17258 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage.md @@ -1,85 +1,76 @@ --- title: movingAverage() function description: > - The `movingAverage()` function calculates the mean of values in a defined time - range at a specified frequency. + The `movingAverage()` function calculates the the mean of values grouped into `n` number of points. menu: v2_0_ref: name: movingAverage parent: built-in-aggregates weight: 501 +related: + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/ + - https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE() --- -The `movingAverage()` function calculates the mean of values in a defined time -range at a specified frequency. +The `movingAverage()` function calculates the mean of values grouped into `n` number of points. _**Function type:** Aggregate_ ```js movingAverage( - every: 1d, - period: 5d, - column="_value", - timeSrc="_stop", - timeDst="_time", + n: 5, + columns: ["_value"] ) ``` +##### Moving average rules: +- The average over a period populated by `n` values is equal to their algebraic mean. +- The average over a period populated by only `null` values is `null`. +- Moving averages skip `null` values. +- If `n` is less than the number of records in a table, `movingAverage` returns + the average of the available values. + ## Parameters -### every -The frequency of time windows. +### n +The number of points to mean. -_**Data type:** Duration_ +_**Data type:** Integer_ -### period -The length of each averaged time window. -_A negative duration indicates start and stop boundaries are reversed._ +### columns +Columns to operate on. _Defaults to `["_value"]`_. -_**Data type:** Duration_ - -### column -The column used to compute the moving average. -Defaults to `"_value"`. - -_**Data type:** String_ - -### timeSrc -The column used as the source for the aggregated time. -Defaults to `"_stop"`. - -_**Data type:** String_ - -### timeDst -The column in which to store the aggregated time. -Defaults to `"_time"`. - -_**Data type:** String_ +_**Data type:** Array of Strings_ ## Examples -###### Calculate a five year moving average every year +#### Calculate a five point moving average ```js from(bucket: "example-bucket"): - |> range(start: -7y) - |> filter(fn: (r) => - r._measurement == "financial" and - r._field == "closing_price" - ) - |> movingAverage(every: 1y, period: 5y) + |> range(start: -12h) + |> movingAverage(n: 5) ``` -## Function definition +#### Moving average table transformation + +###### Input table: +| _time | A | B | C | D | tag | +|:-----:|:----:|:----:|:----:|:----:|:---:| +| 0001 | null | 1 | 2 | null | tv | +| 0002 | 6 | 2 | null | null | tv | +| 0003 | 4 | null | 4 | 4 | tv | + +###### Query: ```js -movingAverage = (every, period, column="_value", timeSrc="_stop", timeDst="_time", tables=<-) => - tables - |> window(every: every, period: period) - |> mean(column: column) - |> duplicate(column: timeSrc, as: timeDst) - |> window(every: inf) +// ... + |> movingAverage( + n: 2, + columns: ["A", "B", "C", "D"] + ) ``` -
- -##### Related InfluxQL functions and statements: -[MOVING_AVERAGE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average) +###### Output table: +| _time | A | B | C | D | tag | +|:-----:|:----:|:----:|:----:|:----:|:---:| +| 0002 | 6 | 1.5 | 2 | null | tv | +| 0003 | 5 | 2 | 4 | 4 | tv | diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage.md b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage.md new file mode 100644 index 000000000..4aef93f1a --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage.md @@ -0,0 +1,69 @@ +--- +title: timedMovingAverage() function +description: > + The `timedMovingAverage()` function calculates the mean of values in a defined time + range at a specified frequency. +menu: + v2_0_ref: + name: timedMovingAverage + parent: built-in-aggregates +weight: 501 +related: + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/ + - https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE() +--- + +The `timedMovingAverage()` function calculates the mean of values in a defined time +range at a specified frequency. + +_**Function type:** Aggregate_ + +```js +timedMovingAverage( + every: 1d, + period: 5d, + column="_value" +) +``` + +## Parameters + +### every +The frequency of time windows. + +_**Data type:** Duration_ + +### period +The length of each averaged time window. +_A negative duration indicates start and stop boundaries are reversed._ + +_**Data type:** Duration_ + +### column +The column used to compute the moving average. +Defaults to `"_value"`. + +_**Data type:** String_ + +## Examples + +###### Calculate a five year moving average every year +```js +from(bucket: "example-bucket"): + |> range(start: -7y) + |> filter(fn: (r) => + r._measurement == "financial" and + r._field == "closing_price" + ) + |> timedMovingAverage(every: 1y, period: 5y) +``` + +## Function definition +```js +timedMovingAverage = (every, period, column="_value", tables=<-) => + tables + |> window(every: every, period: period) + |> mean(column:column) + |> duplicate(column: "_stop", as: "_time") + |> window(every: inf) +``` diff --git a/content/v2.0/reference/release-notes/flux.md b/content/v2.0/reference/release-notes/flux.md index 3e1e82d30..456b29016 100644 --- a/content/v2.0/reference/release-notes/flux.md +++ b/content/v2.0/reference/release-notes/flux.md @@ -27,7 +27,7 @@ InfluxDB until the next InfluxDB v2.0 release._ ## v0.36.0 [2019-07-09] ### Features -- Refactored `movingAverage()`. +- Updated `movingAverage()` and added `timedMovingAverage`. - `elapsed()` function. - `mode()` function. - `sleep()` function. diff --git a/layouts/partials/article/related.html b/layouts/partials/article/related.html index 7bbe046e0..7817ad286 100644 --- a/layouts/partials/article/related.html +++ b/layouts/partials/article/related.html @@ -4,7 +4,7 @@