Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 7634:10993baf02c5
(issue1632) Add Unit to CSV export
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 03 Dec 2013 12:50:15 +0100 |
parents | 41567bf1e131 |
children | 0426c1efd680 |
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.apache.log4j.Logger; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 |
7634
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
22 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 import org.dive4elements.river.artifacts.model.CalculationResult; |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
24 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
25 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
|
26 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
|
27 |
7634
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
28 import org.dive4elements.river.artifacts.D4EArtifact; |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
29 |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 import org.dive4elements.river.exports.AbstractExporter; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 import org.dive4elements.river.utils.Formatter; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 import au.com.bytecode.opencsv.CSVWriter; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 |
6676
202ac69e0db1
Cosmetics, docs, imports.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6668
diff
changeset
|
36 |
6759
6eb2b8087cfa
issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6685
diff
changeset
|
37 /** |
6eb2b8087cfa
issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6685
diff
changeset
|
38 * 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
|
39 * client). */ |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 public class SedimentLoadExporter |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 extends AbstractExporter |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
42 { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
43 /** Private logger. */ |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
44 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
|
45 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
46 // i18n keys. |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
47 public static final String CSV_KM = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
48 "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
|
49 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
50 public static final String CSV_YEAR = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
51 "export.sedimentload_ls.csv.header.year"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
52 |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
53 public static final String CSV_COARSE = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
54 "export.sedimentload_ls.csv.header.coarse"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
55 |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
56 public static final String CSV_FINEMIDDLE = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
57 "export.sedimentload_ls.csv.header.finemiddle"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
58 |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
59 public static final String CSV_SAND = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
60 "export.sedimentload_ls.csv.header.sand"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
61 |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
62 public static final String CSV_SUSP_SAND = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
63 "export.sedimentload_ls.csv.header.suspsand"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
64 |
6759
6eb2b8087cfa
issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6685
diff
changeset
|
65 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
|
66 "export.sedimentload_ls.csv.header.suspsandbb"; |
6eb2b8087cfa
issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6685
diff
changeset
|
67 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
68 public static final String CSV_SUSP_SEDIMENT = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
69 "export.sedimentload_ls.csv.header.suspsediment"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
70 |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
71 public static final String CSV_TOTAL = |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
72 "export.sedimentload_ls.csv.header.total"; |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
73 |
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 /** Collected results. */ |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
76 private SedimentLoadResult[] results; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
77 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
78 /** Empty constructor. */ |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
79 public SedimentLoadExporter() { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
80 results = new SedimentLoadResult[0]; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
81 } |
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 /** 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
|
84 @Override |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
85 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
|
86 writeCSVHeader(writer); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
87 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
88 for (SedimentLoadResult result: results) { |
6972
81f84960d722
Correct SedimentLoadExporters compilability-fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
89 String years = (result.getEndYear() == 0) |
81f84960d722
Correct SedimentLoadExporters compilability-fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
90 ? result.getStartYear() + " " |
6963
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
91 : result.getStartYear() + "-" + result.getEndYear(); |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
92 SedimentLoad load = result.getLoad(); |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
93 // Put load.getName()+load.getDescription()}); somewhere? |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
94 for (double km: new TreeSet<Double>(load.getKms())) { |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
95 SedimentLoadFraction fraction = load.getFraction(km); |
6963
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
96 writeRecord(writer, km, years, fraction); |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
97 } |
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 |
7018
acb63fd3c8d3
issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7011
diff
changeset
|
101 |
acb63fd3c8d3
issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7011
diff
changeset
|
102 /** 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
|
103 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
|
104 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
|
105 return " "; |
7007
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
106 } |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
107 return valf.format(val); |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
108 } |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
109 |
7018
acb63fd3c8d3
issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7011
diff
changeset
|
110 /** 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
|
111 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
|
112 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
|
113 return " "; |
acb63fd3c8d3
issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7011
diff
changeset
|
114 } |
acb63fd3c8d3
issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7011
diff
changeset
|
115 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
|
116 } |
acb63fd3c8d3
issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7011
diff
changeset
|
117 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
118 /** Write a line. */ |
6963
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
119 private void writeRecord( |
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
120 CSVWriter writer, |
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
121 double km, |
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
122 String years, |
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
123 SedimentLoadFraction fraction |
aa1d681ee6eb
SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6759
diff
changeset
|
124 ) { |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
125 // 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
|
126 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
127 NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2); |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
128 writer.writeNext(new String[] { |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
129 kmf.format(km), |
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
130 years, |
7007
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
131 numberToString(valf, fraction.getSuspSediment()), |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
132 numberToString(valf, fraction.getSuspSand()), |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
133 numberToString(valf, fraction.getSuspSandBed()), |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
134 numberToString(valf, fraction.getSand()), |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
135 numberToString(valf, fraction.getFineMiddle()), |
d584100063dd
issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6972
diff
changeset
|
136 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
|
137 nonZeroToString(valf, fraction.getTotal()) |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
138 }); |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
139 } |
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 /** 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
|
142 protected void writeCSVHeader(CSVWriter writer) { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
143 logger.debug("writeCSVHeader()"); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
144 |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
145 List<String> header = new LinkedList<String>(); |
7634
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
146 if (results != null) { |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
147 SedimentLoadAccess access = |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
148 new SedimentLoadAccess((D4EArtifact) master); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
149 |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
150 String unit = " [" + msg("state.minfo.sediment.load." + |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
151 access.getUnit(), "translation missing") + "]"; |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
152 |
6759
6eb2b8087cfa
issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6685
diff
changeset
|
153 header.add(msg(CSV_KM, "km")); |
6eb2b8087cfa
issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6685
diff
changeset
|
154 header.add(msg(CSV_YEAR, "Jahr")); |
7634
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
155 header.add(msg(CSV_SUSP_SEDIMENT, "Schwebst.") + unit); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
156 header.add(msg(CSV_SUSP_SAND, "Susp.Sand") + unit); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
157 header.add(msg(CSV_SUSP_SAND_BB, "Susp.Sand(BB)") + unit); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
158 header.add(msg(CSV_SAND, "Sand") + unit); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
159 header.add(msg(CSV_FINEMIDDLE, "Kies(f+m)") + unit); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
160 header.add(msg(CSV_COARSE, "Kies(g)") + unit); |
10993baf02c5
(issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents:
7088
diff
changeset
|
161 header.add(msg(CSV_TOTAL, "Gesamt") + unit); |
6668
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
162 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
163 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
|
164 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
165 |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
166 /** 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
|
167 * calculationresults data. */ |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
168 @Override |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
169 protected void addData(Object data) { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
170 if (!(data instanceof CalculationResult)) { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
171 logger.warn("Invalid data type."); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
172 return; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
173 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
174 Object[] d = (Object[])((CalculationResult)data).getData(); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
175 |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
176 if (!(d instanceof SedimentLoadResult[])) { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
177 logger.warn("Invalid result object."); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
178 return; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
179 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
180 logger.debug("addData: Data added."); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
181 results = (SedimentLoadResult[])d; |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
182 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
183 |
6685
09e70f01ed1e
issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6676
diff
changeset
|
184 /** 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
|
185 @Override |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
186 protected void writePDF(OutputStream out) { |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
187 logger.warn("Not implemented."); |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
188 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
189 } |
368db84f1241
issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
190 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |