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_Engine_hpp
10 #define anna_statistics_Engine_hpp
12 #include <anna/core/Singleton.hpp>
13 #include <anna/core/util/Millisecond.hpp>
20 #include <anna/statistics/Accumulator.hpp>
32 namespace statistics {
37 std::string SampleFile; // Sample file to optional writtings
38 std::string Description;
40 bool IntegerNatureSample;
42 } _concept_identification_t;
44 typedef std::map <int, _concept_identification_t> _concept_identification_map_t;
45 typedef std::map <int, _concept_identification_t>::const_iterator _concept_identification_map_iter;
46 typedef std::map <int, _concept_identification_t>::iterator _concept_identification_map_nc_iter;
51 * Class used to configure general behaviour of statistics processing
52 * By default, the engine is disabled and #enable must be invoked
55 class Engine : public anna::Singleton <Engine> {
63 * Adds a new statistic concept (for example "Time_between_processA_and_processB", "Database time", etc)
65 * @param description Concept description
66 * @param unit Concept unit description
67 * @param integerNatureSample Most of cases we will measure 'time' with the unit which force integer values
68 * (is more intuitive 850 msecs than 0,850 secs). Then, it is @em true by default.
69 * This is useful to advice better representation for some indicators like minimum/maximum
70 * within integer samples.
72 * @return Assigned concept identification number (sequence)
74 int addConcept(const std::string & description, const std::string & unit, const bool & integerNatureSample = true) throw();
78 * Stops statistics engine
80 void enable(void) throw() { a_enabled = true; }
84 * Starts statistics engine
86 void disable(void) throw() { a_enabled = false; }
89 * Enable sample log for statistics processings. Engine starts with this feature disabled. When a new concept id is added
90 * to the engine, sample log is also disabled for it.
92 * Sample logs are used to dump each processing for a certain concept identification (<unix timestamp>,<processed value>).
95 * @param id Concept identification. If -1 value is provided, all concepts will be activated.
96 * @param sampleFileName Absolute or relative to execution path, and completed with extension '.<concept id>.csv'. Empty string, disables log. Default file name is 'sample'
98 * @return @em false if not concept is registered with provided id
99 * @warning Many systems add concepts dynamically. This method only affects to current concepts registered at statistics engine.
101 bool enableSampleLog(const int & id = -1, const char *sampleFileName = NULL) throw();
105 * Disable sample log for statistics processings
107 * @param id Concept identification.
109 * @return @em false if not concept is registered with provided id
111 bool disableSampleLog(const int & id) throw();
116 * Gets statistic concept information.
118 * @param id Concept identification.
119 * @param description Concept description returned by reference
120 * @param unit Concept unit description returned by reference
121 * @param integerNatureSample nature returned by reference
123 * @return @em false if not concept is registered with provided id
125 bool getConcept(const int & id, std::string & description, std::string & unit, bool & integerNatureSample) const throw();
129 * Boolean about engine state (enabled / disabled)
131 bool enabled(void) const throw() { return (a_enabled); }
135 * Class string representation
137 * @return String with class content
139 std::string asString(void) const throw();
143 * Class XML representation
145 * @param numberOfDecimals Number of float decimals at XML representation. Default is 2.
147 * @return XML with class content
149 anna::xml::Node* asXML(anna::xml::Node* parent, const int & numberOfDecimals = 2) const throw();
154 Engine(); // private constructor
156 _concept_identification_map_t a_concept_identification_map;
158 int a_sequence_concept_id;
160 bool logSample(const int & conceptId, const anna::Millisecond & unixTimestamp, const double & value) const throw();
162 friend class anna::Singleton <Engine>;
163 friend class Accumulator;