changeset 2285:5a00269406f3

Improved CSV export of reference curves, include Qs. flys-artifacts/trunk@3947 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 07 Feb 2012 09:58:15 +0000
parents 5d1ba04d2f68
children 89ca1e8572e4
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java
diffstat 2 files changed, 33 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Feb 07 09:54:29 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Feb 07 09:58:15 2012 +0000
@@ -1,3 +1,8 @@
+2012-02-07  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java:
+	  Handle WWQQs, extended CSV export of reference curves.
+
 2012-02-07  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/DurationCurveExporter.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java	Tue Feb 07 09:54:29 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java	Tue Feb 07 09:58:15 2012 +0000
@@ -30,7 +30,7 @@
 import de.intevation.flys.artifacts.WINFOArtifact;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.WW;
+import de.intevation.flys.artifacts.model.WWQQ;
 import de.intevation.flys.artifacts.model.WKmsJRDataSource;
 import de.intevation.flys.artifacts.resources.Resources;
 
@@ -60,11 +60,6 @@
 
     public static final String DEFAULT_CSV_LOCATION_HEADER = "Lage";
 
-    /*
-        For each Bezugs and Ziel-ort (of which there might be multiples):
-          Lage, Bezeichnung, Q, W (cm), W(NN+m).
-     */
-
     public static final String RC_DEFAULT_CSV_KM_HEADER = "Fluss-Km";
     public static final String RC_DEFAULT_CSV_W_HEADER  = "m";
     public static final String RC_DEFAULT_CSV_Q_HEADER  = "Q";
@@ -73,8 +68,7 @@
     public static final String JASPER_FILE = "export.reference_curve.pdf.file";
 
     /** The storage that contains all WKms objects for the different facets. */
-    /* TODO these shall be the function objects, probably. */
-    protected List<WW[]> data;
+    protected List<WWQQ[]> data;
 
 
     public void init(Document request, OutputStream out, CallContext context) {
@@ -82,7 +76,7 @@
 
         super.init(request, out, context);
 
-        this.data = new ArrayList<WW[]>();
+        this.data = new ArrayList<WWQQ[]>();
     }
 
 
@@ -112,21 +106,26 @@
 
     /**
      * Adds given data.
-     * @param d either a WKms or a CalculationResult to add to data.
+     * @param d a WWQQ[].
      */
     @Override
     protected void addData(Object d) {
+        logger.debug("ReferenceCurveExporter.addData");
+
         if (d instanceof CalculationResult) {
             d = ((CalculationResult)d).getData();
-            if (d instanceof WW []) {
-                data.add((WW [])d);
+            if (d instanceof WWQQ []) {
+                data.add((WWQQ [])d);
+                logger.debug("ReferenceCurveExporter.addData wwqq[].");
+            }
+            else {
+                logger.warn("ReferenceCurveExporter.addData/1 unknown type ("
+                    + d + ").");
             }
         }
-        else if (d instanceof WW) {
-            data.add(new WW[] { (WW) d });
-        }
         else {
-            logger.warn("ReferenceCurveExporter.addData unknown data type.");
+            logger.warn("ReferenceCurveExporter.addData/2 unknown type ("
+                + d + ").");
         }
     }
 
@@ -141,9 +140,9 @@
 
         writeCSVHeader(writer);
 
-        for (WW[] tmp: data) {
-            for (WW ww: tmp) {
-                ww2CSV(writer, ww);
+        for (WWQQ[] tmp: data) {
+            for (WWQQ ww: tmp) {
+                wWQQ2CSV(writer, ww);
             }
         }
     }
@@ -156,6 +155,7 @@
     protected void writeCSVHeader(CSVWriter writer) {
         logger.info("ReferenceCurveExporter.writeCSVHeader");
 
+        // TODO missing 'relative' W(cm).
         writer.writeNext(new String[] {
             msg(RC_CSV_KM_HEADER, RC_DEFAULT_CSV_KM_HEADER),
             msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER),
@@ -169,11 +169,13 @@
     }
 
 
-    protected void ww2CSV(CSVWriter writer, WW ww) {
-        logger.debug("ReferenceCurveExporter.ww2CSV");
+    protected void wWQQ2CSV(CSVWriter writer, WWQQ ww) {
+        logger.debug("ReferenceCurveExporter.wWQQ2CSV");
 
-        NumberFormat kmf  = getKmFormatter();
-        NumberFormat wf   = getWFormatter();
+        NumberFormat kmf = getKmFormatter();
+        NumberFormat wf  = getWFormatter();
+        NumberFormat qf  = getQFormatter();
+
         int          size = ww.size();
 
         FLYSArtifact flys       = (FLYSArtifact) master;
@@ -184,41 +186,22 @@
         String endLocationDescription = FLYSUtils.getLocationDescription(
             flys, ww.getEndKm());
 
+        // TODO missing 'relative' W(cm).
         for (int i = 0; i < size; i ++) {
             writer.writeNext(new String[] {
                 kmf.format(ww.getStartKm()),
                 startLocationDescription,
                 wf.format(ww.getW1(i)),
-                "", // "Q"
+                qf.format(ww.getQ1(i)), // "Q"
                 kmf.format(ww.getEndKm()),
                 endLocationDescription,
                 wf.format(ww.getW2(i)),
-                "" // "Q"
+                qf.format(ww.getQ2(i)) // "Q"
             });
         }
     }
 
 
-    /**
-     * Returns the number formatter for kilometer values.
-     *
-     * @return the number formatter for kilometer values.
-     */
-    protected NumberFormat getKmFormatter() {
-        return Formatter.getWaterlevelKM(context);
-    }
-
-
-    /**
-     * Returns the number formatter for W values.
-     *
-     * @return the number formatter for W values.
-     */
-    protected NumberFormat getWFormatter() {
-        return Formatter.getWaterlevelW(context);
-    }
-
-
     @Override
     protected void writePDF(OutputStream out) {
         /*

http://dive4elements.wald.intevation.org