Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

StatisticAccumulator.ct

Go to the documentation of this file.
00001 // $Id: StatisticAccumulator.ct 1783 2011-04-17 11:58:37Z mtk $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <thorsten.horstmann@fit.fraunhofer.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 // Custom includes
00027 
00028 #define prefix_
00030 
00032 // senf::StatisticAccumulator<T>
00033 
00034 template <class T>
00035 prefix_ senf::StatisticAccumulator<T>::StatisticAccumulator( )
00036     : sum_squared_(0),
00037       sum_(0),
00038       min_(0),
00039       max_(0),
00040       last_avg_(0),
00041       count_(0)
00042 {
00043 }
00044 
00045 //template <class T>
00046 //prefix_ senf::StatisticAccumulator<T>::~StatisticAccumulator()
00047 //{ }
00048 
00049 template <class T>
00050 prefix_ float senf::StatisticAccumulator<T>::stddev()
00051     const
00052 {
00053     if (count_ == 0) {
00054         return NAN;
00055     }
00056     else if (count_ == 1) {
00057         return 0.0;
00058     }
00059     float _avg (avg());
00060     return sqrt( ( float(sum_squared_) / float( count_) ) - (_avg * _avg) );
00061 }
00062 
00063 template <class T>
00064 prefix_ void senf::StatisticAccumulator<T>::setLastAvg( T value)
00065 {
00066     last_avg_ = value;        
00067 }
00068 
00069 template <class T>
00070 prefix_ void senf::StatisticAccumulator<T>::accumulate( T value)
00071 {
00072     if (count_ == 0) {
00073         min_ = max_ = sum_ = value;
00074         sum_squared_ = value * value;
00075         count_++;
00076         return;
00077     }
00078     sum_ += value;
00079     sum_squared_ += value * value;
00080     count_++;
00081     if (value < min_)
00082         min_ = value;
00083     else if (value > max_)
00084         max_ = value;
00085 }
00086 
00087 template <class T>
00088 prefix_ void senf::StatisticAccumulator<T>::clear()
00089 {
00090     if( count_ > 0){
00091       last_avg_ = avg();
00092       count_ = 0;
00093       sum_squared_ = 0;
00094       sum_ = min_ = max_ = 0;
00095     }
00096 }
00097 
00098 template <class T>
00099 prefix_ void senf::StatisticAccumulator<T>::data( StatisticsData &data_) const
00100 {
00101     if( count_ == 0){
00102         data_.min = data_.avg = data_.max = last_avg_;
00103         data_.stddev = 0.0;
00104         data_.count = 0;
00105     }
00106     else{
00107       data_.min = (float) min_;
00108       data_.avg = avg();        
00109       data_.max = (float) max_;
00110       data_.stddev = stddev();
00111       data_.count = count_;
00112   }
00113 }
00114 
00115 
00117 #undef prefix_

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research