changeset 450:c8bb38115290

Enabled the discharge longitudinal section to be exported as WST. flys-artifacts/trunk@1944 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 18 May 2011 10:59:38 +0000
parents 9814d4808410
children 73bc64c4a7b0
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java
diffstat 6 files changed, 127 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed May 18 09:11:10 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed May 18 10:59:38 2011 +0000
@@ -1,3 +1,21 @@
+2011-05-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/artifacts/winfo.xml: Registered the WST export for discharge
+	  longitudinal sections.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Set the
+	  names of the discharge longitudinal section computation results.
+
+	* src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java:
+	  The W/Q curves in the chart will now have names.
+
+	* src/main/java/de/intevation/flys/exports/WaterlevelExporter.java:
+	  The WstWriter is filled with column names in an own method. So, we are
+	  able to override this process in subclasses.
+
+	* src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java:
+	  Adapted the column names for the WST export.
+
 2011-05-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
     Work on flys/issue69
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Wed May 18 09:11:10 2011 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Wed May 18 10:59:38 2011 +0000
@@ -179,6 +179,7 @@
                 <outputmode name="discharge_longitudinal_section_export" description="output.discharge_longitudinal_section_export" mime-type="text/plain">
                     <facets>
                         <facet name="csv" description="facet.discharge_longitudinal_section_export.csv" />
+                        <facet name="wst" description="facet.discharge_longitudinal_section_export.csv" />
                     </facets>
                 </outputmode>
             </outputmodes>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed May 18 09:11:10 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed May 18 10:59:38 2011 +0000
@@ -495,7 +495,11 @@
         double[][] dist = getSplittedDistance();
         int        num  = dist != null ? dist.length : 0;
 
-        WQKms[][] wqkms = new WQKms[num][];
+        double[][] allQs = new double[num][];
+        double[][] allWs = new double[num][];
+        WQKms[][]  wqkms = new WQKms[num][];
+
+        boolean qSel = true;
 
         for (int i = 0; i < num; i++) {
             double[] kms = getKms(dist[i]);
@@ -505,11 +509,14 @@
             }
 
             double[] qs = getQs(dist[i]);
+            allQs[i]    = qs;
+
             if (qs == null) {
                 logger.debug("Determine Q values based on a set of W values.");
+                qSel = false;
 
-                double[] ws = getWs(dist[i]);
-                qs = getQsForWs(ws);
+                allWs[i] = getWs(dist[i]);
+                qs       = getQsForWs(allWs[i]);
             }
 
             wqkms[i] = computeWaterlevelData(kms, qs, wst);
@@ -521,6 +528,12 @@
 
         for (int i = 0; i < numMerged; i++) {
             computed[i] = computeDischargeLongitudinalSectionData(merged[i]);
+
+            setDischargeLongitudinalSectionNames(
+                computed[i],
+                qSel ? allQs : allWs,
+                i,
+                qSel ? "Q" : "W");
         }
 
         // TODO Introduce a caching mechanism here!
@@ -530,6 +543,46 @@
 
 
     /**
+     * Sets the name for discharge longitudinal section curves where each WQKms
+     * in <i>r</i> represents a column.
+     *
+     * @param wqkms A longitudinal section curve.
+     * @param allValues The input values of the computations.
+     * @param col The requested column in the table of Ws or Qs.
+     * @param wq The WQ mode - can be one of "W" or "Q".
+     */
+    public static void setDischargeLongitudinalSectionNames(
+        WQKms      wqkms,
+        double[][] allValues,
+        int        col,
+        String     wq)
+    {
+        logger.debug("WINFOArtifact.setDischargeLongitudinalSectionNames");
+
+        StringBuilder sb = new StringBuilder(" (");
+        boolean    first = true;
+
+        int rows = allValues.length;
+
+        for (int i = 0; i < rows; i++) {
+            double[] values = allValues[i];
+
+            if (!first) {
+                sb.append("; ");
+            }
+
+            sb.append(Double.toString(values[col]));
+
+            first = false;
+        }
+
+        sb.append(")");
+
+        wqkms.setName(wq + " Benutzerdefiniert" + sb.toString());
+    }
+
+
+    /**
      * Computes the data used for a discharge longitudinal section based on a
      * given WQKms object. If there are backjumps while computing the data, a
      * WQCKms object is returned, otherwise the incoming wqkms object.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java	Wed May 18 09:11:10 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java	Wed May 18 10:59:38 2011 +0000
@@ -90,5 +90,34 @@
             });
         }
     }
+
+
+    @Override
+    protected void addWSTColumn(WstWriter writer, WQKms wqkms) {
+        String name = wqkms.getName();
+
+        // is it a W or a Q mode?
+        int wIdx = name.indexOf("W");
+        int qIdx = name.indexOf("Q");
+
+        String wq = null;
+        if (wIdx >= 0) {
+            wq = "W";
+        }
+        else if (qIdx >= 0) {
+            wq = "Q";
+        }
+
+        // we just want to display the first W or Q value in the WST
+        int start = name.indexOf("(");
+        int end   = name.indexOf(")");
+
+        String   tmp    = name.substring(start+1, end);
+        String[] values = tmp.split(";");
+
+        String column = wq + "=" + values[0];
+
+        writer.addColumn(column);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java	Wed May 18 09:11:10 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java	Wed May 18 10:59:38 2011 +0000
@@ -136,8 +136,7 @@
     protected void doWOut(WQKms wqkms) {
         logger.debug("DischargeLongitudinalSectionGenerator.doWOut");
 
-        // TODO CREATE CORRECT SERIES NAME
-        XYSeries series = new XYSeries("W");
+        XYSeries series = new XYSeries(getSeriesName(wqkms, "W"));
 
         double[] target = new double[4];
         int      size   = wqkms.size();
@@ -160,8 +159,7 @@
     protected void doCorrectedWOut(WQCKms wqckms) {
         logger.debug("DischargeLongitudinalSectionGenerator.doCorrectedWOut");
 
-        // TODO CREATE CORRECT SERIES NAME
-        XYSeries series = new XYSeries("Korrigiert");
+        XYSeries series = new XYSeries(getSeriesNameForCorrected(wqckms, "W"));
 
         double[] target = new double[4];
         int      size   = wqckms.size();
@@ -176,5 +174,20 @@
             cw.addSeries(series);
         }
     }
+
+
+    protected String getSeriesNameForCorrected(WQKms wqkms, String mode) {
+        String name = wqkms.getName();
+
+        name = name.replace(
+            "Benutzerdefiniert",
+            "Benutzerdefiniert [korrigiert]");
+
+        String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode;
+
+        return prefix != null && prefix.length() > 0
+            ? prefix + "(" + name +")"
+            : name;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java	Wed May 18 09:11:10 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java	Wed May 18 10:59:38 2011 +0000
@@ -171,7 +171,7 @@
             for (WQKms wqkms: tmp) {
                 int size = wqkms != null ? wqkms.size() : 0;
 
-                writer.addColumn(wqkms.getName());
+                addWSTColumn(writer, wqkms);
 
                 for (int i = 0; i < size; i++) {
                     result = wqkms.get(i, result);
@@ -183,6 +183,11 @@
     }
 
 
+    protected void addWSTColumn(WstWriter writer, WQKms wqkms) {
+        writer.addColumn(wqkms.getName());
+    }
+
+
     /**
      * Returns the number formatter for kilometer values.
      *

http://dive4elements.wald.intevation.org