Author: sebb
Date: Thu Mar 11 22:55:21 2010
New Revision: 922051

URL: http://svn.apache.org/viewvc?rev=922051&view=rev
Log:
Implement addValue(T val, int sampleCount) method to simplify processing 
aggregated samples

Modified:
    jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java
    
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java
    
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java

Modified: 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java?rev=922051&r1=922050&r2=922051&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java 
(original)
+++ 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java 
Thu Mar 11 22:55:21 2010
@@ -191,29 +191,44 @@ public abstract class StatCalculator<T e
         return count;
     }
 
-    public void addValue(T val) {
-        updateValueCount(val);
-        count++;
+    protected abstract T divide(T val, int n);
+
+    public void addValue(T val, int sampleCount) {
+        updateValueCount(val, sampleCount);
+        count += sampleCount;
         double currentVal = val.doubleValue();
         sum += currentVal;
-        sumOfSquares += currentVal * currentVal;
+        T actualValue = val;
+        if (sampleCount > 1){
+            // For n values in an aggregate sample the average value = (val/n)
+            // So need to add n * (val/n) * (val/n) = val * val / n
+            sumOfSquares += currentVal * currentVal / sampleCount;
+            actualValue = divide(val, sampleCount);
+        } else {
+            sumOfSquares += currentVal * currentVal;
+            actualValue = val;
+        }
         mean = sum / count;
         deviation = Math.sqrt((sumOfSquares / count) - (mean * mean));
-        if (val.compareTo(max) > 0){
-            max=val;
+        if (actualValue.compareTo(max) > 0){
+            max=actualValue;
         }
-        if (val.compareTo(min) < 0){
-            min=val;
+        if (actualValue.compareTo(min) < 0){
+            min=actualValue;
         }
     }
 
-    private void updateValueCount(T val) {
+    public void addValue(T val) {
+        addValue(val,1);
+    }
+
+    private void updateValueCount(T val, int sampleCount) {
         MutableLong count = valuesMap.get(val);
         if (count != null) {
-            count.increment();
+            count.add(sampleCount);
         } else {
             // insert new value
-            valuesMap.put(val, new MutableLong(1L));
+            valuesMap.put(val, new MutableLong(sampleCount));
         }
     }
 }

Modified: 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java?rev=922051&r1=922050&r2=922051&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java
 (original)
+++ 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorInteger.java
 Thu Mar 11 22:55:21 2010
@@ -30,4 +30,13 @@ public class StatCalculatorInteger exten
     public void addValue(int val){
         super.addValue(new Integer(val));
     }
+
+    public void addValue(int val, int sampleCount){
+        super.addValue(new Integer(val), sampleCount);
+    }
+
+    @Override
+    protected Integer divide(Integer val, int n) {
+        return new Integer(val.intValue() / n);
+    }
 }

Modified: 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java?rev=922051&r1=922050&r2=922051&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java
 (original)
+++ 
jakarta/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculatorLong.java
 Thu Mar 11 22:55:21 2010
@@ -30,4 +30,13 @@ public class StatCalculatorLong extends 
     public void addValue(long val){
         super.addValue(new Long(val));
     }
+
+    public void addValue(long val, int sampleCount){
+        super.addValue(new Long(val), sampleCount);
+    }
+
+    @Override
+    protected Long divide(Long val, int n) {
+        return new Long(val.longValue() / n);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org

Reply via email to