changeset 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 4b26fd60105f
children aff189df381b
files backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java
diffstat 2 files changed, 31 insertions(+), 6 deletions(-) [+]
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;
--- 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);
             }

http://dive4elements.wald.intevation.org