annotate artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 8146:ce35bdf3d750

Let the facet know the period of it's data.
author Tom Gottfried <tom@intevation.de>
date Wed, 27 Aug 2014 15:09:45 +0200
parents cda45ed151ed
children 705f8b92fd66
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 {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42 /** Private logger. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 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
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
47 "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
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
50 "export.sedimentload_ls.csv.header.year";
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
53 "export.sedimentload_ls.csv.header.coarse";
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
56 "export.sedimentload_ls.csv.header.finemiddle";
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
59 "export.sedimentload_ls.csv.header.sand";
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
62 "export.sedimentload_ls.csv.header.suspsand";
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 =
6eb2b8087cfa issue1416: exporter for sedimentload and i18n.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6685
diff changeset
65 "export.sedimentload_ls.csv.header.suspsandbb";
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 =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
68 "export.sedimentload_ls.csv.header.suspsediment";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
69
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
70 public static final String CSV_TOTAL =
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
71 "export.sedimentload_ls.csv.header.total";
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
72
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
73 /* Header is: suspended_sediment, susp_sand, susp_sand_bed, sand,
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
74 * fine_middle, coarse, total */
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
75 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
76 "suspended_sediment",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
77 "susp_sand",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
78 "susp_sand_bed",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
79 "sand",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
80 "fine_middle",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
81 "coarse",
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
82 "total"
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
83 };
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
84
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
85 /** Collected results. */
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
86 private SedimentLoadDataResult result;
6668
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 /** Empty constructor. */
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
89 public SedimentLoadExporter() {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
90 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
91
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
92 /** 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
93 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
94 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
95 if (result == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
96 return;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
97 }
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
98 writeCSVHeader(writer);
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
99
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
100 /* 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
101 * header and thus static. */
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
102
8146
ce35bdf3d750 Let the facet know the period of it's data.
Tom Gottfried <tom@intevation.de>
parents: 8136
diff changeset
103 /* 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
104 * 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
105
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
106 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
107 new TreeMap<String, TreeMap<Double, Double[]>>();
8136
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
108 for (int i = 0; i < FRACTION_ORDER.length; i++) {
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
109 String name = FRACTION_ORDER[i];
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
110 List<Fraction> fractions = result.getFractionsByName(name);
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
111 if (fractions == null) {
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
112 continue;
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
113 }
cda45ed151ed Fix exporter loops
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8134
diff changeset
114 for (Fraction fract: fractions) {
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
115 String period = fract.getPeriod();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
116 TreeMap<Double, Double[]> cur_map;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
117 if (result_map.containsKey(period)) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
118 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
119 } else {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
120 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
121 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
122 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
123 double[][] values = fract.getData();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
124 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
125 Double km = values[0][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
126 Double val = values[1][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
127 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
128 if (old == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
129 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
130 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
131 old [k] = Double.NaN;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
132 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
133 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
134 old [i] = val;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
135 cur_map.put(km, old);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
136 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
137 }
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 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
140 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
141 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
142 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
143 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
144 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
145 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
146
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
147
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
148 /** 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
149 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
150 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
151 return " ";
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
152 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
153 return valf.format(val);
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
154 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
155
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
156 /** 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
157 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
158 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
159 return " ";
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
160 }
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
161 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
162 }
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
163
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
164 /** Write a line. */
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
165 private void writeRecord(
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
166 CSVWriter writer,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
167 double km,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
168 String years,
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
169 Double[] fractions
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
170 ) {
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
171 // 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
172 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
173 NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2);
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
174 writer.writeNext(new String[] {
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
175 kmf.format(km),
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
176 years,
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
177 numberToString(valf, fractions[0]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
178 numberToString(valf, fractions[1]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
179 numberToString(valf, fractions[2]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
180 numberToString(valf, fractions[3]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
181 numberToString(valf, fractions[4]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
182 numberToString(valf, fractions[5]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
183 nonZeroToString(valf, fractions[6])
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
184 });
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
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
187 /** 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
188 protected void writeCSVHeader(CSVWriter writer) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
189 logger.debug("writeCSVHeader()");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
190
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
191 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
192 SedimentLoadAccess access =
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
193 new SedimentLoadAccess((D4EArtifact) master);
7634
10993baf02c5 (issue1632) Add Unit to CSV export
Andre Heinecke <aheinecke@intevation.de>
parents: 7088
diff changeset
194
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
195 String unit = " [" + msg("state.minfo." +
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
196 access.getUnit(), "translation missing") + "]";
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
197
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
198 header.add(msg(CSV_KM, "km"));
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
199 header.add(msg(CSV_YEAR, "Jahr"));
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
200 header.add(msg(CSV_SUSP_SEDIMENT, "Schwebst.") + unit);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
201 header.add(msg(CSV_SUSP_SAND, "Susp.Sand") + unit);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
202 header.add(msg(CSV_SUSP_SAND_BB, "Susp.Sand(BB)") + unit);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
203 header.add(msg(CSV_SAND, "Sand") + unit);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
204 header.add(msg(CSV_FINEMIDDLE, "Kies(f+m)") + unit);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
205 header.add(msg(CSV_COARSE, "Kies(g)") + unit);
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
206 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
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)) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215 logger.warn("Invalid data type.");
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)) {
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221 logger.warn("Invalid result object.");
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 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
224 logger.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) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
231 logger.warn("Not implemented.");
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