added movingAverage and mode functions, resolves #298

pull/303/head
Scott Anderson 2019-07-01 09:07:05 -06:00
parent a111ca9c3c
commit 2d9a73ac1e
2 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,43 @@
---
title: mode() function
description: >
The `mode()` function computes the mode or value that occurs most often among
records in the input table.
menu:
v2_0_ref:
name: mode
parent: built-in-aggregates
weight: 501
---
The `mode()` function computes the mode or value that occurs most often among
records in the input table.
_**Function type:** Aggregate_
## Parameters
### column
The column to use to compute the mode.
Defaults to `"_value"`.
_**Data type:** String_
## Examples
###### Mode as an aggregate
```js
from(bucket: "example-bucket")
|> filter(fn: (r) =>
r._measurement == "errors" and
r._field == "count_per_minute"
)
|> range(start:-12h)
|> window(every:10m)
|> mode()
```
<hr style="margin-top:4rem"/>
##### Related InfluxQL functions and statements:
[MODE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#mode)

View File

@ -0,0 +1,85 @@
---
title: movingAverage() function
description: >
The `movingAverage()` function calculates the mean of values in a defined time
range at a specified frequency.
menu:
v2_0_ref:
name: movingAverage
parent: built-in-aggregates
weight: 501
---
The `movingAverage()` function calculates the mean of values in a defined time
range at a specified frequency.
_**Function type:** Aggregate_
```js
movingAverage(
every: 1d,
period: 5d,
column="_value",
timeSrc="_stop",
timeDst="_time",
)
```
## 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_
### 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_
## 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"
)
|> movingAverage(every: 1y, period: 5y)
```
## Function definition
```js
movingAverage = (every, period, column="_value", timeSrc="_stop",timeDst="_time", tables=<-) =>
tables
|> window(every: every, period: period)
|> mean()
|> duplicate(column: "_stop", as: "_time")
|> window(every: inf)
```
<hr style="margin-top:4rem"/>
##### Related InfluxQL functions and statements:
[MOVING_AVERAGE()](https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average)