do not reset the last_avg() if no new values have been reported in the current period
mtk [Wed, 19 Jan 2011 14:11:37 +0000 (14:11 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1767 270642c3-0616-0410-b53a-bc976706d245

senf/Utils/StatisticAccumulator.ct

index 0117732..9e5d106 100644 (file)
@@ -81,20 +81,29 @@ prefix_ void senf::StatisticAccumulator<T>::accumulate( T value)
 template <class T>
 prefix_ void senf::StatisticAccumulator<T>::clear()
 {
-    last_avg_ = avg();
-    count_ = 0;
-    sum_squared_ = 0;
-    sum_ = min_ = max_ = 0;
+    if( count_ > 0){
+      last_avg_ = avg();
+      count_ = 0;
+      sum_squared_ = 0;
+      sum_ = min_ = max_ = 0;
+    }
 }
 
 template <class T>
 prefix_ void senf::StatisticAccumulator<T>::data( StatisticsData &data_) const
 {
-    data_.min = (float) min_;
-    data_.avg = avg();
-    data_.max = (float) max_;
-    data_.stddev = stddev();
-    data_.count = count_;
+    if( count_ == 0){
+       data_.min = data_.avg = data_.max = last_avg_;
+       data_.stddev = 0.0;
+       data_.count = 0;
+    }
+    else{
+      data_.min = (float) min_;
+      data_.avg = avg();       
+      data_.max = (float) max_;
+      data_.stddev = stddev();
+      data_.count = count_;
+  }
 }