ANNA Suite  2020b
Multipurpose development suite for Telco applications
Accumulator.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
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 //
7 
8 
9 #ifndef anna_statistics_Accumulator_hpp
10 #define anna_statistics_Accumulator_hpp
11 
13 #include <anna/core/functions.hpp>
14 
15 // Standard
16 #include <string>
17 
18 namespace anna {
19 namespace xml {
20 class Node;
21 }
22 }
23 
24 
25 namespace anna {
26 
27 namespace statistics {
28 
29 
30 class Operation {
31 public:
32 
33  enum Type {
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
39  Maximum
40  };
41 };
42 
43 typedef struct {
44 
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
55 
56 
57  void reset() {
58  Size = (unsigned long long)0;
59  Sum = (double)0;
60  SquareSum = (double)0;
61  Average = (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();
68  }
69 
71 
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;
74 
75 
76 
77 
78 //------------------------------------------------------------------------------
79 //------------------------------------------------------------ class Accumulator
80 //------------------------------------------------------------------------------
87 class Accumulator {
88 
89  std::string a_name;
90 
91  void initialize(const int & conceptId) ;
92  _concept_data_t * getConcept(const int & conceptId) const noexcept(false);
93  // Gets the data structure for a existing concept Id.
94  // Initializes and returns the new data structure for a new stored concept Id which is valid (exists for the engine).
95  // Launch exception if concept id is not a valid concept registered at Engine.
96 
97  /*mutable */_concept_data_map_t a_concept_data_map;
98 
99  std::string floatFormat(const int & numberOfDecimals) const ;
100 
101  double getStandardDeviation(const _concept_data_t * conceptData) const noexcept(false);
102  double getBesselStandardDeviation(const _concept_data_t * conceptData) const noexcept(false);
103 
104 
105 public:
106 
112  Accumulator(const std::string &name) : a_name(name) {};
113 
118 
119 
125  void setName(const std::string &name) { a_name = name; }
126 
142  int addConcept(const std::string & description, const std::string & unit, const bool & integerNatureSample = true, const char *conceptNameFormat = "%s [%s]") ;
143 
152  void process(const int & conceptId, const double & value) noexcept(false);
153 
154 
160  void reset(void) ;
161 
162 
170  void reset(const int & conceptId) noexcept(false);
171 
172 
180  const Accumulator & operator = (const Accumulator & accumulator);
181 
182 
183 
184  // Gets
185 
191  const std::string &getName() const { return a_name; }
192 
203  unsigned long long int sampleSize(const int & conceptId) const noexcept(false);
204 
205 
217  double getValue(const int & conceptId, const Operation::Type & operation) const noexcept(false);
218 
219 
227  std::string asString(const int & numberOfDecimals = 2) const ;
228 
229 
237  anna::xml::Node* asXML(anna::xml::Node* parent, const int & numberOfDecimals = 2) const ;
238 };
239 
240 }
241 }
242 
243 #endif
static Millisecond getTime()
anna::Millisecond MaximumEventTimestampMs
Definition: Accumulator.hpp:53
Definition: Millisecond.hpp:24
Definition: Node.hpp:56
unsigned long long Size
Definition: Accumulator.hpp:45
double MinimumProcessed
Definition: Accumulator.hpp:50
double Average
Definition: Accumulator.hpp:48
double SquareSum
Definition: Accumulator.hpp:47
double MaximumProcessed
Definition: Accumulator.hpp:51
Type
Definition: Accumulator.hpp:33
Accumulator(const std::string &name)
Definition: Accumulator.hpp:112
Definition: Accumulator.hpp:43
void reset()
Definition: Accumulator.hpp:57
Definition: Accumulator.hpp:38
anna::Millisecond MinimumEventTimestampMs
Definition: Accumulator.hpp:52
std::map< int, _concept_data_t > _concept_data_map_t
Definition: Accumulator.hpp:72
const std::string & getName() const
Definition: Accumulator.hpp:191
xml::Node Node
Definition: Node.hpp:21
void setName(const std::string &name)
Definition: Accumulator.hpp:125
Definition: app.hpp:12
double Sum
Definition: Accumulator.hpp:46
Definition: Accumulator.hpp:30
anna::Millisecond LastResetEventTimestampMs
Definition: Accumulator.hpp:54
Contains statistical sample information.
Definition: Accumulator.hpp:87
Definition: Accumulator.hpp:35
std::map< int, _concept_data_t >::const_iterator _concept_data_map_iter
Definition: Accumulator.hpp:73
~Accumulator()
Definition: Accumulator.hpp:117