Ocean
Ocean::RateCalculator Class Reference

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 &timestamp, const double quantity=1.0)
 Adds another occurrence (e.g., a new frame has been processed). More...
 
double rate (const Timestamp &timestamp) 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...
 

Detailed Description

This class implements a calculate for rates like frame rates.

The rates are determined with a sliding windows.
The class is thread-safe.

Member Typedef Documentation

◆ TimestampMap

typedef std::map<Timestamp, double> Ocean::RateCalculator::TimestampMap
protected

Definition of an ordered map mapping timestamps to quantities.

Constructor & Destructor Documentation

◆ RateCalculator()

Ocean::RateCalculator::RateCalculator ( const double  window = 1.0)
inlineexplicit

Creates a new rate calculator object.

Parameters
windowThe size of the sliding window, in seconds, with range (0, infinity)

Member Function Documentation

◆ addOccurance()

void Ocean::RateCalculator::addOccurance ( const Timestamp timestamp,
const double  quantity = 1.0 
)

Adds another occurrence (e.g., a new frame has been processed).

Parameters
timestampThe timestamp at which the occurrence happened, must be valid
quantityThe quantity of the current occurrence

◆ clear()

void Ocean::RateCalculator::clear ( )
inline

Clears the rate calculator e.g., to start with a completely new measurement.

◆ rate()

double Ocean::RateCalculator::rate ( const Timestamp timestamp) const

Returns the current rate.

Parameters
timestampThe timestamp at which the current rate will be determined, must be valid
Returns
The current rate, with range [0, infinity)

◆ rateEveryNSeconds()

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.

Parameters
rateTimestampThe timestamp at which the current rate will be determined, must be valid
rateThe resulting current rate, with range [0, infinity)
intervalThe number of seconds necessary since the last successful call of this function, with range [0, infinity)
requestTimestampOptional an explicit timestamp when the request happens, e.g., in display time, invalid to use the timestamp for the rate
Returns
True, if the rate was determined; False, if the interval was not yet reached

◆ setWindow()

void Ocean::RateCalculator::setWindow ( const double  window)
inline

Updates the window of this rate calculator.

Parameters
windowThe window to be set, in seconds, with range [0, infinity)

◆ window()

double Ocean::RateCalculator::window ( ) const
inline

Returns the window of this rate calculator.

Returns
The rate calculator's window, in seconds, with range [0, infinity)

Field Documentation

◆ lastRequestTimestamp_

Timestamp Ocean::RateCalculator::lastRequestTimestamp_
protected

The timestamp at which the rate has been sucessfully requested the last time when calling rateEveryNSeconds().

◆ lock_

Lock Ocean::RateCalculator::lock_
mutableprotected

The lock of this object.

◆ timestampMap_

TimestampMap Ocean::RateCalculator::timestampMap_
protected

The map mapping timestamps to quantities.

◆ window_

double Ocean::RateCalculator::window_ = 1.0
protected

The size of the sliding window, in seconds, with range (0, infinity).


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