[Dive4elements-commits] [PATCH 1 of 4] Added exporter for bed height differences
Wald Commits
scm-commit at wald.intevation.org
Thu Jun 6 16:43:52 CEST 2013
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1370529687 -7200
# Node ID e213b538f78cbb5fae0832d4aa545e963ee35bd1
# Parent 9fdb2b59b9922f104b70454794e0e4f765fe0d8e
Added exporter for bed height differences.
diff -r 9fdb2b59b992 -r e213b538f78c artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Thu Jun 06 16:41:27 2013 +0200
@@ -0,0 +1,89 @@
+package org.dive4elements.river.exports.minfo;
+
+import gnu.trove.TDoubleArrayList;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.text.NumberFormat;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult;
+import org.dive4elements.river.exports.AbstractExporter;
+import org.dive4elements.river.utils.Formatter;
+import org.w3c.dom.Document;
+
+import au.com.bytecode.opencsv.CSVWriter;
+
+
+public class BedDifferenceExporter
+extends AbstractExporter
+{
+
+ /** Private logger. */
+ private static Logger logger =
+ Logger.getLogger(BedDifferenceExporter.class);
+
+ private static final String CSV_HEADER_KM = "export.minfo.beddifference.km";
+ private static final String CSV_HEADER_DIFF =
+ "export.minfo.beddifference.diff";
+
+ private BedDifferencesResult[] results;
+
+ @Override
+ public void init(Document request, OutputStream out, CallContext context) {
+ logger.debug("BedQualityExporter.init");
+ super.init(request, out, context);
+ results = new BedDifferencesResult[0];
+ }
+ @Override
+ protected void writeCSVData(CSVWriter writer) throws IOException {
+ writeCSVHeader(writer);
+
+ NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
+ NumberFormat mf = Formatter.getMeterFormat(context);
+ for (int i = 0; i < results.length; i++) {
+ BedDifferencesResult result = results[i];
+ double[][] kms = result.getDifferencesData();
+ for (int j = 0; j < kms[0].length; j++) {
+ writer.writeNext(new String[] {
+ kmf.format(kms[0][j]), mf.format(kms[1][j])});
+ }
+ }
+ }
+
+ @Override
+ protected void writePDF(OutputStream out) {
+ // TODO implement me!
+
+ }
+
+ @Override
+ protected void addData(Object data) {
+ if (!(data instanceof CalculationResult)) {
+ logger.warn("Invalid data type.");
+ return;
+ }
+ Object[] d = (Object[])((CalculationResult)data).getData();
+
+ if (!(d instanceof BedDifferencesResult[])) {
+ logger.warn("Invalid result object.");
+ return;
+ }
+ results = (BedDifferencesResult[])d;
+ }
+
+ protected void writeCSVHeader(CSVWriter writer) {
+ logger.debug("writeCSVHeader()");
+
+ List<String> header = new LinkedList<String>();
+ if (results != null) {
+ header.add(msg(CSV_HEADER_KM, "km"));
+ header.add(msg(CSV_HEADER_DIFF, "m"));
+ }
+ writer.writeNext(header.toArray(new String[header.size()]));
+ }
+}
More information about the Dive4elements-commits
mailing list