changeset 253:07650fc6014c

Put a name to each Statistic group which is similar to the name of the Series in the Charts. issue83 gnv-artifacts/trunk@326 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 12 Nov 2009 10:15:05 +0000
parents f1e7ddeef5bc
children ce408af0ee57
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/StatisticSet.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java
diffstat 7 files changed, 227 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Nov 11 15:54:31 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Thu Nov 12 10:15:05 2009 +0000
@@ -1,3 +1,25 @@
+2009-11-12  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (writeStatistics2XML): 
+	  Changed XML-Syntaxt according to the new Structure of StatisticValues. 
+	  (out):
+	  Changed Call of calculateStatistics according to the new Methodsignature.  
+	
+	* src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java, 
+	  src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java. 
+	  src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java,
+	  src/main/java/de/intevation/gnv/statistics/Statistics.java: 
+	  Extended Methods calculateStatistics to put Lable-Values into the
+	  Calculation. Now for each Group of Statistics is it possible
+	  to calclulate a separat name which is simmilar to the name of 
+	  the Diagramm-Series-Name.
+	  Also the Representation of the Statistics has changed so each Group 
+	  will be stored in one StatisticSet
+	
+	* src/main/java/de/intevation/gnv/statistics/StatisticSet.java:
+	  Bean for Storing the Statistic to one Group and also storing the
+	  Name of the Statistic. 
+
 2009-11-11  Tim Englich  <tim.englich@intevation.de>
 
 	* src/main/java/de/intevation/gnv/transition/TransitionBase.java (putInputData): 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java	Wed Nov 11 15:54:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java	Thu Nov 12 10:15:05 2009 +0000
@@ -4,8 +4,10 @@
 package de.intevation.gnv.statistics;
 
 import java.sql.SQLException;
+import java.util.Collection;
 
 import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -24,4 +26,18 @@
     protected double calculateXOrdinateValue(Result row) throws SQLException {
         return 0; // TODO FIXME
     }
