libstatistics_collector  master
Lightweight aggregation utilities to collect statistics and measure message metrics.
Public Member Functions | List of all members
libstatistics_collector::moving_average_statistics::MovingAverageStatistics Class Referenceabstract

#include <moving_average.hpp>

Public Member Functions

 MovingAverageStatistics ()=default
 
 ~MovingAverageStatistics ()=default
 
double Average () const RCPPUTILS_TSA_REQUIRES(mutex_)
 
double Max () const RCPPUTILS_TSA_REQUIRES(mutex_)
 
double Min () const RCPPUTILS_TSA_REQUIRES(mutex_)
 
double StandardDeviation () const RCPPUTILS_TSA_REQUIRES(mutex_)
 
StatisticData GetStatistics () const
 
void Reset ()
 
virtual void AddMeasurement (const double item)
 
uint64_t GetCount () const
 

Detailed Description

A class for calculating moving average statistics. This operates in constant memory and constant time. Note: reset() must be called manually in order to start a new measurement window.

The statistics calculated are average, maximum, minimum, and standard deviation (population). All are calculated online without storing the observation data. Specifically, the average is a running sum and the variance is obtained by Welford's online algorithm (reference: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford%27s_online_algorithm) for standard deviation.

When statistics are not available, e.g. no observations have been made, NaNs are returned.

Constructor & Destructor Documentation

◆ MovingAverageStatistics()

libstatistics_collector::moving_average_statistics::MovingAverageStatistics::MovingAverageStatistics ( )
default

◆ ~MovingAverageStatistics()

libstatistics_collector::moving_average_statistics::MovingAverageStatistics::~MovingAverageStatistics ( )
default

Member Function Documentation

◆ Average()

double libstatistics_collector::moving_average_statistics::MovingAverageStatistics::Average ( ) const

Returns the arithmetic mean of all data recorded. If no observations have been made, returns NaN.

Returns
The arithmetic mean of all data recorded, or NaN if the sample count is 0.

◆ Max()

double libstatistics_collector::moving_average_statistics::MovingAverageStatistics::Max ( ) const

Returns the maximum value recorded. If size of list is zero, returns NaN.

Returns
The maximum value recorded, or NaN if size of data is zero.

◆ Min()

double libstatistics_collector::moving_average_statistics::MovingAverageStatistics::Min ( ) const

Returns the minimum value recorded. If size of list is zero, returns NaN.

Returns
The minimum value recorded, or NaN if size of data is zero.

◆ StandardDeviation()

double libstatistics_collector::moving_average_statistics::MovingAverageStatistics::StandardDeviation ( ) const

Returns the standard deviation (population) of all data recorded. If size of list is zero, returns NaN.

Variance is obtained by Welford's online algorithm, see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford%27s_online_algorithm

Returns
The standard deviation (population) of all data recorded, or NaN if size of data is zero.

◆ GetStatistics()

StatisticData libstatistics_collector::moving_average_statistics::MovingAverageStatistics::GetStatistics ( ) const

Return a StatisticData object, containing average, minimum, maximum, standard deviation (population), and sample count. For the case of no observations, the average, min, max, and standard deviation are NaN.

Returns
StatisticData object, containing average, minimum, maximum, standard deviation (population), and sample count.

◆ Reset()

void libstatistics_collector::moving_average_statistics::MovingAverageStatistics::Reset ( )

Reset all calculated values. Equivalent to a new window for a moving average.

◆ AddMeasurement()

virtual void libstatistics_collector::moving_average_statistics::MovingAverageStatistics::AddMeasurement ( const double  item)
virtual

Observe a sample for the given window. The input item is used to calculate statistics. Note: any input values of NaN will be discarded and not added as a measurement.

Parameters
itemThe item that was observed

◆ GetCount()

uint64_t libstatistics_collector::moving_average_statistics::MovingAverageStatistics::GetCount ( ) const

Return the number of samples observed

Returns
the number of samples observed

The documentation for this class was generated from the following file: