annotate artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 8134:dfcc96deebd8

Make SedimentloadExporter work with the new result scheme. Pretty much untested.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 25 Aug 2014 20:02:28 +0200
parents 963ede7b32bb
children cda45ed151ed
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
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
103 /* The result is ordered by the peridods. For each period there is
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
104 * then a map of km - fractions pairs which are the actual result. */
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[]>>();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
108 int i = 0;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
109 for (String name: FRACTION_ORDER) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
110 for (Fraction fract: result.getFractionsByName(name)) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
111 String period = fract.getPeriod();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
112 TreeMap<Double, Double[]> cur_map;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
113 if (result_map.containsKey(period)) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
114 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
115 } else {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
116 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
117 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
118 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
119 double[][] values = fract.getData();
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
120 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
121 Double km = values[0][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
122 Double val = values[1][j];
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
123 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
124 if (old == null) {
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
125 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
126 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
127 old [k] = Double.NaN;
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 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
130 old [i] = val;
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
131 cur_map.put(km, old);
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 }
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
135 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
136 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
137 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
138 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
139 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
140 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
141 }
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
142
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
143
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
144 /** 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
145 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
146 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
147 return " ";
7007
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
148 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
149 return valf.format(val);
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
150 }
d584100063dd issue1465: Prepare SedimentLoadExporter to show "-" for NaN-values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6972
diff changeset
151
7018
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
152 /** 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
153 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
154 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
155 return " ";
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
156 }
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
157 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
158 }
acb63fd3c8d3 issue1465: Assume that a "0" measurement for total sediment load is
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7011
diff changeset
159
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
160 /** Write a line. */
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
161 private void writeRecord(
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
162 CSVWriter writer,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
163 double km,
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
164 String years,
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
165 Double[] fractions
6963
aa1d681ee6eb SedimentLoadExporter: Minor refac. Determine a displayed string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6759
diff changeset
166 ) {
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
167 // 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
168 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
169 NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2);
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
170 writer.writeNext(new String[] {
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
171 kmf.format(km),
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
172 years,
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
173 numberToString(valf, fractions[0]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
174 numberToString(valf, fractions[1]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
175 numberToString(valf, fractions[2]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
176 numberToString(valf, fractions[3]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
177 numberToString(valf, fractions[4]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
178 numberToString(valf, fractions[5]),
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
179 nonZeroToString(valf, fractions[6])
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
180 });
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) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
185 logger.debug("writeCSVHeader()");
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
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
191 String unit = " [" + msg("state.minfo." +
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
192 access.getUnit(), "translation missing") + "]";
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
193
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
205
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
206 /** 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
207 * calculationresults data. */
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
208 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
209 protected void addData(Object data) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
210 if (!(data instanceof CalculationResult)) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
211 logger.warn("Invalid data type.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
212 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
213 }
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
214 Object d = ((CalculationResult)data).getData();
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215
8134
dfcc96deebd8 Make SedimentloadExporter work with the new result scheme.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8024
diff changeset
216 if (!(d instanceof SedimentLoadDataResult)) {
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217 logger.warn("Invalid result object.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
218 return;
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
219 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 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
221 result = (SedimentLoadDataResult)d;
6668
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
222 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223
6685
09e70f01ed1e issue1416: SedimentLoadExporter: Implemented rough output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6676
diff changeset
224 /** 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
225 @Override
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
226 protected void writePDF(OutputStream out) {
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227 logger.warn("Not implemented.");
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
228 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
229 }
368db84f1241 issue1416: Move a stub new SedimentLoadExporter in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
230 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org