statistics.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017 CNRS
3 //
4 // This file is part of tsid
5 // tsid is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 // tsid is distributed in the hope that it will be
10 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Lesser Public License for more details. You should have
13 // received a copy of the GNU Lesser General Public License along with
14 // tsid If not, see
15 // <http://www.gnu.org/licenses/>.
16 //
17 
18 
19 #ifndef __invdyn_statistics_H__
20 #define __invdyn_statistics_H__
21 
22 #include <iostream>
23 #include <map>
24 #include <sstream>
25 
26 #define STATISTICS_MAX_NAME_LENGTH 60
27 
28 // Generic statistics exception class
30 {
31 public:
32  StatisticsException(std::string error) : error(error) { }
33  std::string error;
34 };
35 
36 
69 class Statistics {
70 public:
71 
73  Statistics();
74 
76  ~Statistics();
77 
79  bool quantity_exists(std::string name);
80 
82  void store(std::string name, const double & value);
83 
85  void reset(std::string name);
86 
88  void reset_all();
89 
91  void report(std::string name, int precision=2,
92  std::ostream& output = std::cout);
93 
95  void report_all(int precision=2, std::ostream& output = std::cout);
96 
98  long double get_total(std::string name);
99 
101  long double get_average(std::string name);
102 
104  long double get_min(std::string name);
105 
107  long double get_max(std::string name);
108 
110  long double get_last(std::string name);
111 
114  void turn_off();
115 
117  void turn_on();
118 
119 protected:
120 
122  struct QuantityData {
123 
125  total(0),
126  min(0),
127  max(0),
128  last(0),
129  stops(0) {
130  }
131 
133  long double total;
134 
136  long double min;
137 
139  long double max;
140 
142  long double last;
143 
145  int stops;
146  };
147 
149  bool active;
150 
153  std::map<std::string, QuantityData >* records_of;
154 
155 };
156 
158 
159 #endif
Definition: statistics.hpp:29
std::string error
Definition: statistics.hpp:33
long double last
Definition: statistics.hpp:142
Definition: statistics.hpp:122
bool active
Definition: statistics.hpp:149
long double min
Definition: statistics.hpp:136
A class to compute statistics about quantities of interest.
Definition: statistics.hpp:69
StatisticsException(std::string error)
Definition: statistics.hpp:32
QuantityData()
Definition: statistics.hpp:124
long double total
Definition: statistics.hpp:133
std::map< std::string, QuantityData > * records_of
Definition: statistics.hpp:153
int stops
Definition: statistics.hpp:145
long double max
Definition: statistics.hpp:139
Statistics & getStatistics()
Definition: statistics.cpp:26