+
+    @Override
+    protected String generateStatisticsName(
+                                            String break1,
+                                            String break2,
+                                            String break3,
+                                            Collection<KeyValueDescibeData> parameters,
+                                            Collection<KeyValueDescibeData> measurements,
+                                            Collection<KeyValueDescibeData> dates) {
+        return (this.findValueTitle(parameters, break1)+ " "+ 
+                this.findValueTitle(measurements,break2)).trim()+" "+
+                this.findValueTitle(dates,break3);
+    }
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/StatisticSet.java	Thu Nov 12 10:15:05 2009 +0000
@@ -0,0 +1,40 @@
+/**
+ *
+ */
+package de.intevation.gnv.statistics;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class StatisticSet {
+
+    
+    private String name = null;
+    
+    private Collection<Statistic> statistics = new ArrayList<Statistic>();
+    
+    /**
+     * Constructor
+     */
+    public StatisticSet(String name) {
+        this.name = name;
+    }
+    
+    
+    public void addStatistic(Statistic statistic){
+        this.statistics.add(statistic);
+    }
+    
+    public Collection<Statistic> getStatistics(){
+        return this.statistics;
+    }
+    
+    public String getName(){
+        return this.name;
+    }
+
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java	Wed Nov 11 15:54:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java	Thu Nov 12 10:15:05 2009 +0000
@@ -19,6 +19,7 @@
 
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.statistics.exception.StatisticsException;
+import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
 
 /**
  * The interface <code>Statistics</code> fulfills the following purposes:
@@ -34,13 +35,21 @@
  */
 public interface Statistics {
 
-    /**
-     * @param resultSet
-     * @return
-     * @throws StatisticsException
-     */
-    public Collection<Statistic> calculateStatistics(
-                                                     Collection<Result> resultSet)
-                                                                                  throws StatisticsException;
+   /**
+    * 
+    * @param resultSet
+    * @param parameters
+    * @param measurements
+    * @param dates
+    * @return
+    * @throws StatisticsException
+    */
+    public Collection<StatisticSet>  calculateStatistics(
+                                                     Collection<Result> resultSet,
+                                                     Collection<KeyValueDescibeData> parameters,
+                                                     Collection<KeyValueDescibeData> measurements,
+                                                     Collection<KeyValueDescibeData> dates
+                                                     )
+                                                    throws StatisticsException;
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java	Wed Nov 11 15:54:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java	Thu Nov 12 10:15:05 2009 +0000
@@ -26,6 +26,7 @@
 
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.statistics.exception.StatisticsException;
+import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
 
 /**
  * The class <code>TimeseriesStatistics</code> fulfills the following purposes:
@@ -48,22 +49,25 @@
     private static Logger log = Logger.getLogger(TimeseriesStatistics.class);
     private static boolean sDebug = log.isDebugEnabled();
 
-    private Collection<Statistic> statistics = null;
 
     public TimeseriesStatistics() {
         super();
     }
 
     /**
-     * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection)
+     * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection)
      */
-    public Collection<Statistic> calculateStatistics(
-                                                     Collection<Result> resultSet)
-                                                                                  throws StatisticsException {
+    public Collection<StatisticSet> calculateStatistics(
+                                                     Collection<Result> resultSet,
+                                                     Collection<KeyValueDescibeData> parameters,
+                                                     Collection<KeyValueDescibeData> measurements,
+                                                     Collection<KeyValueDescibeData> dates
+                                                     )
+                                                     throws StatisticsException {
         DescriptiveStatistics lStatistics = null;
         SimpleRegression lRegression = null;
-        statistics = new ArrayList<Statistic>();
-        String break1, break2;
+        Collection<StatisticSet> statisticSets = new ArrayList<StatisticSet>();
+        String break1, break2, break3;
         int lSeries = 1;
         try {
 
@@ -72,13 +76,21 @@
                 Result row = resultIterator.next();
                 break1 = row.getString("GROUP1");
                 break2 = row.getString("GROUP2");
+                break3 = row.getString("GROUP3");
                 lRegression = new SimpleRegression();
                 lStatistics = DescriptiveStatistics.newInstance();
                 while (resultIterator.hasNext()) {
 
                     if (!break1.equals(row.getString("GROUP1"))
-                        || !break2.equals(row.getString("GROUP2"))) {
-                        addStatisticsValues(lStatistics, lRegression, lSeries);
+                        || !break2.equals(row.getString("GROUP2"))
+                        || !break3.equals(row.getString("GROUP3"))
+                        ) {
+                        String statisticsName = this.generateStatisticsName(break1, break2, 
+                                                                            break3, parameters, 
+                                                                            measurements, dates);
+                        statisticSets.add(this.generateStatisticsValues(lStatistics, 
+                                                                        lRegression,
+                                                                        statisticsName));
 
                         lStatistics.clear();
                         lRegression.clear();
@@ -89,6 +101,7 @@
 
                         break1 = row.getString("GROUP1");
                         break2 = row.getString("GROUP2");
+                        break3 = row.getString("GROUP3");
                         row = resultIterator.next();
                         lSeries++;
                     } else {
@@ -100,7 +113,13 @@
                     }
 
                 }
-                addStatisticsValues(lStatistics, lRegression, lSeries);
+                String statisticsName = this.generateStatisticsName(break1, break2, 
+                                                                    break3, parameters, 
+                                                                    measurements, dates);
+                
+                statisticSets.add(this.generateStatisticsValues(lStatistics, 
+                                                                lRegression, 
+                                                                statisticsName));
                 lStatistics.clear();
                 lRegression.clear();
             }
@@ -108,9 +127,45 @@
             log.error(e.getMessage(), e);
         }
 
-        return statistics;
+        return statisticSets;
     }
 
+    /**
+     * 
+     * @param break1
+     * @param break2
+     * @param break3
+     * @param parameters
+     * @param measurements
+     * @param dates
+     * @return
+     */
+    protected String generateStatisticsName(String break1, 
+                                            String break2,
+                                            String break3,
+                                            Collection<KeyValueDescibeData> parameters,
+                                            Collection<KeyValueDescibeData> measurements,
+                                            Collection<KeyValueDescibeData> dates){
+        log.debug("TimeseriesStatistics.generateStatisticsName");
+        return this.findValueTitle(parameters,break1)+ " "+
+               this.findValueTitle(measurements,break2) + "m";
+    }
+    
+    
+    protected String findValueTitle(Collection<KeyValueDescibeData> values,
+                                  String id) {
+        log.debug("TimeseriesStatistics.findValueTitle "+ id);
+        if (values != null) {
+            Iterator<KeyValueDescibeData> it = values.iterator();
+            while (it.hasNext()) {
+                KeyValueDescibeData data = it.next();
+                if (id.equals(data.getKey())) {
+                    return data.getValue();
+                }
+            }
+        }
+        return "";
+    }
     protected double calculateXOrdinateValue(Result row) throws SQLException {
         return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600);
     }
@@ -121,44 +176,46 @@
      * @param lStats
      * @param lSeries
      */
-    private void addStatisticsValues(DescriptiveStatistics lStatistics,
-                                     SimpleRegression lRegression, int lSeries) {
-        statistics.add(new Statistic("gnviewer.statistics.series",
-                lSeries));
-        statistics.add(new Statistic(
+    private StatisticSet generateStatisticsValues(DescriptiveStatistics lStatistics,
+                                     SimpleRegression lRegression, String  statisticName) {
+        
+        StatisticSet statisticSet = new StatisticSet(statisticName);
+        
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.arithmeticMean", lStatistics
                         .getMean()));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.kurtosis", lStatistics
                         .getKurtosis()));
-        statistics.add(new Statistic("gnviewer.statistics.descriptive.max",
+        statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.max",
                 lStatistics.getMax()));
-        statistics.add(new Statistic("gnviewer.statistics.descriptive.min",
+        statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.min",
                 lStatistics.getMin()));
-        statistics.add(new Statistic("gnviewer.statistics.descriptive.n",
+        statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.n",
                 lStatistics.getN()));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.percentile.90", lStatistics
                         .getPercentile(90)));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.percentile.75", lStatistics
                         .getPercentile(75)));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.percentile.50", lStatistics
                         .getPercentile(50)));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.percentile.10", lStatistics
                         .getPercentile(10)));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.deviation", lStatistics
                         .getStandardDeviation()));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.variance", lStatistics
                         .getVariance()));
