annotate artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 7077:0a337f0005c2 generator-refactoring

Extended init() of OutGenerator to take name of the out to serve.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 20 Sep 2013 16:34:09 +0200
parents acb63fd3c8d3
children 41567bf1e131
rev   line source
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
3 *
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
7 */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
8
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.exports.minfo;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 import java.util.LinkedList;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
12 import java.util.List;
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
13 import java.util.TreeSet;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15 import java.io.OutputStream;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16 import java.io.IOException;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18 import java.text.NumberFormat;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20 import org.w3c.dom.Document;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22 import org.apache.log4j.Logger;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 import org.dive4elements.artifacts.CallContext;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 import org.dive4elements.river.artifacts.model.CalculationResult;
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
28 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
31 import org.dive4elements.river.exports.AbstractExporter;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33 import org.dive4elements.river.utils.Formatter;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 import au.com.bytecode.opencsv.CSVWriter;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36
6676
202ac69e0db1 Cosmetics, docs, imports.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6668
diff changeset
37
6759
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
38 /**
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
39 * Do CSV export for sediment load calculations (will also be shown in
6676
202ac69e0db1 Cosmetics, docs, imports.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6668
diff changeset
40 * client). */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 public class SedimentLoadExporter
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42 extends AbstractExporter
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44 /** Private logger. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45 private static Logger logger = Logger.getLogger(SedimentLoadExporter.class);
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
47 // i18n keys.
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
48 public static final String CSV_KM =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
49 "export.sedimentload_ls.csv.header.km";
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
51 public static final String CSV_YEAR =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
52 "export.sedimentload_ls.csv.header.year";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
53
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
54 public static final String CSV_COARSE =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
55 "export.sedimentload_ls.csv.header.coarse";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
56
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
57 public static final String CSV_FINEMIDDLE =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
58 "export.sedimentload_ls.csv.header.finemiddle";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
59
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
60 public static final String CSV_SAND =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
61 "export.sedimentload_ls.csv.header.sand";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
62
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
63 public static final String CSV_SUSP_SAND =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
64 "export.sedimentload_ls.csv.header.suspsand";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
65
6759
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
66 public static final String CSV_SUSP_SAND_BB =
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
67 "export.sedimentload_ls.csv.header.suspsandbb";
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
68
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
69 public static final String CSV_SUSP_SEDIMENT =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
70 "export.sedimentload_ls.csv.header.suspsediment";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
71
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
72 public static final String CSV_TOTAL =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
73 "export.sedimentload_ls.csv.header.total";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
74
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
75
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
76 /** Collected results. */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
77 private SedimentLoadResult[] results;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
78
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
79 /** Empty constructor. */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
80 public SedimentLoadExporter() {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
81 results = new SedimentLoadResult[0];
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
82 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
83
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
84 /** Process all stored data and write csv. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
85 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
86 protected void writeCSVData(CSVWriter writer) throws IOException {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
87 writeCSVHeader(writer);
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
88
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
89 for (SedimentLoadResult result: results) {
6972
81f84960d722 Correct SedimentLoadExporters compilability-fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6970
diff changeset
90 String years = (result.getEndYear() == 0)
81f84960d722 Correct SedimentLoadExporters compilability-fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6970
diff changeset
91 ? result.getStartYear() + " "
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
92 : result.getStartYear() + "-" + result.getEndYear();
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
93 SedimentLoad load = result.getLoad();
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
94 // Put load.getName()+load.getDescription()}); somewhere?
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
95 for (double km: new TreeSet<Double>(load.getKms())) {
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
96 SedimentLoadFraction fraction = load.getFraction(km);
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
97 writeRecord(writer, km, years, fraction);
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
98 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
99 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
100 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
101
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
102
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
103 /** Return space when val is NaN, apply NumberFormat otherwise. */
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
104 private String numberToString(NumberFormat valf, double val) {
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
105 if (Double.isNaN(val)) {
7011
b1fadc5af121 issue1465: Show space instead of '-' in table results view.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7007
diff changeset
106 return " ";
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
107 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
108 return valf.format(val);
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
109 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
110
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
111 /** Return space when val is NaN or zero, apply NumberFormat otherwise. */
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
112 private String nonZeroToString(NumberFormat valf, double val) {
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
113 if (Double.isNaN(val) || val == 0d) {
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
114 return " ";
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
115 }
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
116 return valf.format(val);
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
117 }
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
118
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
119 /** Write a line. */
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
120 private void writeRecord(
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
121 CSVWriter writer,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
122 double km,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
123 String years,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
124 SedimentLoadFraction fraction
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
125 ) {
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
126 // year, total, susp sed, susp sandbed suspsand, sand, finemiddle, coarse
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
128 NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2);
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
129 writer.writeNext(new String[] {
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
130 kmf.format(km),
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
131 years,
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
132 numberToString(valf, fraction.getSuspSediment()),
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
133 numberToString(valf, fraction.getSuspSand()),
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
134 numberToString(valf, fraction.getSuspSandBed()),
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
135 numberToString(valf, fraction.getSand()),
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
136 numberToString(valf, fraction.getFineMiddle()),
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
137 numberToString(valf, fraction.getCoarse()),
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
138 nonZeroToString(valf, fraction.getTotal())
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
139 });
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
140 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
141
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
142 /** Writes i18ned header for csv file/stream. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
143 protected void writeCSVHeader(CSVWriter writer) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
144 logger.debug("writeCSVHeader()");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
145
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
146 List<String> header = new LinkedList<String>();
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
147 if (results != null) {
6759
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
148 header.add(msg(CSV_KM, "km"));
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
149 header.add(msg(CSV_YEAR, "Jahr"));
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
150 header.add(msg(CSV_SUSP_SEDIMENT, "Schwebst."));
6759
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
151 header.add(msg(CSV_SUSP_SAND, "Susp.Sand"));
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
152 header.add(msg(CSV_SUSP_SAND_BB, "Susp.Sand(BB)"));
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
153 header.add(msg(CSV_SAND, "Sand"));
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
154 header.add(msg(CSV_FINEMIDDLE, "Kies(f+m)"));
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
155 header.add(msg(CSV_COARSE, "Kies(g)"));
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
156 header.add(msg(CSV_TOTAL, "Gesamt"));
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
157 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
158 writer.writeNext(header.toArray(new String[header.size()]));
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
159 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
160
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
161 /** Store data internally, accepting only SedimentLoadResults[] in
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
162 * calculationresults data. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
163 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
164 protected void addData(Object data) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
165 if (!(data instanceof CalculationResult)) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
166 logger.warn("Invalid data type.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
167 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
168 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
169 Object[] d = (Object[])((CalculationResult)data).getData();
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
170
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
171 if (!(d instanceof SedimentLoadResult[])) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
172 logger.warn("Invalid result object.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
173 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
174 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
175 logger.debug("addData: Data added.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
176 results = (SedimentLoadResult[])d;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
177 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
178
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
179 /** Write PDF to outputstream (not implemented yet). */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
180 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
181 protected void writePDF(OutputStream out) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
182 logger.warn("Not implemented.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
183 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
184 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
185 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org