08ba3447f0d6c21cbda70a32e85a22809270d621
[senf.git] / senf / Utils / StatisticAccumulator.hh
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief StatisticAccumulator public header */
25
26 #ifndef HH_SENF_Utils_StatisticAccumulator_
27 #define HH_SENF_Utils_StatisticAccumulator_ 1
28
29 // Custom includes
30 #include <math.h>
31 #include <boost/cstdint.hpp>
32 ///////////////////////////////hh.p////////////////////////////////////////
33 namespace senf {
34
35      struct StatisticsData
36      {
37          float min;
38          float max;
39          float avg;
40          float stddev;
41          boost::uint32_t count;
42      };
43
44      /** \brief Accumulate measurement values
45
46          The accumulator mainly do the prelimenary work for the senf::Statistic class.
47          It accumulates certain values with in an interval to be used by senf::Statistics
48
49          \li the senf::Statistics class
50          \li statistics sources
51
52          This class provides the average, standard deviation, min, max values over one
53          interval, means until clear() is called. It rather directly calculates the results
54          then collection all single values provided by calling accumulate().
55          \see senf::Statistics to process accumulated values
56          \ingroup senf_statistics
57       */
58     template <class T>
59     class StatisticAccumulator
60     {
61     public:
62         StatisticAccumulator();
63 //        virtual ~StatisticAccumulator();
64
65         void clear();
66         ///< Reset accumulated values.
67         /**< This member reset all values. */
68         void accumulate(T value);
69         ///< Gather value to be accumulated.
70         /**< This method accumulate a value.
71              \param[in] value to be accumulated value*/
72
73     public:
74         T     min() const;
75         ///< Returns current minimal value.
76         /**< This method returns the minimal value of the current accumulation.*/
77         T     max() const;
78         ///< Returns current maximal value.
79         /**< This method returns the maximal value of the current accumulation.*/
80         float avg() const;
81         ///< Returns average value.
82         /**< This method returns the average value of the current accumulation.*/
83         float last_avg() const;
84         ///< Returns former average value.
85         /**< This method returns the average value of the former accumulation period.*/
86         float stddev() const;
87         ///< Returns standard deviation value.
88         /**< This method returns the standard deviation value of the current accumulation.*/
89         boost::uint32_t count() const;
90         ///< Returns count of accumulated values.
91         /**< This method returns count of accumulated values of the current accumulation.*/
92         void data( StatisticsData & data_) const;
93         ///< Returns the accumulated data as a tuple
94         /**< This method returns the accumulated information as a tuple.*/  
95
96     private:
97         T sum_squared_;
98         T sum_;
99         T min_;
100         T max_;
101         float last_avg_;
102         boost::uint32_t count_;
103
104
105     };
106
107
108     typedef StatisticAccumulator<int> StatisticAccumulatorInt;
109     typedef StatisticAccumulator<float> StatisticAccumulatorFloat;
110
111 }
112 ///////////////////////////////hh.e////////////////////////////////////////
113 //#include "StatisticAccumulator.cci"
114 #include "StatisticAccumulator.ct"
115 #include "StatisticAccumulator.cti"
116 #endif
117