changeset 255:5403452c06fc

Added proper values for calculating the Statistics of VerticalProfiles and HorizontalProfiles issue86 gnv-artifacts/trunk@330 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 12 Nov 2009 14:47:20 +0000
parents ce408af0ee57
children 008709f79611
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalCrossSectionStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java
diffstat 5 files changed, 74 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Thu Nov 12 11:40:32 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Thu Nov 12 14:47:20 2009 +0000
@@ -1,5 +1,17 @@
 2009-11-12  Tim Englich  <tim.englich@intevation.de>
 
+	* src/main/java/de/intevation/gnv/statistics/HorizontalCrossSectionStatistics.java (calculateXOrdinateValue), 
+	  src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java (calculateXOrdinateValue), 
+	  src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java (calculateXOrdinateValue), 
+	  src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java :
+	  Added the previous Row to the Method for calculating the GAP between 
+	  those Rows. Also added Calculation of the Distance between two Points in 
+	  HorizontalProfileStatistic and returning the Depth in VerticalProfileStatistics.
+	  Also added the Metjod clearStatistics to restet the Object if an new Calculation
+	  will started. 
+
+2009-11-12  Tim Englich  <tim.englich@intevation.de>
+	
 	* src/main/java/de/intevation/gnv/transition/TransitionBase.java (extractKVP): 
 	  Translated "Keine Auswahl" to "No Selection" according to the Specification that
 	  the primary Language is english. Please note that the Values  that are currently 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalCrossSectionStatistics.java	Thu Nov 12 11:40:32 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalCrossSectionStatistics.java	Thu Nov 12 14:47:20 2009 +0000
@@ -21,7 +21,7 @@
     }
 
     @Override
-    protected double calculateXOrdinateValue(Result row) throws SQLException {
+    protected double calculateXOrdinateValue(Result previousRow,Result row) throws SQLException {
         return 0; // TODO: Select propper Value
     }
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java	Thu Nov 12 11:40:32 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java	Thu Nov 12 14:47:20 2009 +0000
@@ -6,15 +6,30 @@
 import java.sql.SQLException;
 import java.util.Collection;
 
+import org.apache.log4j.Logger;
+
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
+import de.intevation.gnv.utils.DistanceCalculator;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  * 
  */
 public class HorizontalProfileStatistics extends TimeseriesStatistics {
+    
+    private static Logger log = Logger.getLogger(HorizontalProfileStatistics.class);
 
+    private WKTReader wktReader = new WKTReader();
+    
+    private DistanceCalculator dc = new DistanceCalculator();
+    
+    private double distance = 0;
+    
     /**
      * Constructor
      */
@@ -22,11 +37,29 @@
         super();
     }
 
+    /**
+     * @see de.intevation.gnv.statistics.TimeseriesStatistics#calculateXOrdinateValue(de.intevation.gnv.geobackend.base.Result, de.intevation.gnv.geobackend.base.Result)
+     */
     @Override
-    protected double calculateXOrdinateValue(Result row) throws SQLException {
-        return 0; // TODO FIXME
+    protected double calculateXOrdinateValue(Result previousRow,Result row)
+                     throws SQLException {
+        try {
+            Point start = (Point)this.wktReader.read(previousRow.getString("SHAPE"));
+            Point current = (Point)this.wktReader.read(row.getString("SHAPE"));
+            double delta = this.dc.calculateDistance(start, current);
+            
+            if (!Double.isNaN(delta)){
+                this.distance = this.distance + delta;
+            }
+        } catch (ParseException e) {
+            log.error(e,e);
+        }
+        return this.distance;
     }
 
+    /**
+     * @see de.intevation.gnv.statistics.TimeseriesStatistics#generateStatisticsName(java.lang.String, java.lang.String, java.lang.String, java.util.Collection, java.util.Collection, java.util.Collection)
+     */
     @Override
     protected String generateStatisticsName(
                                             String break1,
@@ -39,5 +72,15 @@
                 this.findValueTitle(measurements,break2)).trim()+" "+
                 this.findValueTitle(dates,break3);
     }
+    
+    /**
+     * @see de.intevation.gnv.statistics.TimeseriesStatistics#clearStatistics()
+     */
+    @Override
+    protected void clearStatistics() {
+        log.debug("HorizontalProfileStatistics.clearStatistics");
+        super.clearStatistics();
+        this.distance = 0;
+    }
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java	Thu Nov 12 11:40:32 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java	Thu Nov 12 14:47:20 2009 +0000
@@ -47,9 +47,10 @@
      * Default Logging instance
      */
     private static Logger log = Logger.getLogger(TimeseriesStatistics.class);
-    private static boolean sDebug = log.isDebugEnabled();
 
-
+    /**
+     * Constructor
+     */
     public TimeseriesStatistics() {
         super();
     }
@@ -64,6 +65,7 @@
                                                      Collection<KeyValueDescibeData> dates
                                                      )
                                                      throws StatisticsException {
+        this.clearStatistics();
         DescriptiveStatistics lStatistics = null;
         SimpleRegression lRegression = null;
         Collection<StatisticSet> statisticSets = new ArrayList<StatisticSet>();
@@ -74,6 +76,7 @@
             Iterator<Result> resultIterator = resultSet.iterator();
             if (resultIterator.hasNext()) {
                 Result row = resultIterator.next();
+                Result previousRow = row;
                 break1 = row.getString("GROUP1");
                 break2 = row.getString("GROUP2");
                 break3 = row.getString("GROUP3");
@@ -94,21 +97,25 @@
 
                         lStatistics.clear();
                         lRegression.clear();
+                        
+                        this.clearStatistics();
 
                         lStatistics.addValue(row.getDouble("YORDINATE"));
-                        Double x = this.calculateXOrdinateValue(row);
+                        Double x = this.calculateXOrdinateValue(previousRow,row);
                         lRegression.addData(x, row.getDouble("YORDINATE"));
 
                         break1 = row.getString("GROUP1");
                         break2 = row.getString("GROUP2");
                         break3 = row.getString("GROUP3");
+                        previousRow = row;
                         row = resultIterator.next();
                         lSeries++;
                     } else {
 
                         lStatistics.addValue(row.getDouble("YORDINATE"));
-                        Double x = this.calculateXOrdinateValue(row);
+                        Double x = this.calculateXOrdinateValue(previousRow, row);
                         lRegression.addData(x, row.getDouble("YORDINATE"));
+                        previousRow = row;
                         row = resultIterator.next();
                     }
 
@@ -130,6 +137,8 @@
         return statisticSets;
     }
 
+    protected void clearStatistics(){}
+    
     /**
      * 
      * @param break1
@@ -166,7 +175,7 @@
         }
         return "";
     }
-    protected double calculateXOrdinateValue(Result row) throws SQLException {
+    protected double calculateXOrdinateValue(Result previousRow, Result row) throws SQLException {
         return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600);
     }
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java	Thu Nov 12 11:40:32 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java	Thu Nov 12 14:47:20 2009 +0000
@@ -23,8 +23,8 @@
     }
 
     @Override
-    protected double calculateXOrdinateValue(Result row) throws SQLException {
-        return 0;
+    protected double calculateXOrdinateValue(Result previousRow, Result row) throws SQLException {
+        return row.getDouble("XORDINATE");
     }
 
     @Override

http://dive4elements.wald.intevation.org