annotate artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
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;
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
13 import java.util.TreeMap;
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
20 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
21 import org.apache.logging.log4j.LogManager;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22
7634
10993baf02c5 (issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents: 7088
diff changeset
23 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
24 import org.dive4elements.river.artifacts.model.CalculationResult;
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataResult.Fraction;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataResult;
6668
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 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
43 /** Private log. */
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
44 private static Logger log = LogManager.getLogger(SedimentLoadExporter.class);
6668
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
48 "export.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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
51 "export.csv.header.year";
6685
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
54 "export.sedimentload.csv.header.coarse";
6685
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
57 "export.sedimentload.csv.header.fine_middle";
6685
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
60 "export.sedimentload.csv.header.sand";
6685
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
63 "export.sedimentload.csv.header.susp_sand";
6685
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
66 "export.sedimentload.csv.header.susp_sand_bed";
6759
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 =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
69 "export.sedimentload.csv.header.suspended_sediment";
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
70
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
71 public static final String CSV_BED_LOAD =
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
72 "export.sedimentload.csv.header.bed_load";
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
73
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
74 public static final String CSV_BED_LOAD_SUSP_SAND =
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
75 "export.sedimentload.csv.header.bed_load_susp_sand";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
76
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
77 public static final String CSV_TOTAL =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
78 "export.sedimentload.csv.header.total";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
79
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
80 private static final String[] FRACTION_ORDER = {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
81 "suspended_sediment",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
82 "susp_sand",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
83 "susp_sand_bed",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
84 "sand",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
85 "fine_middle",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
86 "coarse",
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
87 "bed_load",
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
88 "bed_load_susp_sand",
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
89 "total"
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
90 };
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
91
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
92 /** Collected results. */
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
93 private SedimentLoadDataResult result;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
94
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
95 /** Empty constructor. */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
96 public SedimentLoadExporter() {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
97 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
98
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
99 /** 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
100 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
101 protected void writeCSVData(CSVWriter writer) throws IOException {
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
102 if (result == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
103 return;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
104 }
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105 writeCSVHeader(writer);
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
106
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
107 /* Prepare the values. The order of the fractions is given by the
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
108 * header and thus static. */
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
109
8146
ce35bdf3d750 Let the facet know the period of it's data.
Tom Gottfried <tom@intevation.de>
parents: 8136
diff changeset
110 /* The result is ordered by the periods. For each period there is
ce35bdf3d750 Let the facet know the period of it's data.
Tom Gottfried <tom@intevation.de>
parents: 8136
diff changeset
111 * then a map of km-fraction pairs which are the actual result. */
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
112
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
113 TreeMap <String, TreeMap <Double, Double[]>> result_map =
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
114 new TreeMap<String, TreeMap<Double, Double[]>>();
8136
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
115 for (int i = 0; i < FRACTION_ORDER.length; i++) {
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
116 String name = FRACTION_ORDER[i];
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
117 List<Fraction> fractions = result.getFractionsByName(name);
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
118 if (fractions == null) {
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
119 continue;
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
120 }
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
121 for (Fraction fract: fractions) {
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
122 String period = fract.getPeriod();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
123 TreeMap<Double, Double[]> cur_map;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
124 if (result_map.containsKey(period)) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
125 cur_map = result_map.get(period);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
126 } else {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
127 cur_map = new TreeMap<Double, Double[]>();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
128 result_map.put(period, cur_map);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
129 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
130 double[][] values = fract.getData();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
131 for (int j = 0; j < values[0].length; j++) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
132 Double km = values[0][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
133 Double val = values[1][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
134 Double[] old = cur_map.get(km);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
135 if (old == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
136 old = new Double[FRACTION_ORDER.length];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
137 for (int k = 0; k < old.length; k++) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
138 old [k] = Double.NaN;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
139 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
140 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
141 old [i] = val;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
142 cur_map.put(km, old);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
143 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
144 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
145 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
146 for (String period: result_map.keySet()) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
147 TreeMap<Double, Double[]> cur_map = result_map.get(period);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
148 for (Double km: cur_map.keySet()) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
149 writeRecord(writer, km, period, cur_map.get(km));
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
150 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
151 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
152 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
153
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
154
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
155 /** 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
156 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
157 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
158 return " ";
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
159 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
160 return valf.format(val);
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
161 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
162
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
163 /** Write a line. */
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
164 private void writeRecord(
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
165 CSVWriter writer,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
166 double km,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
167 String years,
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
168 Double[] fractions
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
169 ) {
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
170 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
171 NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2);
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
172
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
173 String[] record = new String[fractions.length+2];
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
174 record[0] = kmf.format(km);
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
175 record[1] = years;
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
176 for (int i = 0; i < fractions.length; ++i) {
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
177 record[i+2] = numberToString(valf, fractions[i]);
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
178 }
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
180 writer.writeNext(record);
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
181 }
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 /** 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
184 protected void writeCSVHeader(CSVWriter writer) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
185 log.debug("writeCSVHeader()");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
186
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
187 List<String> header = new LinkedList<String>();
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
188 SedimentLoadAccess access =
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
189 new SedimentLoadAccess((D4EArtifact) master);
7634
10993baf02c5 (issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents: 7088
diff changeset
190
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
191 String unit = msg("state.minfo." + access.getUnit());
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
192
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
193 header.add(msg(CSV_KM));
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
194 header.add(msg(CSV_YEAR));
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
195 for (String head: new String[] {
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
196 CSV_SUSP_SEDIMENT,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
197 CSV_SUSP_SAND,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
198 CSV_SUSP_SAND_BB,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
199 CSV_SAND,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
200 CSV_FINEMIDDLE,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
201 CSV_COARSE,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
202 CSV_BED_LOAD,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
203 CSV_BED_LOAD_SUSP_SAND,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
204 CSV_TOTAL
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
205 }) {
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
206 header.add(msg(head, new Object[] { unit }));
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
207 }
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
208 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
209 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
210
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
211 /** 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
212 * calculationresults data. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
213 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
214 protected void addData(Object data) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215 if (!(data instanceof CalculationResult)) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
216 log.warn("Invalid data type.");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
218 }
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
219 Object d = ((CalculationResult)data).getData();
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
221 if (!(d instanceof SedimentLoadDataResult)) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
222 log.warn("Invalid result object.");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
224 }
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
225 log.debug("addData: Data added.");
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
226 result = (SedimentLoadDataResult)d;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
228
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
229 /** 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
230 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
231 protected void writePDF(OutputStream out) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
232 log.warn("Not implemented.");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
233 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
234 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
235 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org