changeset 5229:016616df35dc

WaterlevelDifferencesParser: In analogy to WaterlevelParser, allow model conversion to Wst.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 11 Mar 2013 15:08:13 +0100
parents 8320427ecd5c
children fb7d43ba8147
files flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java	Mon Mar 11 15:07:19 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java	Mon Mar 11 15:08:13 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,13 @@
 import de.intevation.flys.importer.ImportWaterlevelDifferenceColumn;
 import de.intevation.flys.importer.ImportWaterlevelDifferenceValue;
 
+import de.intevation.flys.importer.ImportWst;
+import de.intevation.flys.importer.ImportWstColumn;
 
+
+/**
+ * Parse WaterlevelDifferences CSV file.
+ */
 public class WaterlevelDifferencesParser extends LineParser {
 
     private static final Logger log =
@@ -45,6 +52,35 @@
         return differences;
     }
 
+    public List<ImportWst> exportWsts() {
+        List<ImportWst> wsts = new ArrayList<ImportWst>();
+        for(ImportWaterlevelDifference waterlevel: getDifferences()) {
+            String description = waterlevel.getDescription();
+            ImportWst wst = new ImportWst();
+            wsts.add(wst);
+            wst.setDescription(description);
+            // Fixation kind.
+            wst.setKind(7);
+            wst.setUnit(waterlevel.getUnit());
+            wst.setNumberColumns(waterlevel.getColumns().size());
+
+            int i = 0;
+            for (ImportWaterlevelDifferenceColumn wdc: waterlevel.getColumns()) {
+                ImportWstColumn column = wst.getColumn(i);
+                column.setDescription(wdc.getDescription());
+                column.setName(wdc.getDescription());
+                column.setPosition(i);
+                for (ImportWaterlevelDifferenceValue val: wdc.getValues()) {
+                    column.addColumnValue(BigDecimal.valueOf(val.getStation()),
+                        BigDecimal.valueOf(val.getValue()));
+                
+                }
+                i++;
+            }
+        }
+        return wsts;
+    }
+
 
     @Override
     public void parse(File file) throws IOException {

http://dive4elements.wald.intevation.org