-        statistics.add(new Statistic(
+        statisticSet.addStatistic(new Statistic(
                 "gnviewer.statistics.descriptive.intercept", lRegression
                         .getIntercept()));
-        statistics.add(new Statistic("gnviewer.statistics.descriptive.slope",
+        statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.slope",
                 lRegression.getSlope()));
+        return statisticSet;
     }
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java	Wed Nov 11 15:54:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java	Thu Nov 12 10:15:05 2009 +0000
@@ -4,8 +4,10 @@
 package de.intevation.gnv.statistics;
 
 import java.sql.SQLException;
+import java.util.Collection;
 
 import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -25,4 +27,19 @@
         return 0;
     }
 
+    @Override
+    protected String generateStatisticsName(
+                                            String break1,
+                                            String break2,
+                                            String break3,
+                                            Collection<KeyValueDescibeData> parameters,
+                                            Collection<KeyValueDescibeData> measurements,
+                                            Collection<KeyValueDescibeData> dates) {
+        
+        return (this.findValueTitle(parameters, break1)+ " "+ 
+               this.findValueTitle(measurements,break2)).trim();
+    }
+    
+    
+
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Wed Nov 11 15:54:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Thu Nov 12 10:15:05 2009 +0000
@@ -42,6 +42,7 @@
 import de.intevation.gnv.exports.Export.Profile;
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.statistics.Statistic;
+import de.intevation.gnv.statistics.StatisticSet;
 import de.intevation.gnv.statistics.Statistics;
 import de.intevation.gnv.statistics.TimeseriesStatistics;
 import de.intevation.gnv.statistics.exception.StatisticsException;
@@ -203,8 +204,17 @@
                 log.debug("Statistics will be generated.");
                 Statistics s = getStatisticsGenerator();
                 Collection<Result> chartResult = this.getChartResult(uuid);
-                Collection<Statistic> statistics = s
-                        .calculateStatistics(chartResult);
+                Collection<KeyValueDescibeData> parameters = 
+                                                this.getParameters(uuid);
+                Collection<KeyValueDescibeData> measurements = 
+                                                this.getMeasurements(uuid);
+                Collection<KeyValueDescibeData> dates = 
+                                                this.getDates(uuid);
+                Collection<StatisticSet> statistics = 
+                                      s.calculateStatistics(chartResult,
+                                                            parameters,
+                                                            measurements,
+                                                            dates);
                 Document doc = this.writeStatistics2XML(statistics);
                 this.writeDocument2OutputStream(doc, outputStream);
             } else if (outputMode.equalsIgnoreCase("odv")) {
@@ -283,21 +293,30 @@
         }
     }
 
-    protected Document writeStatistics2XML(Collection<Statistic> statistic) {
+    protected Document writeStatistics2XML( Collection<StatisticSet> statistic) {
         ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
         Document doc = XMLUtils.newDocument();
         if (statistic != null) {
             Node statisticResults = xmlUtilities.createArtifactElement(doc,
-                    "statistic-values");
+                    "statistics");
             doc.appendChild(statisticResults);
-            Iterator<Statistic> it = statistic.iterator();
+            Iterator<StatisticSet> it = statistic.iterator();
             while (it.hasNext()) {
-                Statistic s = it.next();
-                Element result = xmlUtilities.createArtifactElement(doc,
-                        "statistic");
-                result.setAttribute("name", s.getKey());
-                result.setAttribute("value", s.getStringValue());
-                statisticResults.appendChild(result);
+                StatisticSet set = it.next();
+                Element setElement = xmlUtilities.createArtifactElement(doc,
+                                                                       "statistic");
+                setElement.setAttribute("name", set.getName());
+                
+                Iterator<Statistic> sit = set.getStatistics().iterator();
+                while (sit.hasNext()){
+                    Statistic s = sit.next();
+                    Element result = xmlUtilities.createArtifactElement(doc,
+                    "statistic-value");
+                    result.setAttribute("name", s.getKey());
+                    result.setAttribute("value", s.getStringValue());
+                    setElement.appendChild(result);
+                }
+                statisticResults.appendChild(setElement);
             }
 
         }

http://dive4elements.wald.intevation.org