Maintains a rolling (moving) average over a fixed-length window of recent readings using a circular b...
Definition: RollingAverage.h:14
unsigned int GetWindowLength() const
Gets the window length (the number of readings averaged over).
Definition: RollingAverage.cpp:126
unsigned int myNumberOfValidReadings
The number of valid readings we have had so far.
Definition: RollingAverage.h:26
std::string ToString() const
Serializes the average, window length, current index, valid-reading count, and every buffered reading...
Definition: RollingAverage.cpp:177
unsigned int myCurrentReadingIndex
The index in the readings we are currently writing to.
Definition: RollingAverage.h:23
unsigned int GetNumberOfValidReadings() const
Gets the number of valid readings recorded so far (grows until the buffer is full,...
Definition: RollingAverage.cpp:160
float GetAverage() const
Gets the current rolling average.
Definition: RollingAverage.cpp:103
unsigned int myWindowLength
The number of readings in total to average.
Definition: RollingAverage.h:20
std::vector< float > myReadings
A circular buffer of recent readings.
Definition: RollingAverage.h:29
float myAverage
Calculated average.
Definition: RollingAverage.h:17
void AddReading(float reading)
Adds a reading to the circular buffer and recomputes the current average over the valid readings.
Definition: RollingAverage.cpp:48
unsigned int GetCurrentReadingIndex() const
Gets the index in the circular buffer that the next reading will be written to.
Definition: RollingAverage.cpp:143
RollingAverage(unsigned int windowLength=RUMPI_MAX_NUM_SAMPLES)
Builds a rolling average over the given window length, defaulting a zero window to one (with a warnin...
Definition: RollingAverage.cpp:20
void Reset()
Resets the average, current index, and valid-reading count back to their initial (empty) state.
Definition: RollingAverage.cpp:84
RumPi is the library's top-level facade.
Definition: AlertManager.h:6
constexpr unsigned int RUMPI_MAX_NUM_SAMPLES
Default rolling-average window length.
Definition: Common.h:59