diff gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 95:13402ac8d8fe

Put the Statisticscalulation to the Outmethod of the OutputTransition. gnv-artifacts/trunk@140 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 28 Sep 2009 08:20:28 +0000
parents 6a825a184883
children fce237b6fdb8
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java	Mon Sep 28 07:32:03 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java	Mon Sep 28 08:20:28 2009 +0000
@@ -46,19 +46,22 @@
     /**
      * Default Logging instance
      */
-    private static Logger sLogger = Logger.getLogger(TimeseriesStatistics.class);
-    private static boolean sDebug = sLogger.isDebugEnabled();
+    private static Logger log = Logger.getLogger(TimeseriesStatistics.class);
+    private static boolean sDebug = log.isDebugEnabled();
 
-    private Statistic[] mStatistics = null;
+    private Collection<Statistic> statistics = null;
 
- 
-    public TimeseriesStatistics(Collection<Result> resultSet) throws StatisticsException {
+    public TimeseriesStatistics(){
+        super();
+    }
+    
+    public Collection<Statistic> calculateStatistics(Collection<Result> resultSet) throws StatisticsException {
         DescriptiveStatistics lStatistics = null;
         SimpleRegression lRegression = null;
-        ArrayList<Statistic> lStats = new ArrayList<Statistic>();
+        statistics = new ArrayList<Statistic>();
         int break1, break2;
         int lSeries = 1;
-        if (sDebug) sLogger.debug("TimeseriesStatistics() lImageFile != null");
+        if (sDebug) log.debug("TimeseriesStatistics() lImageFile != null");
         try{
             
             Iterator<Result> resultIterator = resultSet.iterator();
@@ -72,10 +75,8 @@
                 
                 if (break1 != row.getInteger("GROUP1")
                         || break2 != row.getInteger("GROUP2")) {
-                    //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd);
-                    //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd);
-                    
-                    addStatisticsValues(lStatistics, lRegression, lStats, lSeries);
+
+                    addStatisticsValues(lStatistics, lRegression, lSeries);
                     
                     lStatistics.clear();
                     lRegression.clear();
@@ -97,17 +98,18 @@
                 }
                 
             }
-            addStatisticsValues(lStatistics, lRegression, lStats, lSeries);
+            addStatisticsValues(lStatistics, lRegression,lSeries);
             lStatistics.clear();
             lRegression.clear();
-            mStatistics = new Statistic[lStats.size()];
-            mStatistics = lStats.toArray(mStatistics);
             }
         }
         catch (Exception e){
-            sLogger.error(e.getMessage(), e);
+            log.error(e.getMessage(), e);
         }
+        
+        return statistics;
     }
+    
     /**
      * @param lStatistics
      * @param lRegression
@@ -115,29 +117,20 @@
      * @param lSeries
      */
     private void addStatisticsValues(DescriptiveStatistics lStatistics,
-            SimpleRegression lRegression, ArrayList<Statistic> lStats,
-            int lSeries) {
-        lStats.add(new Statistic("gnviewer.statistics.series",(double)lSeries));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90)));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75)));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50)));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10)));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept()));
-        lStats.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope()));
+            SimpleRegression lRegression, int lSeries) {
+        statistics.add(new Statistic("gnviewer.statistics.series",(double)lSeries));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90)));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75)));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50)));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10)));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept()));
+        statistics.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope()));
     } 
-
-    /**
-     * 
-     * @return
-     */
-    public Statistic[] getStatistics() {
-        return mStatistics;
-    }
 }

http://dive4elements.wald.intevation.org