Ocean
|
This class implements a calculate for rates like frame rates. More...
Public Member Functions | |
RateCalculator (const double window=1.0) | |
Creates a new rate calculator object. More... | |
void | addOccurance (const Timestamp ×tamp, const double quantity=1.0) |
Adds another occurrence (e.g., a new frame has been processed). More... | |
double | rate (const Timestamp ×tamp) const |
Returns the current rate. More... | |
bool | rateEveryNSeconds (const Timestamp &rateTimestamp, double &rate, const double interval=1.0, const Timestamp &requestTimestamp=Timestamp(false)) |
Returns the current rate only every n-th second. More... | |
void | setWindow (const double window) |
Updates the window of this rate calculator. More... | |
double | window () const |
Returns the window of this rate calculator. More... | |
void | clear () |
Clears the rate calculator e.g., to start with a completely new measurement. More... | |
Protected Types | |
typedef std::map< Timestamp, double > | TimestampMap |
Definition of an ordered map mapping timestamps to quantities. More... | |
Protected Attributes | |
double | window_ = 1.0 |
The size of the sliding window, in seconds, with range (0, infinity). More... | |
TimestampMap | timestampMap_ |
The map mapping timestamps to quantities. More... | |
Timestamp | lastRequestTimestamp_ |
The timestamp at which the rate has been sucessfully requested the last time when calling rateEveryNSeconds(). More... | |
Lock | lock_ |
The lock of this object. More... | |
This class implements a calculate for rates like frame rates.
The rates are determined with a sliding windows.
The class is thread-safe.
|
protected |
Definition of an ordered map mapping timestamps to quantities.
|
inlineexplicit |
Creates a new rate calculator object.
window | The size of the sliding window, in seconds, with range (0, infinity) |
void Ocean::RateCalculator::addOccurance | ( | const Timestamp & | timestamp, |
const double | quantity = 1.0 |
||
) |
Adds another occurrence (e.g., a new frame has been processed).
timestamp | The timestamp at which the occurrence happened, must be valid |
quantity | The quantity of the current occurrence |
|
inline |
Clears the rate calculator e.g., to start with a completely new measurement.
double Ocean::RateCalculator::rate | ( | const Timestamp & | timestamp | ) | const |
Returns the current rate.
timestamp | The timestamp at which the current rate will be determined, must be valid |
bool Ocean::RateCalculator::rateEveryNSeconds | ( | const Timestamp & | rateTimestamp, |
double & | rate, | ||
const double | interval = 1.0 , |
||
const Timestamp & | requestTimestamp = Timestamp(false) |
||
) |
Returns the current rate only every n-th second.
rateTimestamp | The timestamp at which the current rate will be determined, must be valid |
rate | The resulting current rate, with range [0, infinity) |
interval | The number of seconds necessary since the last successful call of this function, with range [0, infinity) |
requestTimestamp | Optional an explicit timestamp when the request happens, e.g., in display time, invalid to use the timestamp for the rate |
|
inline |
Updates the window of this rate calculator.
window | The window to be set, in seconds, with range [0, infinity) |
|
inline |
Returns the window of this rate calculator.
|
protected |
The timestamp at which the rate has been sucessfully requested the last time when calling rateEveryNSeconds().
|
mutableprotected |
The lock of this object.
|
protected |
The map mapping timestamps to quantities.
|
protected |
The size of the sliding window, in seconds, with range (0, infinity).