changeset 2068:0cf60d64895c

#370 Added a 'W at gauge' column to CSV exports if 'W at gauge' mode has been selected. flys-artifacts/trunk@3563 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 02 Jan 2012 13:30:44 +0000
parents 40624968c7f4
children b18f056c244e
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
diffstat 4 files changed, 82 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jan 02 11:01:29 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jan 02 13:30:44 2012 +0000
@@ -1,3 +1,16 @@
+2012-01-02  Ingo Weinzierl <ingo@intevation.de>
+
+	flys/issue370 (WINFO: Berechnungsausgabe W/Pegel [cm] fehlt bei Wasserspiegellage und W am Pegel)
+
+	* src/main/java/de/intevation/flys/utils/FLYSUtils.java: New method that
+	  extracts the double value of a WQ object's name.
+
+	* src/main/java/de/intevation/flys/exports/WaterlevelExporter.java: Adapted
+	  the header of CSV exports and the content of the "W at gauge" column.
+
+	* src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java:
+	  Adapted method signatures that have been changed in WaterlevelExporter.
+
 2012-01-02  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/resources/messages.properties,
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java	Mon Jan 02 11:01:29 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java	Mon Jan 02 13:30:44 2012 +0000
@@ -50,7 +50,11 @@
 
 
     @Override
-    protected void writeCSVHeader(CSVWriter writer, boolean atGauge) {
+    protected void writeCSVHeader(
+        CSVWriter writer,
+        boolean   atGauge,
+        boolean   isQ
+    ) {
         logger.info("WaterlevelExporter.writeCSVHeader");
 
         writer.writeNext(new String[] {
@@ -61,8 +65,14 @@
         });
     }
 
+
     @Override
-    protected void wQKms2CSV(CSVWriter writer, WQKms wqkms, boolean atGauge) {
+    protected void wQKms2CSV(
+        CSVWriter writer,
+        WQKms     wqkms,
+        boolean   atGauge,
+        boolean   isQ
+    ) {
         logger.debug("WaterlevelExporter.wQKms2CSV");
 
         int      size   = wqkms.size();
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java	Mon Jan 02 11:01:29 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java	Mon Jan 02 13:30:44 2012 +0000
@@ -58,6 +58,9 @@
     public static final String CSV_Q_DESC_HEADER =
         "export.waterlevel.csv.header.q.desc";
 
+    public static final String CSV_W_DESC_HEADER =
+        "export.waterlevel.csv.header.w.desc";
+
     public static final String CSV_LOCATION_HEADER =
         "export.waterlevel.csv.header.location";
 
@@ -99,6 +102,7 @@
     public static final String DEFAULT_CSV_W_HEADER        = "W [NN + m]";
     public static final String DEFAULT_CSV_Q_HEADER        = "Q [m\u00b3/s]";
     public static final String DEFAULT_CSV_Q_DESC_HEADER   = "Bezeichnung";
+    public static final String DEFAULT_CSV_W_DESC_HEADER   = "W/Pegel [cm]";
     public static final String DEFAULT_CSV_LOCATION_HEADER = "Lage";
     public static final String DEFAULT_CSV_GAUGE_HEADER    = "Bezugspegel";
     public static final String DEFAULT_CSV_NOT_IN_GAUGE_RANGE =
@@ -200,13 +204,14 @@
 
         WQ_MODE mode    = FLYSUtils.getWQMode((FLYSArtifact)master);
         boolean atGauge = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.WGAUGE;
+        boolean isQ     = mode == WQ_MODE.QGAUGE || mode == WQ_MODE.QFREE;
 
         writeCSVMeta(writer);
-        writeCSVHeader(writer, atGauge);
+        writeCSVHeader(writer, atGauge, isQ);
 
         for (WQKms[] tmp: data) {
             for (WQKms wqkms: tmp) {
-                wQKms2CSV(writer, wqkms, atGauge);
+                wQKms2CSV(writer, wqkms, atGauge, isQ);
             }
         }
     }
@@ -321,7 +326,11 @@
     }
 
 
-    protected void writeCSVHeader(CSVWriter writer, boolean atGauge) {
+    protected void writeCSVHeader(
+        CSVWriter writer,
+        boolean   atGauge,
+        boolean   isQ
+    ) {
         logger.info("WaterlevelExporter.writeCSVHeader");
 
         if (atGauge) {
@@ -329,7 +338,9 @@
                 msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER),
                 msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER),
                 msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER),
-                msg(CSV_Q_DESC_HEADER, DEFAULT_CSV_Q_DESC_HEADER),
+                (isQ
+                    ? msg(CSV_Q_DESC_HEADER, DEFAULT_CSV_Q_DESC_HEADER)
+                    : msg(CSV_W_DESC_HEADER, DEFAULT_CSV_W_DESC_HEADER)),
                 msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER),
                 msg(CSV_GAUGE_HEADER, DEFAULT_CSV_GAUGE_HEADER)
             });
@@ -345,7 +356,12 @@
     }
 
 
-    protected void wQKms2CSV(CSVWriter writer, WQKms wqkms, boolean atGauge) {
+    protected void wQKms2CSV(
+        CSVWriter writer,
+        WQKms     wqkms,
+        boolean   atGauge,
+        boolean   isQ
+    ) {
         logger.debug("WaterlevelExporter.wQKms2CSV");
 
         NumberFormat kmf = getKmFormatter();
@@ -366,9 +382,14 @@
         double a = gauge.getRange().getA().doubleValue();
         double b = gauge.getRange().getB().doubleValue();
 
-        if (flys instanceof WINFOArtifact) {
+        if (flys instanceof WINFOArtifact && isQ) {
             desc = getColumnTitle((WINFOArtifact)flys, wqkms);
         }
+        else if (!isQ) {
+            Double value = FLYSUtils.getValueFromWQ(wqkms);
+            desc         = value != null
+                ? Formatter.getWaterlevelW(context).format(value) : null;
+        }
 
         for (int i = 0; i < size; i ++) {
             result = wqkms.get(i, result);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Mon Jan 02 11:01:29 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Mon Jan 02 13:30:44 2012 +0000
@@ -6,6 +6,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.xml.xpath.XPathConstants;
 
@@ -29,6 +31,7 @@
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.artifacts.model.LocationProvider;
+import de.intevation.flys.artifacts.model.WQ;
 import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.MainValue;
 import de.intevation.flys.model.River;
@@ -46,6 +49,10 @@
      */
     public static enum WQ_MODE { QFREE, QGAUGE, WFREE, WGAUGE, NONE };
 
+
+    public static final Pattern NUMBERS_PATTERN =
+        Pattern.compile("\\D*(\\d++.\\d*)\\D*");
+
     public static final String XPATH_RIVER_PROJECTION =
         "/artifact-database/floodmap/river[@name=$name]/srid/@value";
 
@@ -402,6 +409,29 @@
     }
 
 
+    public static Double getValueFromWQ(WQ wq) {
+        if (wq == null) {
+            return null;
+        }
+
+        Matcher m = NUMBERS_PATTERN.matcher(wq.getName());
+
+        if (m.matches()) {
+            logger.debug("Found a number.");
+
+            String raw = m.group(1);
+
+            try {
+                return Double.valueOf(raw);
+            }
+            catch (NumberFormatException nfe) {
+            }
+        }
+
+        return null;
+    }
+
+
     public static String createWspWTitle(
         WINFOArtifact winfo,
         CallContext   cc,

http://dive4elements.wald.intevation.org