Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java @ 8877:9f7a285b0ee3
Some work on SINFO FlowDepth
author | gernotbelger |
---|---|
date | Thu, 08 Feb 2018 18:48:24 +0100 |
parents | 1009cab0f86b |
children | 64ca63f79f6f |
comparison
equal
deleted
inserted
replaced
8876:23264d1a528f | 8877:9f7a285b0ee3 |
---|---|
15 import java.util.Date; | 15 import java.util.Date; |
16 import java.util.HashMap; | 16 import java.util.HashMap; |
17 import java.util.Locale; | 17 import java.util.Locale; |
18 import java.util.Map; | 18 import java.util.Map; |
19 | 19 |
20 import org.apache.commons.lang.StringUtils; | |
20 import org.apache.log4j.Logger; | 21 import org.apache.log4j.Logger; |
21 import org.dive4elements.artifacts.CallMeta; | 22 import org.dive4elements.artifacts.CallMeta; |
22 import org.dive4elements.artifacts.common.utils.Config; | 23 import org.dive4elements.artifacts.common.utils.Config; |
23 import org.dive4elements.river.FLYS; | 24 import org.dive4elements.river.FLYS; |
24 import org.dive4elements.river.artifacts.model.CalculationResult; | 25 import org.dive4elements.river.artifacts.model.CalculationResult; |
42 * @author Gernot Belger | 43 * @author Gernot Belger |
43 */ | 44 */ |
44 // REMARK: must be public because its registered in generators.xml | 45 // REMARK: must be public because its registered in generators.xml |
45 public class FlowDepthExporter extends AbstractExporter { | 46 public class FlowDepthExporter extends AbstractExporter { |
46 | 47 |
47 /** The log used in this exporter.*/ | 48 /** The log used in this exporter. */ |
48 private static Logger log = Logger.getLogger(FlowDepthExporter.class); | 49 private static Logger log = Logger.getLogger(FlowDepthExporter.class); |
49 | 50 |
50 private static final String CSV_KM_HEADER = "sinfo.export.flow_depth.csv.header.km"; | 51 private static final String CSV_KM_HEADER = "sinfo.export.flow_depth.csv.header.km"; |
51 private static final String CSV_FLOWDEPTH_HEADER = "sinfo.export.flow_depth.csv.header.flowdepth"; | 52 private static final String CSV_FLOWDEPTH_HEADER = "sinfo.export.flow_depth.csv.header.flowdepth"; |
52 private static final String CSV_FLOWDEPTHTKH_HEADER = "sinfo.export.flow_depth.csv.header.flowdepthTkh"; | 53 private static final String CSV_FLOWDEPTHTKH_HEADER = "sinfo.export.flow_depth.csv.header.flowdepthTkh"; |
57 private static final String CSV_GAUGE_HEADER = "sinfo.export.flow_depth.csv.header.gauge"; | 58 private static final String CSV_GAUGE_HEADER = "sinfo.export.flow_depth.csv.header.gauge"; |
58 private static final String CSV_MEAN_BED_HEIGHT_HEADER = "sinfo.export.flow_depth.csv.header.mean_bed_height"; | 59 private static final String CSV_MEAN_BED_HEIGHT_HEADER = "sinfo.export.flow_depth.csv.header.mean_bed_height"; |
59 private static final String CSV_MEAN_BED_HEIGHT_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.mean_bed_height.short"; | 60 private static final String CSV_MEAN_BED_HEIGHT_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.mean_bed_height.short"; |
60 private static final String CSV_SOUNDING_HEADER = "sinfo.export.flow_depth.csv.header.sounding"; | 61 private static final String CSV_SOUNDING_HEADER = "sinfo.export.flow_depth.csv.header.sounding"; |
61 private static final String CSV_LOCATION_HEADER = "sinfo.export.flow_depth.csv.header.location"; | 62 private static final String CSV_LOCATION_HEADER = "sinfo.export.flow_depth.csv.header.location"; |
62 | 63 |
63 private static final String CSV_META_HEADER_RESULT = | 64 private static final String CSV_META_HEADER_RESULT = "sinfo.export.flow_depth.csv.meta.header.result"; |
64 "sinfo.export.flow_depth.csv.meta.header.result"; | 65 |
65 | 66 private static final String CSV_META_HEADER_RESULT_LABEL = "sinfo.export.flow_depth.csv.meta.header.result.label"; |
66 private static final String CSV_META_HEADER_RESULT_LABEL = | 67 |
67 "sinfo.export.flow_depth.csv.meta.header.result.label"; | 68 private static final String CSV_META_VERSION = "sinfo.export.flow_depth.csv.meta.version"; |
68 | 69 |
69 private static final String CSV_META_VERSION = | 70 private static final String CSV_META_VERSION_LABEL = "sinfo.export.flow_depth.csv.meta.version.label"; |
70 "sinfo.export.flow_depth.csv.meta.version"; | 71 |
71 | 72 private static final String CSV_META_USER = "sinfo.export.flow_depth.csv.meta.user"; |
72 private static final String CSV_META_VERSION_LABEL = | 73 |
73 "sinfo.export.flow_depth.csv.meta.version.label"; | 74 private static final String CSV_META_USER_LABEL = "sinfo.export.flow_depth.csv.meta.user.label"; |
74 | 75 |
75 private static final String CSV_META_USER = | 76 private static final String CSV_META_CREATION = "sinfo.export.flow_depth.csv.meta.creation"; |
76 "sinfo.export.flow_depth.csv.meta.user"; | 77 |
77 | 78 private static final String CSV_META_CREATION_LABEL = "sinfo.export.flow_depth.csv.meta.creation.label"; |
78 private static final String CSV_META_USER_LABEL = | 79 |
79 "sinfo.export.flow_depth.csv.meta.user.label"; | 80 private static final String CSV_META_RIVER = "sinfo.export.flow_depth.csv.meta.river"; |
80 | 81 |
81 private static final String CSV_META_CREATION = | 82 private static final String CSV_META_RIVER_LABEL = "sinfo.export.flow_depth.csv.meta.river.label"; |
82 "sinfo.export.flow_depth.csv.meta.creation"; | 83 |
83 | 84 private static final String CSV_META_HEADER_SOUNDING = "sinfo.export.flow_depth.csv.meta.header.sounding"; |
84 private static final String CSV_META_CREATION_LABEL = | 85 |
85 "sinfo.export.flow_depth.csv.meta.creation.label"; | 86 private static final String CSV_META_HEADER_SOUNDING_YEAR = "sinfo.export.flow_depth.csv.meta.header.sounding.year"; |
86 | 87 |
87 private static final String CSV_META_RIVER = | 88 private static final String CSV_META_HEADER_SOUNDING_TYPE = "sinfo.export.flow_depth.csv.meta.header.sounding.type"; |
88 "sinfo.export.flow_depth.csv.meta.river"; | 89 |
89 | 90 private static final String CSV_META_HEADER_SOUNDING_PRJ = "sinfo.export.flow_depth.csv.meta.header.sounding.prj"; |
90 private static final String CSV_META_RIVER_LABEL = | 91 |
91 "sinfo.export.flow_depth.csv.meta.river.label"; | 92 private static final String CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL = "sinfo.export.flow_depth.csv.meta.header.sounding.elevationmodel"; |
92 | 93 |
93 private static final String CSV_META_HEADER_SOUNDING = | 94 private static final String CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL_ORIGINAL = "sinfo.export.flow_depth.csv.meta.header.sounding.elevationmodel.original"; |
94 "sinfo.export.flow_depth.csv.meta.header.sounding"; | 95 |
95 | 96 private static final String CSV_META_HEADER_WATERLEVEL = "sinfo.export.flow_depth.csv.meta.header.waterlevel"; |
96 private static final String CSV_META_HEADER_WATERLEVEL = | 97 |
97 "sinfo.export.flow_depth.csv.meta.header.waterlevel"; | 98 private static final String CSV_META_HEADER_WATERLEVEL_NAME = "sinfo.export.flow_depth.csv.meta.header.waterlevel.name"; |
98 | 99 |
99 private static final String CSV_META_RANGE = | 100 private static final String CSV_META_HEADER_WATERLEVEL_ELEVATION_MODEL = "sinfo.export.flow_depth.csv.meta.header.waterlevel.elevationmodel"; |
100 "sinfo.export.flow_depth.csv.meta.range"; | 101 |
101 | 102 private static final String CSV_META_HEADER_WATERLEVEL_EVALUATOR = "sinfo.export.flow_depth.csv.meta.header.waterlevel.evaluator"; |
102 private static final String CSV_META_RANGE_LABEL = | 103 |
103 "sinfo.export.flow_depth.csv.meta.range.label"; | 104 private static final String CSV_META_HEADER_WATERLEVEL_GAUGE = "sinfo.export.flow_depth.csv.meta.header.waterlevel.gauge"; |
104 | 105 |
106 private static final String CSV_META_HEADER_WATERLEVEL_YEAR = "sinfo.export.flow_depth.csv.meta.header.waterlevel.year"; | |
107 | |
108 private static final String CSV_META_RANGE = "sinfo.export.flow_depth.csv.meta.range"; | |
109 | |
110 private static final String CSV_META_RANGE_LABEL = "sinfo.export.flow_depth.csv.meta.range.label"; | |
111 | |
105 private static final String CSV_META_HEIGHT_UNIT_RIVER = "sinfo.export.flow_depth.csv.meta.height_unit.river"; | 112 private static final String CSV_META_HEIGHT_UNIT_RIVER = "sinfo.export.flow_depth.csv.meta.height_unit.river"; |
106 | 113 |
107 private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper"; | 114 private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper"; |
108 | 115 |
109 private static final String UNIT_M = "m"; | 116 private static final String UNIT_M = "m"; |
110 | 117 |
111 private static final String UNIT_CM = "cm"; | 118 private static final String UNIT_CM = "cm"; |
112 | 119 |
113 private static final String UNIT_CUBIC_M = "m³/s"; | 120 private static final String UNIT_CUBIC_M = "m³/s"; |
114 | 121 |
115 /** The storage that contains the current calculation result.*/ | 122 /** The storage that contains the current calculation result. */ |
116 private FlowDepthCalculationResults data = null; | 123 private FlowDepthCalculationResults data = null; |
117 | 124 |
118 /** | 125 /** |
119 * Formats header with unit | 126 * Formats header with unit |
120 */ | 127 */ |
121 private String msgUnit(final String key, String unit ) { | 128 private String msgUnit(final String key, final String unit) { |
122 | 129 |
123 final String msg = msg(key); | 130 final String msg = msg(key); |
124 return String.format("%s [%s]", msg, unit); | 131 return String.format("%s [%s]", msg, unit); |
125 } | 132 } |
126 | 133 |
127 @Override | 134 @Override |
128 protected void addData(Object d) { | 135 protected void addData(final Object d) { |
129 /* reset */ | 136 /* reset */ |
130 data = null; | 137 this.data = null; |
131 | 138 |
132 if (d instanceof CalculationResult) { | 139 if (d instanceof CalculationResult) { |
133 | 140 |
134 final Object dat = ((CalculationResult)d).getData(); | 141 final Object dat = ((CalculationResult) d).getData(); |
135 if( dat != null ) | 142 if (dat != null) |
136 data = (FlowDepthCalculationResults)dat; | 143 this.data = (FlowDepthCalculationResults) dat; |
137 } | 144 } |
138 } | 145 } |
139 | 146 |
140 @Override | 147 @Override |
141 protected void writeCSVData(CSVWriter writer) { | 148 protected void writeCSVData(final CSVWriter writer) { |
142 log.info("FlowDepthExporter.writeCSVData"); | 149 log.info("FlowDepthExporter.writeCSVData"); |
143 | 150 |
144 /* fetch calculation results */ | 151 /* fetch calculation results */ |
145 final FlowDepthCalculationResults results = data; | 152 final FlowDepthCalculationResults results = this.data; |
146 | 153 |
147 final boolean useTkh = results.isUseTkh(); | 154 final boolean useTkh = results.isUseTkh(); |
148 final River river = results.getRiver(); | 155 final River river = results.getRiver(); |
149 | 156 |
150 /* write as csv */ | 157 /* write as csv */ |
151 writeCSVMeta(writer, results); | 158 writeCSVMeta(writer, results); |
152 writeCSVHeader(writer, river, useTkh); | 159 writeCSVHeader(writer, river, useTkh); |
153 | 160 |
154 for (final FlowDepthCalculationResult result : results.getResults()) { | 161 for (final FlowDepthCalculationResult result : results.getResults()) { |
155 writeCSVFlowDepthResult(writer, result, useTkh); | 162 writeCSVFlowDepthResult(writer, result, useTkh); |
156 } | 163 } |
157 } | 164 } |
158 | 165 |
159 private void writeCSVFlowDepthResult(final CSVWriter writer, final FlowDepthCalculationResult result, final boolean useTkh) { | 166 private void writeCSVFlowDepthResult(final CSVWriter writer, final FlowDepthCalculationResult result, |
167 final boolean useTkh) { | |
168 | |
169 /* first some specific metadata */ | |
170 final BedHeightInfo sounding = result.getSounding(); | |
171 final WstInfo wst = result.getWst(); | |
172 | |
173 // "##METADATEN PEILUNG" | |
174 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING); | |
175 | |
176 // "# Jahr der Peilung: " | |
177 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_YEAR, Integer.toString(sounding.getYear())); | |
178 // "# Aufnahmeart: " | |
179 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_TYPE, sounding.getType()); | |
180 // "# Lagesystem: " | |
181 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_PRJ, sounding.getLocationSystem()); | |
182 // "# Höhensystem: " | |
183 // TODO: klären einheit oder name des höhensystems? | |
184 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL, sounding.getCurElevationModelName()); | |
185 // "# ursprüngliches Höhensystem: " | |
186 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL_ORIGINAL, | |
187 sounding.getOldElevationModelName()); | |
188 | |
189 // "##METADATEN WASSERSPIEGELLAGE" | |
190 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL); | |
191 // "# Bezeichnung der Wasserspiegellage: " | |
192 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_NAME, wst.getLabel()); | |
193 // "# Höhensystem der Wasserspiegellage: " | |
194 // FIXME: discussion! | |
195 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_ELEVATION_MODEL, "FIXME"); | |
196 // "# Auswerter: ": discussion! | |
197 // FIXME: discussion! | |
198 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_EVALUATOR, "FIXME"); | |
199 // "# Bezugspegel: " discussion | |
200 // FIXME: Umsetzung IDENTISCH zu allen möglichen Arten wie ein WSPL berechnet wird.... | |
201 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_GAUGE, "FIXME"); | |
202 // "# Jahr/Zeitraum der Wasserspiegellage: " | |
203 // FIXME: discussion! | |
204 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_YEAR, Integer.toString(wst.getYear())); | |
205 | |
206 /* nwo the value rows */ | |
160 final Collection<FlowDepthRow> rows = result.getRows(); | 207 final Collection<FlowDepthRow> rows = result.getRows(); |
161 for (final FlowDepthRow flowDepthRow : rows) { | 208 for (final FlowDepthRow flowDepthRow : rows) { |
162 writeCSVFlowDepthRow(writer, flowDepthRow, useTkh); | 209 writeCSVFlowDepthRow(writer, flowDepthRow, useTkh); |
163 } | 210 } |
164 } | 211 } |
165 | 212 |
166 private void writeCSVMeta(final CSVWriter writer, final FlowDepthCalculationResults results) { | 213 private void writeCSVMeta(final CSVWriter writer, final FlowDepthCalculationResults results) { |
167 log.info("FlowDepthExporter.writeCSVMeta"); | 214 log.info("FlowDepthExporter.writeCSVMeta"); |
168 | 215 |
169 final String calcModeLabel = results.getCalcModeLabel(); | 216 final String calcModeLabel = results.getCalcModeLabel(); |
170 final River river = results.getRiver(); | 217 final River river = results.getRiver(); |
171 writeCSVMetaEntry(writer, CSV_META_HEADER_RESULT, msg( CSV_META_HEADER_RESULT_LABEL ), river.getName(), calcModeLabel ); | 218 writeCSVMetaEntry(writer, CSV_META_HEADER_RESULT, msg(CSV_META_HEADER_RESULT_LABEL), river.getName(), |
172 | 219 calcModeLabel); |
173 // "# FLYS-Version: " | 220 |
174 writeCSVMetaEntry(writer, CSV_META_VERSION, msg( CSV_META_VERSION_LABEL ), FLYS.VERSION ); | 221 // "# FLYS-Version: " |
175 | 222 writeCSVMetaEntry(writer, CSV_META_VERSION, msg(CSV_META_VERSION_LABEL), FLYS.VERSION); |
176 // "# Bearbeiter: " | 223 |
177 writeCSVMetaEntry(writer, CSV_META_USER, msg( CSV_META_USER_LABEL ), results.getUser() ); | 224 // "# Bearbeiter: " |
225 writeCSVMetaEntry(writer, CSV_META_USER, msg(CSV_META_USER_LABEL), results.getUser()); | |
178 | 226 |
179 // "# Datum der Erstellung: " | 227 // "# Datum der Erstellung: " |
180 final Locale locale = Resources.getLocale(context.getMeta()); | 228 final Locale locale = Resources.getLocale(this.context.getMeta()); |
181 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | 229 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); |
182 writeCSVMetaEntry(writer, CSV_META_CREATION, msg( CSV_META_CREATION_LABEL ), df.format(new Date()) ); | 230 writeCSVMetaEntry(writer, CSV_META_CREATION, msg(CSV_META_CREATION_LABEL), df.format(new Date())); |
183 | 231 |
184 // "# Gewässer: " | 232 // "# Gewässer: " |
185 writeCSVMetaEntry(writer, CSV_META_RIVER, msg( CSV_META_RIVER_LABEL ), river.getName() ); | 233 writeCSVMetaEntry(writer, CSV_META_RIVER, msg(CSV_META_RIVER_LABEL), river.getName()); |
186 | 234 |
187 // "# Höhensystem des Flusses: " | 235 // "# Höhensystem des Flusses: " |
236 // FIXME: klären, was ist gemeint? | |
188 final Unit wstUnit = river.getWstUnit(); | 237 final Unit wstUnit = river.getWstUnit(); |
189 writeCSVMetaEntry(writer, CSV_META_HEIGHT_UNIT_RIVER, wstUnit.getName()); | 238 writeCSVMetaEntry(writer, CSV_META_HEIGHT_UNIT_RIVER, wstUnit.getName()); |
190 | 239 |
191 // "# Ort/Bereich (km): " | 240 // "# Ort/Bereich (km): " |
192 writeCSVMetaEntry(writer, CSV_META_RANGE, msg( CSV_META_RANGE_LABEL ), getKmFormatter().format(results.getFrom() ), getKmFormatter().format( results.getTo())); | 241 writeCSVMetaEntry(writer, CSV_META_RANGE, msg(CSV_META_RANGE_LABEL), getKmFormatter().format(results.getFrom()), |
193 | 242 getKmFormatter().format(results.getTo())); |
194 // "##METADATEN PEILUNG" | |
195 writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING ); | |
196 | |
197 // FIXME: check: macht nicht viel sinn da es mehrere geben kann.. oder immer wieder wiederholen? | |
198 // "# Jahr der Peilung: " | |
199 // FIXME | |
200 // "# Aufnahmeart: " | |
201 // FIXME | |
202 // "# Lagesystem: " | |
203 // FIXME | |
204 // "# Höhensystem: " | |
205 // FIXME | |
206 // "# ursprüngliches Höhensystem: " | |
207 // FIXME | |
208 // "##METADATEN WASSERSPIEGELLAGE" | |
209 writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL ); | |
210 // "# Bezeichnung der Wasserspiegellage: " | |
211 // FIXME | |
212 // "# Höhensystem der Wasserspiegellage: " | |
213 // FIXME | |
214 // "# Auswerter: " | |
215 // FIXME | |
216 // "# Bezugspegel: " | |
217 // FIXME | |
218 // "# Jahr/Zeitraum der Wasserspiegellage: " | |
219 // FIXME | |
220 | |
221 // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel) | |
222 // TODO: unklar, es wird kein W eingegeben | |
223 | |
224 // "# Q (m³/s): " (nur bei Eingabe des Durchflusses) | |
225 // TODO: unklar, es wird kein Q eingegeben | |
226 | 243 |
227 writer.writeNext(new String[] { "" }); | 244 writer.writeNext(new String[] { "" }); |
228 } | 245 } |
229 | 246 |
230 | 247 private void writeCSVMetaEntry(final CSVWriter writer, final String message, final Object... messageArgs) { |
231 private void writeCSVMetaEntry(CSVWriter writer, String message, Object... messageArgs) { | 248 |
232 | 249 final CallMeta meta = this.context.getMeta(); |
233 CallMeta meta = context.getMeta(); | 250 |
234 | 251 writer.writeNext(new String[] { Resources.getMsg(meta, message, message, messageArgs) }); |
235 writer.writeNext(new String[] { | 252 } |
236 Resources.getMsg( | 253 |
237 meta, | 254 /** |
238 message, | |
239 message, | |
240 messageArgs) | |
241 }); | |
242 } | |
243 | |
244 /** | |
245 * Write the header, with different headings depending on whether at a | 255 * Write the header, with different headings depending on whether at a |
246 * gauge or at a location. | 256 * gauge or at a location. |
247 * @param river | 257 * |
248 * @param useTkh | 258 * @param river |
259 * @param useTkh | |
249 */ | 260 */ |
250 private void writeCSVHeader( | 261 private void writeCSVHeader(final CSVWriter writer, final River river, final boolean useTkh) { |
251 final CSVWriter writer, | |
252 final River river, | |
253 final boolean useTkh | |
254 ) { | |
255 log.info("FlowDepthExporter.writeCSVHeader"); | 262 log.info("FlowDepthExporter.writeCSVHeader"); |
256 | 263 |
257 final Collection<String> header = new ArrayList<>(11); | 264 final Collection<String> header = new ArrayList<>(11); |
258 | 265 |
259 header.add(msg(CSV_KM_HEADER)); | 266 header.add(msg(CSV_KM_HEADER)); |
260 header.add(msgUnit(CSV_FLOWDEPTH_HEADER, UNIT_M)); | 267 header.add(msgUnit(CSV_FLOWDEPTH_HEADER, UNIT_M)); |
261 if( useTkh ) | 268 if (useTkh) { |
262 { | 269 header.add(msgUnit(CSV_FLOWDEPTHTKH_HEADER, UNIT_M)); |
263 header.add(msgUnit(CSV_FLOWDEPTHTKH_HEADER, UNIT_M)); | 270 header.add(msgUnit(CSV_TKH_HEADER, UNIT_CM)); |
264 header.add(msgUnit(CSV_TKH_HEADER, UNIT_CM)); | |
265 } | 271 } |
266 | 272 |
267 final String wstUnitName = river.getWstUnit().getName(); | 273 final String wstUnitName = river.getWstUnit().getName(); |
268 header.add(msgUnit(CSV_WATERLEVEL_HEADER, wstUnitName)); | 274 header.add(msgUnit(CSV_WATERLEVEL_HEADER, wstUnitName)); |
269 header.add(msgUnit(CSV_DISCHARGE_HEADER, UNIT_CUBIC_M)); | 275 header.add(msgUnit(CSV_DISCHARGE_HEADER, UNIT_CUBIC_M)); |
271 header.add(msg(CSV_GAUGE_HEADER)); | 277 header.add(msg(CSV_GAUGE_HEADER)); |
272 header.add(msgUnit(CSV_MEAN_BED_HEIGHT_HEADER, wstUnitName)); | 278 header.add(msgUnit(CSV_MEAN_BED_HEIGHT_HEADER, wstUnitName)); |
273 header.add(msg(CSV_SOUNDING_HEADER)); | 279 header.add(msg(CSV_SOUNDING_HEADER)); |
274 header.add(msg(CSV_LOCATION_HEADER)); | 280 header.add(msg(CSV_LOCATION_HEADER)); |
275 | 281 |
276 writer.writeNext(header.toArray(new String[header.size()])); | 282 writer.writeNext(header.toArray(new String[header.size()])); |
277 } | 283 } |
278 | 284 |
279 /** | 285 /** |
280 * Format a row of a flow depth result into an array of string, both used by csv and pdf | 286 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
281 * @param useTkh | 287 * |
288 * @param useTkh | |
282 */ | 289 */ |
283 private String[] formatFlowDepthRow( | 290 private String[] formatFlowDepthRow(final FlowDepthRow row, final boolean useTkh) { |
284 final FlowDepthRow row, | 291 |
285 boolean useTkh ) { | 292 final Collection<String> lines = new ArrayList<>(11); |
286 | 293 |
287 final Collection<String> lines = new ArrayList<>(11); | 294 // Fluss-km |
288 | 295 lines.add(getKmFormatter().format(row.getStation())); |
289 // Fluss-km | 296 |
290 lines.add( getKmFormatter().format( row.getStation() ) ); | 297 // Fließtiefe [m] |
291 | 298 lines.add(getFlowDepthFormatter().format(row.getFlowDepth())); |
292 // Fließtiefe [m] | 299 |
293 lines.add( getFlowDepthFormatter().format( row.getFlowDepth() ) ); | 300 if (useTkh) { |
294 | 301 // Fließtiefe mit TKH [m] |
295 if( useTkh ) | 302 lines.add(getFlowDepthFormatter().format(row.getFlowDepthWithTkh())); |
296 { | 303 |
297 // Fließtiefe mit TKH [m] | 304 // TKH [cm] |
298 lines.add( getFlowDepthFormatter().format( row.getFlowDepthWithTkh() ) ); | 305 lines.add(getTkhFormatter().format(row.getTkh())); |
299 | 306 } |
300 // TKH [cm] | 307 |
301 lines.add( getTkhFormatter().format( row.getTkh() ) ); | 308 // Wasserstand [NN + m] |
302 } | 309 lines.add(getW2Formatter().format(row.getWaterlevel())); |
303 | 310 |
304 // Wasserstand [NN + m] | 311 // Q [m³/s] |
305 lines.add( getW2Formatter().format( row.getWaterlevel() ) ); | 312 final double discharge = row.getDischarge(); |
306 | 313 if( Double.isNaN(discharge)) |
307 // Q [m³/s] | 314 lines.add(StringUtils.EMPTY); |
308 lines.add( getQFormatter().format( row.getDischarge() ) ); | 315 else |
309 | 316 lines.add(getQFormatter().format(discharge)); |
310 // Bezeichnung | 317 |
311 lines.add( row.getWaterlevelLabel() ); | 318 // Bezeichnung |
312 | 319 lines.add(row.getWaterlevelLabel()); |
313 // Bezugspegel | 320 |
314 lines.add( row.getGauge() ); | 321 // Bezugspegel |
315 | 322 lines.add(row.getGauge()); |
316 // Mittlere Sohlhöhe [NN + m] | 323 |
317 lines.add( getMeanBedHeighFormatter().format( row.getMeanBedHeight( ) ) ); | 324 // Mittlere Sohlhöhe [NN + m] |
318 | 325 lines.add(getMeanBedHeighFormatter().format(row.getMeanBedHeight())); |
319 // Peilung/Epoche | 326 |
320 lines.add( row.getSoundageLabel() ); | 327 // Peilung/Epoche |
321 | 328 lines.add(row.getSoundageLabel()); |
322 // Lage | 329 |
323 lines.add( row.getLocation() ); | 330 // Lage |
324 | 331 lines.add(row.getLocation()); |
325 return lines.toArray(new String[lines.size()]); | 332 |
326 } | 333 return lines.toArray(new String[lines.size()]); |
334 } | |
335 | |
327 /** | 336 /** |
328 * Write "rows" of csv data from wqkms with writer. | 337 * Write "rows" of csv data from wqkms with writer. |
329 * @param useTkh | 338 * |
339 * @param useTkh | |
330 */ | 340 */ |
331 private void writeCSVFlowDepthRow( | 341 private void writeCSVFlowDepthRow(final CSVWriter writer, final FlowDepthRow row, final boolean useTkh) { |
332 final CSVWriter writer, | |
333 final FlowDepthRow row, | |
334 final boolean useTkh | |
335 ) { | |
336 log.debug("FlowDepthExporter.writeCSVFlowDepthRow"); | 342 log.debug("FlowDepthExporter.writeCSVFlowDepthRow"); |
337 | 343 |
338 final String[] formattedRow = formatFlowDepthRow(row, useTkh); | 344 final String[] formattedRow = formatFlowDepthRow(row, useTkh); |
339 writer.writeNext( formattedRow ); | 345 writer.writeNext(formattedRow); |
340 } | 346 } |
341 | 347 |
342 @Override | 348 @Override |
343 protected void writePDF(OutputStream outStream) { | 349 protected void writePDF(final OutputStream outStream) { |
344 log.debug("write PDF"); | 350 log.debug("write PDF"); |
345 | 351 |
346 final JRDataSource source = createJRData(); | 352 final JRDataSource source = createJRData(); |
347 | 353 |
348 final String confPath = Config.getConfigDirectory().toString(); | 354 final String confPath = Config.getConfigDirectory().toString(); |
349 | 355 |
350 // FIXME: distinguish between with and without tkh: we need two jasper reports! | 356 // FIXME: distinguish between with and without tkh: we need two jasper reports! |
351 | 357 |
352 final Map<String,Object> parameters = new HashMap<>(); | 358 final Map<String, Object> parameters = new HashMap<>(); |
353 parameters.put("ReportTitle", "Exported Data"); | 359 parameters.put("ReportTitle", "Exported Data"); |
354 try { | 360 try { |
355 final JasperPrint print = JasperFillManager.fillReport( | 361 final JasperPrint print = JasperFillManager.fillReport(confPath + JASPER_FILE, parameters, source); |
356 confPath + JASPER_FILE, | |
357 parameters, | |
358 source); | |
359 JasperExportManager.exportReportToPdfStream(print, outStream); | 362 JasperExportManager.exportReportToPdfStream(print, outStream); |
360 } | 363 } |
361 catch(JRException je) { | 364 catch (final JRException je) { |
362 log.warn("Error generating PDF Report!", je); | 365 log.warn("Error generating PDF Report!", je); |
363 } | 366 } |
364 } | 367 } |
365 | 368 |
366 private JRDataSource createJRData() { | 369 private JRDataSource createJRData() { |
367 | 370 |
368 /* fetch calculation results */ | 371 /* fetch calculation results */ |
369 final FlowDepthCalculationResults results = data; | 372 final FlowDepthCalculationResults results = this.data; |
370 | 373 |
371 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | 374 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); |
372 | 375 |
373 addJRMetaData(source, results); | 376 addJRMetaData(source, results); |
374 | 377 |
375 final boolean useTkh = results.isUseTkh(); | 378 final boolean useTkh = results.isUseTkh(); |
376 | 379 |
377 for (final FlowDepthCalculationResult result : results.getResults()) { | 380 for (final FlowDepthCalculationResult result : results.getResults()) { |
378 addJRTableData(source, result, useTkh); | 381 addJRTableData(source, result, useTkh); |
379 } | 382 } |
380 | 383 |
381 return source; | 384 return source; |
382 } | 385 } |
383 | 386 |
384 private void addJRMetaData(final MetaAndTableJRDataSource source, FlowDepthCalculationResults results) { | 387 private void addJRMetaData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResults results) { |
385 | 388 |
386 final River river = results.getRiver(); | 389 final River river = results.getRiver(); |
387 final String wstUnitName = river.getWstUnit().getName(); | 390 final String wstUnitName = river.getWstUnit().getName(); |
388 | 391 |
389 /* general metadata */ | 392 /* general metadata */ |
390 source.addMetaData("header", msg(CSV_META_HEADER_RESULT_LABEL)); | 393 source.addMetaData("header", msg(CSV_META_HEADER_RESULT_LABEL)); |
391 source.addMetaData("calcMode", results.getCalcModeLabel()); | 394 source.addMetaData("calcMode", results.getCalcModeLabel()); |
392 | 395 |
393 source.addMetaData("version_label", msg(CSV_META_VERSION_LABEL)); | 396 source.addMetaData("version_label", msg(CSV_META_VERSION_LABEL)); |
394 source.addMetaData("version", FLYS.VERSION); | 397 source.addMetaData("version", FLYS.VERSION); |
395 | 398 |
396 source.addMetaData("user_label", msg(CSV_META_USER_LABEL)); | 399 source.addMetaData("user_label", msg(CSV_META_USER_LABEL)); |
397 source.addMetaData("user", results.getUser()); | 400 source.addMetaData("user", results.getUser()); |
398 | 401 |
399 final Locale locale = Resources.getLocale(context.getMeta()); | 402 final Locale locale = Resources.getLocale(this.context.getMeta()); |
400 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | 403 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); |
401 source.addMetaData("date_label", msg(CSV_META_CREATION_LABEL)); | 404 source.addMetaData("date_label", msg(CSV_META_CREATION_LABEL)); |
402 source.addMetaData("date", df.format(new Date())); | 405 source.addMetaData("date", df.format(new Date())); |
403 | 406 |
404 source.addMetaData("river_label", msg(CSV_META_RIVER_LABEL) ); | 407 source.addMetaData("river_label", msg(CSV_META_RIVER_LABEL)); |
405 source.addMetaData("river", river.getName()); | 408 source.addMetaData("river", river.getName()); |
406 | 409 |
407 final String rangeValue = String.format( "%s - %s", getKmFormatter().format(results.getFrom() ), getKmFormatter().format( results.getTo())); | 410 final String rangeValue = String.format("%s - %s", getKmFormatter().format(results.getFrom()), |
411 getKmFormatter().format(results.getTo())); | |
408 source.addMetaData("range_label", msg(CSV_META_RANGE_LABEL)); | 412 source.addMetaData("range_label", msg(CSV_META_RANGE_LABEL)); |
409 source.addMetaData("range", rangeValue); | 413 source.addMetaData("range", rangeValue); |
410 | 414 |
411 /* column headings */ | 415 /* column headings */ |
412 source.addMetaData("station_header", msg(CSV_KM_HEADER)); | 416 source.addMetaData("station_header", msg(CSV_KM_HEADER)); |
421 source.addMetaData("bedheight_header", msg(CSV_MEAN_BED_HEIGHT_HEADER_SHORT)); | 425 source.addMetaData("bedheight_header", msg(CSV_MEAN_BED_HEIGHT_HEADER_SHORT)); |
422 source.addMetaData("sounding_name_header", msg(CSV_SOUNDING_HEADER)); | 426 source.addMetaData("sounding_name_header", msg(CSV_SOUNDING_HEADER)); |
423 source.addMetaData("location_header", msg(CSV_LOCATION_HEADER)); | 427 source.addMetaData("location_header", msg(CSV_LOCATION_HEADER)); |
424 } | 428 } |
425 | 429 |
426 private void addJRTableData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResult result, final boolean useTkh) { | 430 private void addJRTableData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResult result, |
427 | 431 final boolean useTkh) { |
428 final Collection<FlowDepthRow> rows = result.getRows(); | 432 |
429 | 433 final Collection<FlowDepthRow> rows = result.getRows(); |
430 for (final FlowDepthRow row : rows) { | 434 |
431 | 435 for (final FlowDepthRow row : rows) { |
432 final String[] formattedRow = formatFlowDepthRow(row, useTkh); | 436 |
433 source.addData(formattedRow); | 437 final String[] formattedRow = formatFlowDepthRow(row, useTkh); |
434 } | 438 source.addData(formattedRow); |
435 } | 439 } |
440 } | |
436 } | 441 } |