changeset 3275:3570abdf7daa

SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists. flys-artifacts/trunk@4919 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 10 Jul 2012 17:04:04 +0000
parents 43e42315ce22
children 4903e491992e
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java
diffstat 2 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jul 10 16:37:48 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jul 10 17:04:04 2012 +0000
@@ -1,3 +1,8 @@
+2012-07-12	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/SQOverview.java:
+	  Made km separating of dates epsilon tolerant and avoid empty date lists.
+
 2012-07-10  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/SQKMChartService.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java	Tue Jul 10 16:37:48 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java	Tue Jul 10 17:04:04 2012 +0000
@@ -83,14 +83,14 @@
 
     private static Logger log = Logger.getLogger(FixingsOverview.class);
 
-    public static final double EPSILON = 1e-1;
+    public static final double EPSILON = 1e-4;
 
     public static final String DATE_FORMAT = "dd.MM.yyyy";
 
     public static final String SQL_SQ =
         "SELECT" +
-        "    s.km," +
-        "    m.datum " +
+        "    s.km    AS km," +
+        "    m.datum AS datum " +
         "FROM messung m " +
         "    JOIN station s" +
         "       on m.stationid = s.stationid " +
@@ -114,6 +114,10 @@
         this.riverName = riverName;
     }
 
+    private static final boolean epsilonEquals(double a, double b) {
+        return Math.abs(a - b) < EPSILON;
+    }
+
     protected void loadData(Session session) {
         SQLQuery query = session.createSQLQuery(SQL_SQ)
             .addScalar("km", StandardBasicTypes.DOUBLE)
@@ -127,22 +131,22 @@
             log.warn("No river '" + riverName + "' found.");
         }
 
-        Double prevKm = -1d;
+        Double prevKm = -Double.MAX_VALUE;
         List<Date> dates = new ArrayList<Date>();
-        for (int i = 0; i < list.size(); i++) {
-            Object[] row = list.get(i);
-            Double km = (Double) row[0];
-            Date date = (Date) row[1];
-            if (km.equals(prevKm)) {
-                dates.add(date);
-            }
-            else {
+
+        for (Object [] row: list) {
+            Double km = (Double)row[0];
+            if (!epsilonEquals(km, prevKm) && !dates.isEmpty()) {
                 entries.add(prevKm, dates);
                 dates = new ArrayList<Date>();
-                dates.add(date);
             }
+            dates.add((Date)row[1]);
             prevKm = km;
         }
+
+        if (!dates.isEmpty()) {
+            entries.add(prevKm, dates);
+        }
     }
 
     public boolean load(Session session) {
@@ -158,6 +162,7 @@
     }
 
     public KMIndex<List<Date>> filter(Filter f) {
+        // TODO: Apply filter
         return entries;
     }
 
@@ -203,4 +208,4 @@
         document.appendChild(sqElement);
     }
 }
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
\ No newline at end of file
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org