diff flys-artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityExporter.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/exports/FlowVelocityExporter.java@aa4391648a05
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityExporter.java	Thu Apr 25 12:06:39 2013 +0200
@@ -0,0 +1,127 @@
+package org.dive4elements.river.exports;
+
+import java.io.OutputStream;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import au.com.bytecode.opencsv.CSVWriter;
+
+import org.dive4elements.artifacts.CallContext;
+
+import org.dive4elements.river.artifacts.FLYSArtifact;
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.FlowVelocityData;
+import org.dive4elements.river.utils.FLYSUtils;
+import org.dive4elements.river.utils.Formatter;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class FlowVelocityExporter extends AbstractExporter {
+
+    private static final Logger logger =
+        Logger.getLogger(FlowVelocityExporter.class);
+
+
+    public static final String CSV_KM =
+        "export.flow_velocity.csv.header.km";
+
+    public static final String CSV_V_TOTAL =
+        "export.flow_velocity.csv.header.v_total";
+
+    public static final String CSV_V_MAIN =
+        "export.flow_velocity.csv.header.v_main";
+
+    public static final String CSV_TAU_MAIN =
+        "export.flow_velocity.csv.header.tau_main";
+
+    public static final String CSV_Q =
+        "export.flow_velocity.csv.header.q";
+
+    public static final String CSV_LOCATIONS =
+        "export.flow_velocity.csv.header.locations";
+
+
+    protected List<FlowVelocityData[]> data;
+
+
+    public void init(Document request, OutputStream out, CallContext cc) {
+        super.init(request, out, cc);
+        data = new ArrayList<FlowVelocityData[]>();
+    }
+
+
+    @Override
+    protected void addData(Object d) {
+        if (d instanceof CalculationResult) {
+            d = ((CalculationResult) d).getData();
+
+            if (d instanceof FlowVelocityData[]) {
+                logger.debug("Add new data of type FlowVelocityData");
+                data.add((FlowVelocityData[]) d);
+            }
+        }
+    }
+
+
+    @Override
+    protected void writeCSVData(CSVWriter writer) {
+        logger.info("FlowVelocityExporter.writeCSVData");
+        logger.debug("CSV gets " + data.size() + " FlowVelocityData objects.");
+
+        writeCSVHeader(writer);
+
+        for (FlowVelocityData[] d: data) {
+            data2CSV(writer, d);
+        }
+    }
+
+
+    protected void writeCSVHeader(CSVWriter writer) {
+        writer.writeNext(new String[] {
+            msg(CSV_KM, CSV_KM),
+            msg(CSV_V_TOTAL, CSV_V_TOTAL),
+            msg(CSV_V_MAIN, CSV_V_MAIN),
+            msg(CSV_TAU_MAIN, CSV_TAU_MAIN),
+            msg(CSV_Q, CSV_Q),
+            msg(CSV_LOCATIONS, CSV_LOCATIONS)
+        });
+    }
+
+
+    protected void data2CSV(CSVWriter writer, FlowVelocityData[] fData) {
+        logger.debug("Add next FlowVelocityData to CSV");
+
+        FLYSArtifact flys = (FLYSArtifact) master;
+
+        for (FlowVelocityData data: fData) {
+            for (int i = 0, n = data.size(); i < n; i++) {
+                NumberFormat kmF  = Formatter.getFlowVelocityKM(context);
+                NumberFormat valF = Formatter.getFlowVelocityValues(context);
+                NumberFormat qF   = Formatter.getFlowVelocityQ(context);
+
+                writer.writeNext(new String[] {
+                    kmF.format(data.getKM(i)),
+                    valF.format(data.getVMain(i)),
+                    valF.format(data.getVTotal(i)),
+                    valF.format(data.getTauMain(i)),
+                    qF.format(data.getQ(i)) + "=" + data.getZone(),
+                    FLYSUtils.getLocationDescription(flys, data.getKM(i)),
+                });
+            }
+        }
+    }
+
+
+    @Override
+    protected void writePDF(OutputStream out) {
+        logger.error("TODO: Implement FlowVelocityExporter.writePDF");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org