8946
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax; |
|
10 |
|
11 import java.util.ArrayList; |
|
12 import java.util.Collection; |
|
13 |
|
14 import org.apache.commons.lang.StringUtils; |
|
15 import org.apache.log4j.Logger; |
|
16 import org.dive4elements.river.artifacts.sinfo.SInfoI18NStrings; |
|
17 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoExporter; |
|
18 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; |
|
19 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource; |
|
20 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
|
21 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
|
22 import org.dive4elements.river.utils.RiverUtils; |
|
23 |
|
24 import au.com.bytecode.opencsv.CSVWriter; |
|
25 |
|
26 /** |
|
27 * Generates different output formats (csv, pdf) of data that resulted from a flow depths computation. |
|
28 * |
|
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
|
30 * @author Gernot Belger |
|
31 */ |
|
32 // REMARK: must be public because its registered in generators.xml |
|
33 public class FlowDepthMinMaxExporter extends AbstractSInfoExporter<FlowDepthMinMaxRow, FlowDepthMinMaxCalculationResult, FlowDepthMinMaxCalculationResults> { |
|
34 |
|
35 /** The log used in this exporter. */ |
|
36 private static Logger log = Logger.getLogger(FlowDepthMinMaxExporter.class); |
|
37 |
|
38 private static final String CSV_FLOWDEPTH_MIN_HEADER = "sinfo.export.flow_depth_minmax.csv.header.min"; |
|
39 |
|
40 private static final String CSV_FLOWDEPTH_MAX_HEADER = "sinfo.export.flow_depth_minmax.csv.header.max"; |
|
41 |
|
42 private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper"; |
|
43 |
|
44 @Override |
|
45 protected Logger getLog() { |
|
46 return log; |
|
47 } |
|
48 |
|
49 @Override |
|
50 protected void writeCSVResultMetadata(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results, |
|
51 final FlowDepthMinMaxCalculationResult result) { |
|
52 |
|
53 final BedHeightInfo sounding = result.getAnySounding(); |
|
54 super.writeCSVSoundingMetadata(writer, sounding); |
|
55 |
|
56 final WstInfo wst = result.getWst(); |
|
57 writeCSVWaterlevelMetadata(writer, wst); |
|
58 } |
|
59 |
|
60 @Override |
|
61 protected void writeCSVGlobalMetadata(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results) { |
|
62 |
|
63 super.writeCSVGlobalMetadataDefaults(writer, results); |
|
64 |
|
65 writer.writeNext(new String[] { "" }); |
|
66 } |
|
67 |
|
68 /** |
|
69 * Write the header, with different headings depending on whether at a |
|
70 * gauge or at a location. |
|
71 * |
|
72 * @param river |
|
73 * @param useTkh |
|
74 */ |
|
75 @Override |
|
76 protected void writeCSVHeader(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results, final RiverInfo river) { |
|
77 log.info("FlowDepthExporter.writeCSVHeader"); |
|
78 |
|
79 final Collection<String> header = new ArrayList<>(11); |
|
80 |
|
81 header.add(msg(SInfoI18NStrings.CSV_KM_HEADER)); |
|
82 |
|
83 header.add(msgUnit(CSV_FLOWDEPTH_MIN_HEADER, SInfoI18NStrings.UNIT_M)); |
|
84 header.add(msgUnit(CSV_FLOWDEPTH_MAX_HEADER, SInfoI18NStrings.UNIT_M)); |
|
85 |
|
86 header.add(msgUnit(SInfoI18NStrings.CSV_WATERLEVEL_HEADER, river.getWstUnit())); |
|
87 header.add(msgUnit(SInfoI18NStrings.CSV_DISCHARGE_HEADER, SInfoI18NStrings.UNIT_CUBIC_M)); |
|
88 header.add(msg(SInfoI18NStrings.CSV_LABEL_HEADER)); |
|
89 header.add(msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); |
|
90 header.add(msgUnit(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER, river.getWstUnit())); |
|
91 header.add(msg(SInfoI18NStrings.CSV_SOUNDING_HEADER)); |
|
92 header.add(msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); |
|
93 |
|
94 writer.writeNext(header.toArray(new String[header.size()])); |
|
95 } |
|
96 |
|
97 @Override |
|
98 protected String[] formatCSVRow(final FlowDepthMinMaxCalculationResults results, final FlowDepthMinMaxRow row) { |
|
99 return formatFlowDepthRow(row); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
|
104 * |
|
105 * @param useTkh |
|
106 */ |
|
107 private String[] formatFlowDepthRow(final FlowDepthMinMaxRow row) { |
|
108 |
|
109 final Collection<String> lines = new ArrayList<>(11); |
|
110 |
|
111 // Fluss-km |
|
112 lines.add(getKmFormatter().format(row.getStation())); |
|
113 |
|
114 // FIXME: spalten weglassen, wenn min oder max fehlt |
|
115 |
|
116 // Minimale Fließtiefe [m] |
|
117 lines.add(getFlowDepthFormatter().format(row.getMinFlowDepth())); |
|
118 // Maximale Fließtiefe [m] |
|
119 lines.add(getFlowDepthFormatter().format(row.getMaxFlowDepth())); |
|
120 |
|
121 // Wasserstand [NN + m] |
|
122 lines.add(getW2Formatter().format(row.getWaterlevel())); |
|
123 |
|
124 // Q [m³/s] |
|
125 final double discharge = row.getDischarge(); |
|
126 if (Double.isNaN(discharge)) |
|
127 lines.add(StringUtils.EMPTY); |
|
128 else { |
|
129 final double roundedDischarge = RiverUtils.roundQ(discharge); |
|
130 lines.add(getQFormatter().format(roundedDischarge)); |
|
131 } |
|
132 |
|
133 // Bezeichnung |
|
134 lines.add(row.getWaterlevelLabel()); |
|
135 |
|
136 // Bezugspegel |
|
137 lines.add(row.getGauge()); |
|
138 |
|
139 // Mittlere Sohlhöhe [NN + m] |
|
140 lines.add(getMeanBedHeighFormatter().format(row.getMeanBedHeight())); |
|
141 |
|
142 // Peilung/Epoche |
|
143 lines.add(row.getSoundageLabel()); |
|
144 |
|
145 // Lage |
|
146 lines.add(row.getLocation()); |
|
147 |
|
148 return lines.toArray(new String[lines.size()]); |
|
149 } |
|
150 |
|
151 @Override |
|
152 protected final String getJasperFile() { |
|
153 return JASPER_FILE; |
|
154 } |
|
155 |
|
156 @Override |
|
157 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final FlowDepthMinMaxCalculationResults results) { |
|
158 |
|
159 /* general metadata */ |
|
160 super.addJRMetaDataDefaults(source, results); |
|
161 |
|
162 /* column headings */ |
|
163 source.addMetaData("station_header", msg(SInfoI18NStrings.CSV_KM_HEADER)); |
|
164 source.addMetaData("flowdepthmin_header", msg(CSV_FLOWDEPTH_MIN_HEADER)); |
|
165 source.addMetaData("flowdepthmax_header", msg(CSV_FLOWDEPTH_MAX_HEADER)); |
|
166 source.addMetaData("waterlevel_header", msg(SInfoI18NStrings.CSV_WATERLEVEL_HEADER)); |
|
167 source.addMetaData("discharge_header", msg(SInfoI18NStrings.CSV_DISCHARGE_HEADER)); |
|
168 source.addMetaData("waterlevel_name_header", msg(SInfoI18NStrings.CSV_LABEL_HEADER)); |
|
169 source.addMetaData("gauge_header", msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); |
|
170 source.addMetaData("bedheight_header", msg(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER_SHORT)); |
|
171 source.addMetaData("sounding_name_header", msg(SInfoI18NStrings.CSV_SOUNDING_HEADER)); |
|
172 source.addMetaData("location_header", msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); |
|
173 } |
|
174 |
|
175 @Override |
|
176 protected String[] formatPDFRow(final FlowDepthMinMaxCalculationResults results, final FlowDepthMinMaxRow row) { |
|
177 return formatFlowDepthRow(row); |
|
178 } |
|
179 } |