diff backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java @ 7377:ad2fdc34910a

Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
author Tom Gottfried <tom@intevation.de>
date Thu, 17 Oct 2013 17:47:58 +0200
parents e032e9e6d09e
children fc8d5b5f2c99
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java	Thu Oct 17 15:26:12 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java	Thu Oct 17 17:47:58 2013 +0200
@@ -46,6 +46,8 @@
     public static final Pattern YEARS_IN_COLUMN =
         Pattern.compile(".*(\\d{4})-(\\d{4})$");
 
+    public static final double INTERVAL_GAP = 0.00001d;
+
     /** List of parsed differences as ImportWst s. */
     private List<ImportWst> differences;
 
@@ -98,14 +100,23 @@
         }
 
         // For all differences columns, add a single Q-Range with
-        // 0.
+        // -1.
+        // Expand range to minimal length in case it would be 0
+        // TODO: should otherwise be extended to 
+        // (first station of next range - INTERVAL_GAP), 
+        // assuming always ascending stations
         for (ImportWstColumn column: columns) {
             List<ImportWstColumnValue> cValues = column.getColumnValues();
+            BigDecimal a = cValues.get(0).getPosition();
+            BigDecimal b = cValues.get(cValues.size() - 1).getPosition();
+            if (a.compareTo(b) == 0) {
+                b = new BigDecimal(b.doubleValue() + INTERVAL_GAP);
+            }
             column.addColumnQRange(
                 new ImportWstQRange(
-                    cValues.get(0).getPosition(),
-                    cValues.get(cValues.size() - 1).getPosition(),
-                    new BigDecimal(0d))
+                    a,
+                    b,
+                    new BigDecimal(-1d))
                 );
         }
         current = null;

http://dive4elements.wald.intevation.org