1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_statistics_Accumulator_hpp
10 #define anna_statistics_Accumulator_hpp
12 #include <anna/core/RuntimeException.hpp>
13 #include <anna/core/functions.hpp>
27 namespace statistics {
34 //Sum = 0, // is not very useful
37 BesselStandardDeviation, //This correction (the use of N - 1 instead of N) is known as Bessel's correction
45 unsigned long long Size; // Sample size
46 double Sum; // Accumulated sum
47 double SquareSum; // Accumulated sum of square values
48 double Average; // Current average
49 //double SquareSumSampleDeviation; // Current total sum for square deviation items;
50 double MinimumProcessed; // Minimum value processed
51 double MaximumProcessed; // Maximum value processed
52 anna::Millisecond MinimumEventTimestampMs; // Timestamp (ms) for minimum event
53 anna::Millisecond MaximumEventTimestampMs; // Timestamp (ms) for maximum event
54 anna::Millisecond LastResetEventTimestampMs; // Timestamp (ms) for last statistics reset
58 Size = (unsigned long long)0;
60 SquareSum = (double)0;
62 //SquareSumSampleDeviation = (double)0;
63 MinimumProcessed = (double)0;
64 MaximumProcessed = (double)0;
65 MinimumEventTimestampMs = (anna::Millisecond)0;
66 MaximumEventTimestampMs = (anna::Millisecond)0;
67 LastResetEventTimestampMs = anna::Millisecond::getTime();
72 typedef std::map <int, _concept_data_t> _concept_data_map_t;
73 typedef std::map <int, _concept_data_t>::const_iterator _concept_data_map_iter;
78 //------------------------------------------------------------------------------
79 //------------------------------------------------------------ class Accumulator
80 //------------------------------------------------------------------------------
82 * Accumulated data information for statistic sample.
83 * It can manage a set of concepts at the same time.
85 * @short Contains statistical sample information
102 * Process new value for the sample.
104 * @param conceptId statistical concept processed
105 * @param value Value for processed item
109 void process(const int & conceptId, const double & value) throw(anna::RuntimeException);
113 * Reset sample for all concepts
117 void reset(void) throw();
121 * Reset sample for provided concept
123 * @param conceptId Concept identification to be reset
127 void reset(const int & conceptId) throw(anna::RuntimeException);
133 * @param accumulator Class instance source of data
135 * @return Returns copied reference
137 const Accumulator & operator = (const Accumulator & accumulator);
144 * Gets current sample size for any concept id
146 * @param conceptId Concept identification
148 * @return Sample size
153 unsigned long long int sampleSize(const int & conceptId) const throw(anna::RuntimeException);
157 * Get statistical information
159 * @param conceptId Statistical concept
160 * @param operation Solicited operation
162 * @return Value for solicited conceptId/operation
167 double getValue(const int & conceptId, const Operation::Type & operation) const throw(anna::RuntimeException);
171 * Class string representation
173 * @param numberOfDecimals Number of float decimals at representation string. Default is 2.
175 * @return String with class content
177 std::string asString(const int & numberOfDecimals = 2) const throw();
181 * Class XML representation
183 * @param numberOfDecimals Number of float decimals at XML representation. Default is 2.
185 * @return XML with class content
187 anna::xml::Node* asXML(anna::xml::Node* parent, const int & numberOfDecimals = 2) const throw();
192 void initialize(const int & conceptId) throw();
193 _concept_data_t * getConcept(const int & conceptId) const throw(anna::RuntimeException);
194 // Return NULL if no data is found for the concept Id
195 // Launch exception if concept id is not a valid concept registered at Engine
197 /*mutable */_concept_data_map_t a_concept_data_map;
199 std::string floatFormat(const int & numberOfDecimals) const throw();
201 double getStandardDeviation(const _concept_data_t * conceptData) const throw(anna::RuntimeException);
202 double getBesselStandardDeviation(const _concept_data_t * conceptData) const throw(anna::RuntimeException);