changeset 6685:09e70f01ed1e

issue1416: SedimentLoadExporter: Implemented rough output.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 29 Jul 2013 09:30:44 +0200
parents 29e2a5217307
children 661b45d13b17
files artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java
diffstat 1 files changed, 66 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Mon Jul 29 09:28:32 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Mon Jul 29 09:30:44 2013 +0200
@@ -10,6 +10,7 @@
 
 import java.util.LinkedList;
 import java.util.List;
+import java.util.TreeSet;
 
 import java.io.OutputStream;
 import java.io.IOException;
@@ -23,6 +24,8 @@
 import org.dive4elements.artifacts.CallContext;
 
 import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult;
 
 import org.dive4elements.river.exports.AbstractExporter;
@@ -40,9 +43,36 @@
     /** Private logger. */
     private static Logger logger = Logger.getLogger(SedimentLoadExporter.class);
 
+    // i18n keys.
+    public static final String CSV_KM =
+        "export.sedimentload_ls.csv.header.km";
 
+    public static final String CSV_YEAR =
+        "export.sedimentload_ls.csv.header.year";
+
+    public static final String CSV_COARSE =
+        "export.sedimentload_ls.csv.header.coarse";
+
+    public static final String CSV_FINEMIDDLE =
+        "export.sedimentload_ls.csv.header.finemiddle";
+
+    public static final String CSV_SAND =
+        "export.sedimentload_ls.csv.header.sand";
+
+    public static final String CSV_SUSP_SAND =
+        "export.sedimentload_ls.csv.header.suspsand";
+
+    public static final String CSV_SUSP_SEDIMENT =
+        "export.sedimentload_ls.csv.header.suspsediment";
+
+    public static final String CSV_TOTAL =
+        "export.sedimentload_ls.csv.header.total";
+
+
+    /** Collected results. */
     private SedimentLoadResult[] results;
 
+    /** Empty constructor. */
     public SedimentLoadExporter() {
     }
 
@@ -60,8 +90,33 @@
     protected void writeCSVData(CSVWriter writer) throws IOException {
         writeCSVHeader(writer);
 
+        for (SedimentLoadResult result: results) {
+            SedimentLoad load = result.getLoad();
+            // Put load.getName()+load.getDescription()}); somewhere?
+            for (double km: new TreeSet<Double>(load.getKms())) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                writeRecord(writer, km, result.getStartYear(), result.getEndYear(), fraction);
+            }
+        }
+    }
+
+    /** Write a line. */
+    private void writeRecord(CSVWriter writer, double km, int fromYear, int toYear, SedimentLoadFraction fraction) {
+        // year, total, susp sed, susp sandbed suspsand, sand, finemiddle, coarse
+        String years = (toYear == 0) ? fromYear+"" : fromYear + "-" + toYear;
         NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
-        /* writer.writeNext(new String[] { */
+        NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2);
+        writer.writeNext(new String[] {
+            kmf.format(km),
+            years,
+            valf.format(fraction.getTotal()),
+            valf.format(fraction.getSand()),
+            valf.format(fraction.getFineMiddle()),
+            valf.format(fraction.getCoarse()),
+            valf.format(fraction.getSuspSand()),
+            //valf.format(fraction.getSuspSandBed()),
+            valf.format(fraction.getSuspSediment())
+        });
     }
 
     /** Writes i18ned header for csv file/stream. */
@@ -70,8 +125,15 @@
 
         List<String> header = new LinkedList<String>();
         if (results != null)  {
-            /*header.add(msg(CSV_HEADER_KM, "km"));
-            header.add(msg(CSV_HEADER_VAL, "m"));*/
+            header.add(msg(CSV_KM, "km"));
+            header.add(msg(CSV_YEAR, "Jahr"));
+            header.add(msg(CSV_TOTAL, "Gesamt"));
+            header.add(msg(CSV_SAND, "Sand"));
+            header.add(msg(CSV_FINEMIDDLE,"Fein"));
+            header.add(msg(CSV_COARSE,    "Grob"));
+            header.add(msg(CSV_SUSP_SAND, "Su.Sand"));
+            header.add(msg(CSV_SUSP_SEDIMENT, "Schwebst."));
+            //header.add("Susp.Sand Bett");
         }
         writer.writeNext(header.toArray(new String[header.size()]));
     }
@@ -94,6 +156,7 @@
         results = (SedimentLoadResult[])d;
     }
 
+    /** Write PDF to outputstream (not implemented yet). */
     @Override
     protected void writePDF(OutputStream out) {
         logger.warn("Not implemented.");

http://dive4elements.wald.intevation.org