esp8266_web_settings beta
|
A class to handle accumulating values. More...
#include <grmcdorman/device/Accumulator.h>
Public Types | |
typedef T | value_type |
The value type. | |
Public Member Functions | |
T | get_last_reading () const |
Get the current value. More... | |
float | get_current_average () const |
Get the current rolling average. More... | |
void | new_reading (T new_value) |
Record a new reading. More... | |
bool | has_accumulation () const |
Return a value indicate whether data has been accumulated. More... | |
uint8_t | get_sample_count () const |
Get the number of samples used for the average. More... | |
uint32_t | get_last_sample_age () const |
Get the last sample age, in milliseconds. More... | |
DynamicJsonDocument | as_json () const |
Get the values in standard JSON. More... | |
A class to handle accumulating values.
This provides tracking for a reading, giving both the most recent reading and the current running average.
The number of readings required for a running average is configurable, and is not time-based. It defaults to 10 readings.
The intent is that readings are accumulated until a reading is published, at which time reset
is called to begin accumulating anew.
T | The type being accumulated; must be an arithmetic type, e.g. int32_t or float. |
unset | The unset value. Defaults to T() , which is likely to be zero. |
zero | The zero value; defaults to 0. |
|
inline |
Get the values in standard JSON.
|
inline |
Get the current rolling average.
This is the rolling average for the last N readings; if fewer than N have been accumulated, it is the average of those.
|
inline |
Get the current value.
This is the last value supplied to new_reading
. If a value has never been read, the returned value will be unset_value
.
|
inline |
Get the last sample age, in milliseconds.
|
inline |
Get the number of samples used for the average.
At first this will be less than the configured maximum until sufficient samples have been collected.
|
inline |
Return a value indicate whether data has been accumulated.
|
inline |
Record a new reading.
The last_reading
is set to this value, and the reading is accumulated in the rolling average set.
new_value | New reading. |