HOG2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
StatCollection Class Reference

The StatCollection class is for collecting stats across different parts of the simulation. More...

#include <StatCollection.h>

Public Member Functions

 StatCollection ()
 
 ~StatCollection ()
 
void AddStat (const char *category, const char *owner, double value)
 Add a new stat entry for the given category, owner and value. More...
 
void AddStat (const char *category, const char *owner, long value)
 Add a new stat entry for the given category, owner and value. More...
 
void SumStat (const char *category, const char *owner, double value)
 Given stats for the category and owner, find an existing stat (chronologically backwards search) with the same category and owner, and add this stat to the existing value. More...
 
void SumStat (const char *category, const char *owner, long value)
 Given stats for the category and owner, find an existing stat (chronologically backwards search) with the same category and owner, and add this stat to the existing value. More...
 
void ClearAllStats ()
 Remove all stat entries from the collection. More...
 
int GetNumStats () const
 The number of stats collected so far. More...
 
const statisticsGetStatNum (int which) const
 Return the nth stat which has been collected. More...
 
int LookupCategory (const char *category) const
 Given a category, look up the ID. More...
 
int LookupOwner (const char *owner) const
 Given an owner, look up the ID. More...
 
const char * lookupCategoryID (int id) const
 Given a category ID, return the text description. More...
 
const char * LookupOwnerID (int id) const
 Given a owner ID, return the text description. More...
 
bool LookupStat (const char *category, const char *owner, statValue &) const
 Find the last stat entered that matches the category and owner. More...
 
bool LookupStat (unsigned int index, statValue &) const
 
void AddFilter (const char *category)
 Adding a filter will cause only stats of the given category to be collected. More...
 
void AddIncludeFilter (const char *category)
 
void AddExcludeFilter (const char *category)
 
void ClearFilters ()
 Clear any filters being used for stat entry. More...
 
void EnablePrintOutput (bool pO)
 
int FindNextStat (const char *category, const char *owner, int startIndex=0) const
 Find the next stat entry that matches the given category and owner name. More...
 
int FindPrevStat (const char *category, const char *owner, int startIndex=-1) const
 Find the previous stat entry that matches the given category and owner name. More...
 
int FindNextStat (const char *what, bool findCategory, int startIndex=0) const
 Find the next stat entry that matches the category if findCategory is true, otherwise look to match the owner name. More...
 
int FindPrevStat (const char *what, bool findCategory, int startIndex=-1) const
 Find the next stat entry that matches the category if findCategory is true, otherwise look to match the owner name. More...
 
void PrintStatsTable () const
 

Private Member Functions

int addCategory (const char *category)
 Add a new category to the category list. More...
 
int addOwner (const char *owner)
 Add a new owner to the owner list. More...
 
bool passFilter (const char *category) const
 Check to see if the category stats should be saved. More...
 
statValuegetLastStat (const char *category, const char *owner)
 Find the last stat entered that matches the category and owner. More...
 

Private Attributes

std::vector< std::string > categories
 
std::vector< std::string > owners
 
std::vector< std::string > includeFilters
 
std::vector< std::string > excludeFilters
 
std::vector< statisticsstats
 
bool printOutput
 

Detailed Description

The StatCollection class is for collecting stats across different parts of the simulation.

This class aggregates results and allows access to the collected information.

Definition at line 34 of file StatCollection.h.

Constructor & Destructor Documentation

◆ StatCollection()

StatCollection::StatCollection ( )

Definition at line 29 of file StatCollection.cpp.

References printOutput.

◆ ~StatCollection()

StatCollection::~StatCollection ( )

Definition at line 35 of file StatCollection.cpp.

Member Function Documentation

◆ addCategory()

int StatCollection::addCategory ( const char *  category)
private

Add a new category to the category list.

If the category exists, returns the id. Otherwise creates the category and returns the id.

Definition at line 258 of file StatCollection.cpp.

References categories, and LookupCategory().

Referenced by AddStat().

◆ AddExcludeFilter()

void StatCollection::AddExcludeFilter ( const char *  category)

Definition at line 207 of file StatCollection.cpp.

References excludeFilters.

◆ AddFilter()

void StatCollection::AddFilter ( const char *  category)

Adding a filter will cause only stats of the given category to be collected.

All other stats added will be ignored. As many categories can be added as needed.

Definition at line 192 of file StatCollection.cpp.

References AddIncludeFilter().

