annotate artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 8587:07c9ac22f611

(issue1755) Generalise BedQuality result handling The bedquality calculation now produces a result for each time period which has BedQualityResultValues for each specific result type. Formally this was split up in density, porosity and diameter classes with some bedload diameter classes mixed in for extra fun. The intent of this commit is to allow more shared code and generic access patterns to the BedQuality results.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 18 Mar 2015 18:42:08 +0100
parents e4606eae8ea5
children 0a5239a1e46e
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
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;
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
24 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
25 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
26
7634
10993baf02c5 (issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents: 7088
diff changeset
27 import org.dive4elements.river.artifacts.D4EArtifact;
10993baf02c5 (issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents: 7088
diff changeset
28
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 import org.dive4elements.river.exports.AbstractExporter;
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.utils.Formatter;
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 au.com.bytecode.opencsv.CSVWriter;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34
6676
202ac69e0db1 Cosmetics, docs, imports.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6668
diff changeset
35
6759
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
36 /**
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
37 * 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
38 * client). */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39 public class SedimentLoadExporter
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40 extends AbstractExporter
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
42 /** Private log. */
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
43 private static Logger log = Logger.getLogger(SedimentLoadExporter.class);
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
45 // i18n keys.
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
46 public static final String CSV_KM =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
47 "export.csv.header.km";
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
49 public static final String CSV_YEAR =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
50 "export.csv.header.year";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
51
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
52 public static final String CSV_COARSE =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
53 "export.sedimentload.csv.header.coarse";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
54
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
55 public static final String CSV_FINEMIDDLE =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
56 "export.sedimentload.csv.header.fine_middle";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
57
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
58 public static final String CSV_SAND =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
59 "export.sedimentload.csv.header.sand";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
60
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
61 public static final String CSV_SUSP_SAND =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
62 "export.sedimentload.csv.header.susp_sand";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
63
6759
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
64 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
65 "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
66
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
67 public static final String CSV_SUSP_SEDIMENT =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
68 "export.sedimentload.csv.header.suspended_sediment";
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
69
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
70 public static final String CSV_BED_LOAD =
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
71 "export.sedimentload.csv.header.bed_load";
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
72
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
73 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
74 "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
75
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
76 public static final String CSV_TOTAL =
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
77 "export.sedimentload.csv.header.total";
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
78
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
79 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
80 "suspended_sediment",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
81 "susp_sand",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
82 "susp_sand_bed",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
83 "sand",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
84 "fine_middle",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
85 "coarse",
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
86 "bed_load",
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
87 "bed_load_susp_sand",
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
88 "total"
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
89 };
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
90
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
91 /** Collected results. */
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
92 private SedimentLoadDataResult result;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
93
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
94 /** Empty constructor. */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
95 public SedimentLoadExporter() {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
96 }
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 /** 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
99 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
100 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
101 if (result == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
102 return;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
103 }
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
104 writeCSVHeader(writer);
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
106 /* 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
107 * header and thus static. */
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
108
8146
ce35bdf3d750 Let the facet know the period of it's data.
Tom Gottfried <tom@intevation.de>
parents: 8136
diff changeset
109 /* 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
110 * 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
111
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
112 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
113 new TreeMap<String, TreeMap<Double, Double[]>>();
8136
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
114 for (int i = 0; i < FRACTION_ORDER.length; i++) {
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
115 String name = FRACTION_ORDER[i];
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
116 List<Fraction> fractions = result.getFractionsByName(name);
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
117 if (fractions == null) {
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
118 continue;
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
119 }
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
120 for (Fraction fract: fractions) {
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
121 String period = fract.getPeriod();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
122 TreeMap<Double, Double[]> cur_map;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
123 if (result_map.containsKey(period)) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
124 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
125 } else {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
126 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
127 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
128 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
129 double[][] values = fract.getData();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
130 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
131 Double km = values[0][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
132 Double val = values[1][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
133 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
134 if (old == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
135 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
136 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
137 old [k] = Double.NaN;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
138 }
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 old [i] = val;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
141 cur_map.put(km, old);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
142 }
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 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
146 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
147 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
148 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
149 }
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
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
153
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
154 /** 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
155 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
156 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
157 return " ";
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
158 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
159 return valf.format(val);
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
160 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
161
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
162 /** Write a line. */
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
163 private void writeRecord(
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
164 CSVWriter writer,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
165 double km,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
166 String years,
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
167 Double[] fractions
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
168 ) {
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
169 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
170 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
171
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
172 String[] record = new String[fractions.length+2];
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
173 record[0] = kmf.format(km);
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
174 record[1] = years;
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
175 for (int i = 0; i < fractions.length; ++i) {
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
176 record[i+2] = numberToString(valf, fractions[i]);
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
177 }
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 writer.writeNext(record);
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
180 }
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 /** 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
183 protected void writeCSVHeader(CSVWriter writer) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
184 log.debug("writeCSVHeader()");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
185
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
186 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
187 SedimentLoadAccess access =
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
188 new SedimentLoadAccess((D4EArtifact) master);
7634
10993baf02c5 (issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents: 7088
diff changeset
189
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
190 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
191
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
192 header.add(msg(CSV_KM));
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
193 header.add(msg(CSV_YEAR));
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
194 for (String head: new String[] {
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
195 CSV_SUSP_SEDIMENT,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
196 CSV_SUSP_SAND,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
197 CSV_SUSP_SAND_BB,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
198 CSV_SAND,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
199 CSV_FINEMIDDLE,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
200 CSV_COARSE,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
201 CSV_BED_LOAD,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
202 CSV_BED_LOAD_SUSP_SAND,
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
203 CSV_TOTAL
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
204 }) {
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
205 header.add(msg(head, new Object[] { unit }));
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 8146
diff changeset
206 }
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
207 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
208 }
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 /** 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
211 * calculationresults data. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
212 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
213 protected void addData(Object data) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
214 if (!(data instanceof CalculationResult)) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
215 log.warn("Invalid data type.");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
216 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217 }
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
218 Object d = ((CalculationResult)data).getData();
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
219
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
220 if (!(d instanceof SedimentLoadDataResult)) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
221 log.warn("Invalid result object.");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
222 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223 }
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
224 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
225 result = (SedimentLoadDataResult)d;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
226 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
228 /** 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
229 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
230 protected void writePDF(OutputStream out) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
231 log.warn("Not implemented.");
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
232 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org