[PATCH] Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers

Wald Commits scm-commit at wald.intevation.org
Thu Oct 17 17:48:01 CEST 2013


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1382024878 -7200
# Node ID ad2fdc34910a4150c736076509f6234a6c821df2
# Parent  4b26fd60105f034333b31956e00cf1ad4fb95913
Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.

diff -r 4b26fd60105f -r ad2fdc34910a backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java
--- 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;
diff -r 4b26fd60105f -r ad2fdc34910a backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java	Thu Oct 17 15:26:12 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java	Thu Oct 17 17:47:58 2013 +0200
@@ -50,6 +50,8 @@
     public static final Pattern META_UNIT =
         Pattern.compile("^Einheit: \\[(.*)\\].*");
 
+    public static final double INTERVAL_GAP = 0.00001d;
+
     private List<ImportWst> waterlevels;
 
     private ImportWst current;
@@ -117,8 +119,20 @@
         if (current != null) {
             if (currentQRange != null) {
                 List<ImportWstColumnValue> cValues = column.getColumnValues();
-                // Set end of range to last station.
-                currentRange.setB(cValues.get(cValues.size() -1).getPosition());
+                // Set end of range to last station
+                // or 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
+                BigDecimal lastStation = cValues.get(cValues.size() -1).getPosition();
+                if (lastStation.compareTo(currentRange.getA()) == 0) {
+                    currentRange.setB(new BigDecimal(lastStation.doubleValue() 
+                        + INTERVAL_GAP));
+                }
+                else {
+                    currentRange.setB(lastStation);
+                }
+
                 currentQRange.setRange(currentRange);
                 column.addColumnQRange(currentQRange);
             }


More information about the Dive4elements-commits mailing list