Loading...
Searching...
No Matches
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{
31public:
33 std::string error;
34};
35
36
70public:
71
73 Statistics();
74
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
119protected:
120
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
A class to compute statistics about quantities of interest.
Definition: statistics.hpp:69
long double get_min(std::string name)
Definition: statistics.cpp:177
long double get_max(std::string name)
Definition: statistics.cpp:189
bool active
Definition: statistics.hpp:149
long double get_total(std::string name)
Definition: statistics.cpp:153
bool quantity_exists(std::string name)
Definition: statistics.cpp:43
void store(std::string name, const double &value)
Definition: statistics.cpp:48
Statistics()
Definition: statistics.cpp:32
std::map< std::string, QuantityData > * records_of
Definition: statistics.hpp:153
void report_all(int precision=2, std::ostream &output=std::cout)
Definition: statistics.cpp:83
void turn_on()
Definition: statistics.cpp:112
long double get_last(std::string name)
Definition: statistics.cpp:201
void reset_all()
Definition: statistics.cpp:72
void turn_off()
Definition: statistics.cpp:118
~Statistics()
Definition: statistics.cpp:38
void reset(std::string name)
Definition: statistics.cpp:95
void report(std::string name, int precision=2, std::ostream &output=std::cout)
Definition: statistics.cpp:124
long double get_average(std::string name)
Definition: statistics.cpp:165
Statistics & getStatistics()
Definition: statistics.cpp:26
Definition: statistics.hpp:30
StatisticsException(std::string error)
Definition: statistics.hpp:32
std::string error
Definition: statistics.hpp:33
Definition: statistics.hpp:122
int stops
Definition: statistics.hpp:145
long double max
Definition: statistics.hpp:139
long double min
Definition: statistics.hpp:136
long double last
Definition: statistics.hpp:142
long double total
Definition: statistics.hpp:133
QuantityData()
Definition: statistics.hpp:124