◆ AddIncludeFilter()

void StatCollection::AddIncludeFilter ( const char *  category)

Definition at line 197 of file StatCollection.cpp.

References includeFilters.

Referenced by AddFilter(), and setupAverageRatio().

◆ addOwner()

int StatCollection::addOwner ( const char *  owner)
private

Add a new owner to the owner list.

If the owner exists, returns the id. Otherwise creates the owner and returns the id.

Definition at line 289 of file StatCollection.cpp.

References LookupOwner(), and owners.

Referenced by AddStat().

◆ AddStat() [1/2]

void StatCollection::AddStat ( const char *  category,
const char *  owner,
double  value 
)

◆ AddStat() [2/2]

void StatCollection::AddStat ( const char *  category,
const char *  owner,
long  value 
)

Add a new stat entry for the given category, owner and value.

Definition at line 87 of file StatCollection.cpp.

References addCategory(), addOwner(), longStored, passFilter(), printOutput, and stats.

◆ ClearAllStats()

void StatCollection::ClearAllStats ( )

Remove all stat entries from the collection.

Definition at line 148 of file StatCollection.cpp.

References stats.

Referenced by setupAverageRatio().

◆ ClearFilters()

void StatCollection::ClearFilters ( )

Clear any filters being used for stat entry.

Definition at line 220 of file StatCollection.cpp.

References excludeFilters, and includeFilters.

Referenced by setupAverageRatio().

◆ EnablePrintOutput()

void StatCollection::EnablePrintOutput ( bool  pO)
inline

Definition at line 61 of file StatCollection.h.

References printOutput.

◆ FindNextStat() [1/2]

int StatCollection::FindNextStat ( const char *  category,
const char *  owner,
int  startIndex = 0 
) const

Find the next stat entry that matches the given category and owner name.

If error occurs, return -1; otherwise, return the found index.

Definition at line 388 of file StatCollection.cpp.

References LookupCategory(), LookupOwner(), passFilter(), and stats.

◆ FindNextStat() [2/2]

int StatCollection::FindNextStat ( const char *  what,
bool  findCategory,
int  startIndex = 0 
) const

Find the next stat entry that matches the category if findCategory is true, otherwise look to match the owner name.

If error occurs, return -1; otherwise, return the found index.

Definition at line 444 of file StatCollection.cpp.

References LookupCategory(), LookupOwner(), passFilter(), and stats.

◆ FindPrevStat() [1/2]

int StatCollection::FindPrevStat ( const char *  category,
const char *  owner,
int  startIndex = -1 
) const

Find the previous stat entry that matches the given category and owner name.

If error occurs, return -1; otherwise, return the found index.

Definition at line 415 of file StatCollection.cpp.

References LookupCategory(), LookupOwner(), passFilter(), and stats.

◆ FindPrevStat() [2/2]

int StatCollection::FindPrevStat ( const char *  what,
bool  findCategory,
int  startIndex = -1 
) const

Find the next stat entry that matches the category if findCategory is true, otherwise look to match the owner name.

If error occurs, return -1; otherwise, return the found index.

Definition at line 475 of file StatCollection.cpp.

References LookupCategory(), LookupOwner(), passFilter(), and stats.

◆ getLastStat()

statValue * StatCollection::getLastStat ( const char *  category,
const char *  owner 
)
private

Find the last stat entered that matches the category and owner.

Returns pointer to entry.

Definition at line 341 of file StatCollection.cpp.

References LookupCategory(), LookupOwner(), passFilter(), and stats.

Referenced by SumStat().

◆ GetNumStats()

int StatCollection::GetNumStats ( ) const

The number of stats collected so far.

Definition at line 158 of file StatCollection.cpp.

References stats.

Referenced by averageStatEntries(), countStatEntries(), maxStatEntries(), measureAverageRatio(), stdevStatEntries(), and SumStatEntries().

◆ GetStatNum()

const statistics * StatCollection::GetStatNum ( int  which) const

Return the nth stat which has been collected.

Definition at line 166 of file StatCollection.cpp.

References stats.

Referenced by averageStatEntries(), countStatEntries(), maxStatEntries(), measureAverageRatio(), stdevStatEntries(), and SumStatEntries().

◆ LookupCategory()

int StatCollection::LookupCategory ( const char *  category) const

Given a category, look up the ID.

