Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MovingAvg ¶
MovingAvg tracks the exponential moving average across a number of events and reports when it has surpassed the set cutoff.
func NewMovingAvg ¶
func NewMovingAvg(p MovingAvgParams) *MovingAvg
NewMovingAvg creates a new MovingAvg with the given cutoff, initial average, smoothing factor, and number of events to average.
func (*MovingAvg) Intake ¶
Intake takes in the current average and calculates the exponential average returning true if it is over the cutoff and false otherwise.
The moving average is calculated by:
A(n) = a × (S/E) + A(n-1) × (1 − S/E)
Where:
A(n) is the current exponential moving average A(n-1) is the previous exponential moving average a is the intake value S is the smoothing factor E is the number of events the average is over
func (*MovingAvg) IsOverCutoff ¶
IsOverCutoff returns true if the average has reached the cutoff and false if it has not
type MovingAvgParams ¶
type MovingAvgParams struct { // Cutoff is the maximum the moving average can reach before an error is // returned on intake. The value should range from 0.0 to 1.0. Cutoff float32 // InitialAverage is the initial exponential moving average to start with. InitialAverage float32 // SmoothingFactor, the exponential smoothing factor; gives the most recent // events more weight. The greater the smoothing factor, the greater the // influence of more recent events. SmoothingFactor float32 // NumberOfEvents is the number of events to average over. NumberOfEvents uint32 }
MovingAvgParams are the parameters needed to create a new MovingAvg.
func DefaultMovingAvgParams ¶
func DefaultMovingAvgParams() MovingAvgParams
DefaultMovingAvgParams returns MovingAvgParams with default values.