Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java @ 8938:9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
author | gernotbelger |
---|---|
date | Tue, 06 Mar 2018 17:09:39 +0100 |
parents | 791714b92b5c |
children | 5d5d482da3e9 |
comparison
equal
deleted
inserted
replaced
8937:8596f95673b1 | 8938:9c02733a1b3c |
---|---|
34 * @author Gernot Belger | 34 * @author Gernot Belger |
35 */ | 35 */ |
36 // REMARK: must be public because its registered in generators.xml | 36 // REMARK: must be public because its registered in generators.xml |
37 public class TkhExporter extends AbstractSInfoExporter<TkhResultRow, TkhCalculationResult, TkhCalculationResults> { | 37 public class TkhExporter extends AbstractSInfoExporter<TkhResultRow, TkhCalculationResult, TkhCalculationResults> { |
38 | 38 |
39 private static enum ExportMode { | |
40 pdf, csv | |
41 } | |
42 | |
39 /** The log used in this exporter. */ | 43 /** The log used in this exporter. */ |
40 private static Logger log = Logger.getLogger(TkhExporter.class); | 44 private static Logger log = Logger.getLogger(TkhExporter.class); |
41 | 45 |
42 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; | 46 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; |
43 | 47 |
55 protected Logger getLog() { | 59 protected Logger getLog() { |
56 return log; | 60 return log; |
57 } | 61 } |
58 | 62 |
59 @Override | 63 @Override |
60 protected final void writeCSVMeta(final CSVWriter writer, final TkhCalculationResults results) { | 64 protected void writeCSVGlobalMetadata(final CSVWriter writer, final TkhCalculationResults results) { |
61 log.info("TkhExporter.writeCSVMeta"); | 65 log.info("TkhExporter.writeCSVMeta"); |
62 | 66 |
63 final String calcModeLabel = results.getCalcModeLabel(); | 67 final String calcModeLabel = results.getCalcModeLabel(); |
64 final RiverInfo river = results.getRiver(); | 68 final RiverInfo river = results.getRiver(); |
65 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_RESULT, msg(SInfoI18NStrings.CSV_META_HEADER_RESULT_LABEL), river.getName(), calcModeLabel); | 69 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_RESULT, msg(SInfoI18NStrings.CSV_META_HEADER_RESULT_LABEL), river.getName(), calcModeLabel); |
93 } | 97 } |
94 | 98 |
95 /** | 99 /** |
96 * Write the header, with different headings depending on whether at a gauge or at a location. | 100 * Write the header, with different headings depending on whether at a gauge or at a location. |
97 */ | 101 */ |
98 @Override | 102 |
99 protected final void writeCSVHeader(final CSVWriter writer, final RiverInfo river) { | 103 @Override |
104 protected void writeCSVHeader(final CSVWriter writer, final TkhCalculationResults results, final RiverInfo river) { | |
100 log.info("TkhExporter.writeCSVHeader"); | 105 log.info("TkhExporter.writeCSVHeader"); |
101 | 106 |
102 final Collection<String> header = new ArrayList<>(11); | 107 final Collection<String> header = new ArrayList<>(11); |
103 | 108 |
104 header.add(msg(SInfoI18NStrings.CSV_KM_HEADER)); | 109 header.add(msg(SInfoI18NStrings.CSV_KM_HEADER)); |
105 header.add(msgUnit(CSV_TKH_HEADER, SInfoI18NStrings.UNIT_CM)); | 110 header.add(msgUnit(CSV_TKH_HEADER, SInfoI18NStrings.UNIT_CM)); |
106 header.add(msgUnit(CSV_TKHKIND_HEADER, SInfoI18NStrings.UNIT_CM)); | 111 header.add(msg(CSV_TKHKIND_HEADER)); |
107 header.add(msgUnit(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER, river.getWstUnit())); | 112 header.add(msgUnit(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER, river.getWstUnit())); |
108 | 113 |
109 header.add(msgUnit(SInfoI18NStrings.CSV_WATERLEVEL_HEADER, river.getWstUnit())); | 114 header.add(msgUnit(SInfoI18NStrings.CSV_WATERLEVEL_HEADER, river.getWstUnit())); |
110 header.add(msgUnit(SInfoI18NStrings.CSV_DISCHARGE_HEADER, SInfoI18NStrings.UNIT_CUBIC_M)); | 115 header.add(msgUnit(SInfoI18NStrings.CSV_DISCHARGE_HEADER, SInfoI18NStrings.UNIT_CUBIC_M)); |
111 header.add(msg(SInfoI18NStrings.CSV_LABEL_HEADER)); | 116 |
117 final String descriptionHeader = results.getDescriptionHeader(); | |
118 if (descriptionHeader != null) | |
119 header.add(msg(descriptionHeader)); | |
120 | |
112 header.add(msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); | 121 header.add(msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); |
113 header.add(msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); | 122 header.add(msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); |
114 | 123 |
115 writer.writeNext(header.toArray(new String[header.size()])); | 124 writer.writeNext(header.toArray(new String[header.size()])); |
116 } | 125 } |
117 | 126 |
118 @Override | 127 @Override |
119 protected void writeCSVResultHeader(final CSVWriter writer, final TkhCalculationResult result) { | 128 // FIXME: rename |
129 protected void writeCSVResultMetadata(final CSVWriter writer, final TkhCalculationResults results, final TkhCalculationResult result) { | |
120 | 130 |
121 /* first some specific metadata */ | 131 /* first some specific metadata */ |
122 final WstInfo wst = result.getWst(); | 132 final WstInfo wst = result.getWst(); |
123 | 133 |
124 // "##METADATEN WASSERSPIEGELLAGE" | 134 // "##METADATEN WASSERSPIEGELLAGE" |
125 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL); | 135 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL); |
126 // "# Bezeichnung der Wasserspiegellage: " | 136 // "# Bezeichnung der Wasserspiegellage: " |
127 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, wst.getLabel()); | 137 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, wst.getLabel()); |
128 // "# Bezugspegel: " | 138 // "# Bezugspegel: " |
129 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, wst.getGauge()); | 139 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, wst.getGauge()); |
130 // "# Jahr/Zeitraum der Wasserspiegellage: " | 140 // // "# Jahr/Zeitraum der Wasserspiegellage: " |
131 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_YEAR, Integer.toString(wst.getYear())); | 141 // writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_YEAR, Integer.toString(wst.getYear())); |
132 } | 142 } |
133 | 143 |
134 @Override | 144 @Override |
135 protected final String[] formatCSVRow(final TkhResultRow row) { | 145 protected String[] formatCSVRow(final TkhCalculationResults results, final TkhResultRow row) { |
136 return formatRow(row); | 146 return formatRow(results, row, ExportMode.csv); |
137 } | 147 } |
138 | 148 |
139 /** | 149 /** |
140 * Format a row of a flow depth result into an array of string, both used by csv and pdf | 150 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
141 * | 151 * |
152 * @param results | |
153 * | |
142 * @param useTkh | 154 * @param useTkh |
143 */ | 155 */ |
144 private String[] formatRow(final TkhResultRow row) { | 156 private String[] formatRow(final TkhCalculationResults results, final TkhResultRow row, final ExportMode mode) { |
145 | 157 |
146 final Collection<String> lines = new ArrayList<>(11); | 158 final Collection<String> lines = new ArrayList<>(11); |
147 | 159 |
148 // Fluss-km | 160 // Fluss-km |
149 lines.add(getKmFormatter().format(row.getStation())); | 161 lines.add(getKmFormatter().format(row.getStation())); |
164 final double discharge = row.getDischarge(); | 176 final double discharge = row.getDischarge(); |
165 final double roundedDischarge = RiverUtils.roundQ(discharge); | 177 final double roundedDischarge = RiverUtils.roundQ(discharge); |
166 lines.add(getQFormatter().format(roundedDischarge)); | 178 lines.add(getQFormatter().format(roundedDischarge)); |
167 | 179 |
168 // Bezeichnung | 180 // Bezeichnung |
169 lines.add(row.getWaterlevelLabel()); | 181 // REMARK: always export this column in pdf-mode, because WInfo also does it (no need for two jasper-templates). |
182 if (results.getDescriptionHeader() != null || mode == ExportMode.pdf) | |
183 lines.add(row.getWaterlevelLabel()); | |
170 | 184 |
171 // Bezugspegel | 185 // Bezugspegel |
172 lines.add(row.getGauge()); | 186 lines.add(row.getGauge()); |
173 | 187 |
174 // Lage | 188 // Lage |
217 source.addMetaData("station_header", msg(SInfoI18NStrings.CSV_KM_HEADER)); | 231 source.addMetaData("station_header", msg(SInfoI18NStrings.CSV_KM_HEADER)); |
218 source.addMetaData("tkh_header", msg(CSV_TKH_HEADER)); | 232 source.addMetaData("tkh_header", msg(CSV_TKH_HEADER)); |
219 source.addMetaData("bedheight_header", msg(CSV_MEAN_BED_HEIGHT_HEADER_SHORT)); | 233 source.addMetaData("bedheight_header", msg(CSV_MEAN_BED_HEIGHT_HEADER_SHORT)); |
220 source.addMetaData("waterlevel_header", msg(SInfoI18NStrings.CSV_WATERLEVEL_HEADER)); | 234 source.addMetaData("waterlevel_header", msg(SInfoI18NStrings.CSV_WATERLEVEL_HEADER)); |
221 source.addMetaData("discharge_header", msg(SInfoI18NStrings.CSV_DISCHARGE_HEADER)); | 235 source.addMetaData("discharge_header", msg(SInfoI18NStrings.CSV_DISCHARGE_HEADER)); |
222 source.addMetaData("waterlevel_name_header", msg(SInfoI18NStrings.CSV_LABEL_HEADER)); | 236 |
237 // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also | |
238 // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates). | |
239 final String descriptionHeader = results.getDescriptionHeader(); | |
240 final String waterlevelNameHeader = descriptionHeader == null ? msg(SInfoI18NStrings.CSV_LABEL_HEADER) : descriptionHeader; | |
241 source.addMetaData("waterlevel_name_header", waterlevelNameHeader); | |
242 | |
223 source.addMetaData("gauge_header", msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); | 243 source.addMetaData("gauge_header", msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); |
224 source.addMetaData("location_header", msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); | 244 source.addMetaData("location_header", msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); |
225 } | 245 } |
226 | 246 |
227 @Override | 247 @Override |
228 protected final String[] formatPDFRow(final TkhResultRow row) { | 248 protected String[] formatPDFRow(final TkhCalculationResults results, final TkhResultRow row) { |
229 return formatRow(row); | 249 return formatRow(results, row, ExportMode.pdf); |
230 } | 250 } |
231 } | 251 } |