[Dive4elements-commits] [PATCH 1 of 3] WaterlevelParser: Add Wst-Converting functionality

Wald Commits scm-commit at wald.intevation.org
Wed Feb 20 12:08:33 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1361358851 -3600
# Node ID b5e3df1feeb41d6aca114e0d15702b2f645fa2ff
# Parent  1c34acb084ee37faf76fb0d7063975ab9dec32cd
WaterlevelParser: Add Wst-Converting functionality.

diff -r 1c34acb084ee -r b5e3df1feeb4 flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java	Wed Feb 20 11:52:52 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java	Wed Feb 20 12:14:11 2013 +0100
@@ -2,6 +2,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -16,7 +17,19 @@
 import de.intevation.flys.importer.ImportWaterlevelQRange;
 import de.intevation.flys.importer.ImportWaterlevelValue;
 
+import de.intevation.flys.importer.ImportWstColumn;
+import de.intevation.flys.importer.ImportRange;
+import de.intevation.flys.importer.ImportWst;
+import de.intevation.flys.importer.ImportWstQRange;
 
+
+/**
+ * Parse CSV Waterlevel files.
+ * As these waterlevels are probably used in fixation analysis
+ * only, functionality to export them to "fixation"-wsts
+ * has been added (the ImportWaterlevel*- stuff is actually
+ * not needed to do so.)
+ */
 public class WaterlevelParser extends LineParser {
 
     private static final Logger log = Logger.getLogger(WaterlevelParser.class);
@@ -44,6 +57,56 @@
     }
 
 
+    /**
+     * Create ImportWst objects from ImportWaterlevel
+     * objects.
+     */
+    public List<ImportWst> exportWsts() {
+        List<ImportWst> wsts = new ArrayList<ImportWst>();
+        for(ImportWaterlevel waterlevel: getWaterlevels()) {
+            String description = waterlevel.getDescription();
+            ImportWst wst = new ImportWst();
+            wsts.add(wst);
+            wst.setDescription(description);
+            // Fixation kind.
+            wst.setKind(2);
+            wst.setUnit(waterlevel.getUnit());
+
+            // Fake WST has but 1 column.
+            wst.setNumberColumns(1);
+            ImportWstColumn column = wst.getColumn(0);
+            column.setDescription(description);
+            column.setName(description);
+            column.setPosition(0);
+
+            // Build Q Range.
+            List<ImportWaterlevelQRange> qRanges = waterlevel.getQRanges();
+            for(ImportWaterlevelQRange range: qRanges) {
+                List<ImportWaterlevelValue> values = range.getValues();
+                if (values.size() < 2) {
+                    log.warn ("Not enough values to build valid QRange");
+                    continue;
+                }
+                ImportRange iRange = new ImportRange(
+                   BigDecimal.valueOf(values.get(0).getStation()),
+                   BigDecimal.valueOf(values.get(values.size() -1).getStation()));
+                column.addColumnQRange(
+                     new ImportWstQRange(iRange, BigDecimal.valueOf(range.getQ())));
+            }
+
+            // The other W/KM values.
+            for(ImportWaterlevelQRange range: qRanges) {
+                for(ImportWaterlevelValue value: range.getValues()) {
+                    column.addColumnValue(BigDecimal.valueOf(value.getStation()),
+                                          BigDecimal.valueOf(value.getW()));
+                }
+            }
+            // TODO Maybe set a timeinterval.
+        }
+        return wsts;
+    }
+
+
     public List<ImportWaterlevel> getWaterlevels() {
         return waterlevels;
     }


More information about the Dive4elements-commits mailing list