O(# categories) operation. If not found, returns -1.

Definition at line 241 of file StatCollection.cpp.

References categories.

Referenced by addCategory(), averageStatEntries(), countStatEntries(), FindNextStat(), FindPrevStat(), getLastStat(), LookupStat(), maxStatEntries(), stdevStatEntries(), and SumStatEntries().

◆ lookupCategoryID()

const char * StatCollection::lookupCategoryID ( int  id) const

Given a category ID, return the text description.

Definition at line 174 of file StatCollection.cpp.

References categories.

Referenced by measureAverageRatio().

◆ LookupOwner()

int StatCollection::LookupOwner ( const char *  owner) const

Given an owner, look up the ID.

O(# owners) operation. If not found, returns -1.

Definition at line 275 of file StatCollection.cpp.

References owners.

Referenced by addOwner(), averageStatEntries(), countStatEntries(), FindNextStat(), FindPrevStat(), getLastStat(), LookupStat(), maxStatEntries(), measureAverageRatio(), stdevStatEntries(), and SumStatEntries().

◆ LookupOwnerID()

const char * StatCollection::LookupOwnerID ( int  id) const

Given a owner ID, return the text description.

Definition at line 182 of file StatCollection.cpp.

References owners.

Referenced by measureAverageRatio().

◆ LookupStat() [1/2]

bool StatCollection::LookupStat ( const char *  category,
const char *  owner,
statValue v 
) const

Find the last stat entered that matches the category and owner.

Returns copy of stat entry. Returns true if a stat was found and false otherwise.

Definition at line 307 of file StatCollection.cpp.

References LookupCategory(), LookupOwner(), passFilter(), and stats.

◆ LookupStat() [2/2]

bool StatCollection::LookupStat ( unsigned int  index,
statValue v 
) const

Definition at line 327 of file StatCollection.cpp.

References stats.

◆ passFilter()

bool StatCollection::passFilter ( const char *  category) const
private

Check to see if the category stats should be saved.

Definition at line 359 of file StatCollection.cpp.

References excludeFilters, and includeFilters.

Referenced by AddStat(), FindNextStat(), FindPrevStat(), getLastStat(), and LookupStat().

◆ PrintStatsTable()

void StatCollection::PrintStatsTable ( ) const

Definition at line 506 of file StatCollection.cpp.

References categories, floatStored, owners, and stats.

◆ SumStat() [1/2]

void StatCollection::SumStat ( const char *  category,
const char *  owner,
double  value 
)

Given stats for the category and owner, find an existing stat (chronologically backwards search) with the same category and owner, and add this stat to the existing value.

If the stat doesn't exist with the same category and owner doesn't exist, a new one will be initialized with the given value.

Definition at line 109 of file StatCollection.cpp.

References AddStat(), statValue::fval, getLastStat(), and printOutput.

Referenced by GenericPatrolUnit< state, action, environment >::LogStats(), and SharedAMapGroup::LogStats().

◆ SumStat() [2/2]

void StatCollection::SumStat ( const char *  category,
const char *  owner,
long  value 
)

Given stats for the category and owner, find an existing stat (chronologically backwards search) with the same category and owner, and add this stat to the existing value.

If the stat doesn't exist with the same category and owner doesn't exist, a new one will be initialized with the given value.

Definition at line 130 of file StatCollection.cpp.

References AddStat(), getLastStat(), statValue::lval, and printOutput.

Member Data Documentation

◆ categories

std::vector<std::string> StatCollection::categories
private

Definition at line 76 of file StatCollection.h.

Referenced by addCategory(), LookupCategory(), lookupCategoryID(), and PrintStatsTable().

◆ excludeFilters

std::vector<std::string> StatCollection::excludeFilters
private

Definition at line 79 of file StatCollection.h.

Referenced by AddExcludeFilter(), ClearFilters(), and passFilter().

◆ includeFilters

std::vector<std::string> StatCollection::includeFilters
private

Definition at line 78 of file StatCollection.h.

Referenced by AddIncludeFilter(), ClearFilters(), and passFilter().

◆ owners

std::vector<std::string> StatCollection::owners
private

Definition at line 77 of file StatCollection.h.

Referenced by addOwner(), LookupOwner(), LookupOwnerID(), and PrintStatsTable().

◆ printOutput

bool StatCollection::printOutput
private

Definition at line 81 of file StatCollection.h.

Referenced by AddStat(), EnablePrintOutput(), StatCollection(), and SumStat().

◆ stats

std::vector<statistics> StatCollection::stats
private

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