Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9205:3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
author | gernotbelger |
---|---|
date | Mon, 02 Jul 2018 19:01:09 +0200 |
parents | b4402594213b |
children | 53cc5b496692 |
comparison
equal
deleted
inserted
replaced
9204:4f411c6ee3ae | 9205:3dae6b78e1da |
---|---|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
8 * documentation coming with Dive4Elements River for details. | 8 * documentation coming with Dive4Elements River for details. |
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | 10 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
11 | 11 |
12 import java.text.NumberFormat; | |
12 import java.util.ArrayList; | 13 import java.util.ArrayList; |
13 import java.util.Collection; | 14 import java.util.Collection; |
14 import java.util.Collections; | 15 import java.util.Collections; |
15 import java.util.List; | 16 import java.util.List; |
16 | 17 |
17 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | 18 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
19 import org.dive4elements.river.artifacts.common.AbstractExportContext; | |
18 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 20 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
19 import org.dive4elements.river.artifacts.common.ExportContextPDF; | 21 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
20 import org.dive4elements.river.artifacts.common.GeneralResultType; | 22 import org.dive4elements.river.artifacts.common.GeneralResultType; |
21 import org.dive4elements.river.artifacts.common.IExportContext; | |
22 import org.dive4elements.river.artifacts.common.IResultType; | 23 import org.dive4elements.river.artifacts.common.IResultType; |
23 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | 24 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
24 import org.dive4elements.river.artifacts.common.ResultRow; | 25 import org.dive4elements.river.artifacts.common.ResultRow; |
25 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings; | 26 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings; |
26 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 27 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
35 */ | 36 */ |
36 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { | 37 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { |
37 | 38 |
38 private static final long serialVersionUID = 1L; | 39 private static final long serialVersionUID = 1L; |
39 | 40 |
40 private static final String JASPER_FILE = "/jasper/templates/sinfo.floodduration.jrxml"; | |
41 | |
42 private final String[] mainvalueLabels; | 41 private final String[] mainvalueLabels; |
42 | |
43 private final int waterlevelCount; | |
44 // private final WstInfo wstInfo; | |
45 private final int maxWaterlevelPdf = 3; | |
46 | |
47 private enum ExportMode { | |
48 pdf, csv | |
49 } | |
43 | 50 |
44 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows) { | 51 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows) { |
45 super(label, rows); | 52 super(label, rows); |
46 this.mainvalueLabels = mainvalueLabels; | 53 this.mainvalueLabels = mainvalueLabels; // TODO: löschen (?) |
54 this.waterlevelCount = mainvalueLabels.length; | |
47 } | 55 } |
48 | 56 |
49 /** | 57 /** |
50 * The label of one of the optional main values, or null | 58 * The label of one of the optional main values, or null |
51 */ | 59 */ |
52 public String getMainValueLabel(final int index) { | 60 // public String getMainValueLabel(final int index) { |
53 if (index <= this.mainvalueLabels.length - 1) | 61 // if (index <= this.mainvalueLabels.length - 1) |
54 return this.mainvalueLabels[index]; | 62 // return this.mainvalueLabels[index]; |
55 else | 63 // else |
56 return null; | 64 // return null; |
57 } | 65 // } |
58 | 66 |
59 /** | 67 /** |
60 * Collection of the result rows containing only the rows describing an infrastructure | 68 * Collection of the result rows containing only the rows describing an infrastructure |
61 */ | 69 */ |
62 @Override | 70 @Override |
103 @Override | 111 @Override |
104 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { | 112 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
105 if (this.mainvalueLabels.length >= 1) { | 113 if (this.mainvalueLabels.length >= 1) { |
106 // "##METADATEN WASSERSPIEGELLAGE" | 114 // "##METADATEN WASSERSPIEGELLAGE" |
107 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL); | 115 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL); |
108 for (int i = 1; i <= this.mainvalueLabels.length; i++) { | 116 for (int i = 1; i <= getWaterlevelCount(); // this.mainvalueLabels.length; |
117 i++) { | |
109 // "# Bezeichnung der Wasserspiegellage: " | 118 // "# Bezeichnung der Wasserspiegellage: " |
110 final String label = this.getMainValueLabel(i - 1); | 119 final String label = this.getMainValueLabel(i - 1); |
111 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label)); | 120 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label)); |
112 } | 121 } |
113 // "# Bezugspegel: " | 122 // "# Bezugspegel: " |
114 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, "TODO: gauge"); | 123 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, "TODO: gauge"); |
115 } | 124 } |
125 exportContextCSV.writeBlankLine(); | |
116 } | 126 } |
117 | 127 |
118 @Override | 128 @Override |
119 protected String getJasperFile() { | 129 protected String getJasperFile() { |
120 // TODO Variante mit Wasserspiegellage(n) | 130 if (this.waterlevelCount <= 1) |
121 return JASPER_FILE; | 131 return "/jasper/templates/sinfo.floodduration.jrxml"; |
122 } | 132 else |
123 | 133 return "/jasper/templates/sinfo.floodduration2.jrxml"; |
124 protected String[] formatRow(final IExportContext exportContextCSV, final ResultRow row) { | 134 } |
135 | |
136 protected String[] formatRow(final AbstractExportContext exportContextCSV, final ResultRow row, final ExportMode mode) { | |
125 | 137 |
126 final Collection<String> lines = new ArrayList<>(10); | 138 final Collection<String> lines = new ArrayList<>(10); |
127 | 139 |
128 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | 140 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); |
129 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); | 141 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); |
130 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); | 142 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); |
131 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); | 143 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); |
132 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); | 144 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); |
133 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); | 145 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); |
134 | 146 |
135 if (this.getMainValueLabel(0) != null) { | 147 final List<DurationWaterlevel> waterlevelList = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); |
136 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel1)); | 148 if (waterlevelList != null) { |
137 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue1Duration)); | 149 final NumberFormat wFormatter = exportContextCSV.getFlowDepthFormatter(); |
138 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge1)); | 150 final NumberFormat qFormatter = exportContextCSV.getQFormatter(); |
139 if (this.getMainValueLabel(1) != null) { | 151 |
140 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel2)); | 152 for (int i = 0; i < waterlevelList.size(); i++) { |
141 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue2Duration)); | 153 |
142 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge2)); | 154 if (i == this.maxWaterlevelPdf && mode == ExportMode.pdf) |
143 if (this.getMainValueLabel(2) != null) { | 155 break; |
144 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel3)); | 156 |
145 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue3Duration)); | 157 final DurationWaterlevel item = waterlevelList.get(i); |
146 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge3)); | 158 lines.add(item.getWFormatted(wFormatter)); |
147 } | 159 lines.add(item.getFloodDurDaysPerYearFormatted()); |
160 lines.add(item.getQFormatted(qFormatter)); | |
161 lines.add(item.getBezeichnung()); | |
148 } | 162 } |
163 } | |
164 | |
165 if ((this.waterlevelCount == 0 || this.waterlevelCount == 2) && mode == ExportMode.pdf) { | |
166 // lines.add("dummy1"); | |
167 // lines.add("dummy2"); | |
168 // lines.add("dummy3"); | |
169 // lines.add("dummy4"); | |
149 } | 170 } |
150 | 171 |
151 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); | 172 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); |
152 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); | 173 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); |
153 | 174 |
164 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); | 185 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); |
165 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); | 186 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); |
166 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit())); | 187 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit())); |
167 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); | 188 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); |
168 | 189 |
169 if (this.getMainValueLabel(0) != null) { | 190 // add dynamic headers |
170 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel1, SInfoResultType.waterlevel.getUnit())); | 191 final int waterlevelCount = // results. |
171 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue1Duration)); | 192 getWaterlevelCount(); |
172 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge1, SInfoResultType.discharge.getUnit())); | 193 for (int i = 0; i < waterlevelCount; i++) { |
173 if (this.getMainValueLabel(1) != null) { | 194 final int naturalIndex = i + 1; |
174 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel2, SInfoResultType.waterlevel2.getUnit())); | 195 final String appendIndex = new StringBuilder().append("_").append(naturalIndex).toString(); |
175 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue2Duration)); | 196 final Object[] args = new Object[] { appendIndex }; |
176 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge2, SInfoResultType.discharge2.getUnit())); | 197 // new StringBuilder().append('\u2081').toString(); // schlechter UTF-8-Support für subscript ints |
177 if (this.getMainValueLabel(2) != null) { | 198 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderW(), new Object[] { appendIndex, "results.getRiver().getWstUnit()" })); |
178 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel3, SInfoResultType.waterlevel3.getUnit())); | 199 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderFloodDurPerYear(), args)); |
179 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue3Duration)); | 200 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderQ(), args)); |
180 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge3, SInfoResultType.discharge3.getUnit())); | 201 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderBezeichn(), args)); |
181 } | |
182 } | |
183 } | 202 } |
184 | 203 |
185 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); | 204 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); |
186 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); | 205 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); |
187 | 206 |
190 } | 209 } |
191 | 210 |
192 @Override | 211 @Override |
193 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { | 212 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
194 | 213 |
195 return this.formatRow(exportContextCSV, row); | 214 return this.formatRow(exportContextCSV, row, ExportMode.csv); |
196 } | 215 } |
197 | 216 |
198 @Override | 217 @Override |
199 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) { | 218 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) { |
200 | 219 |
201 return this.formatRow(exportContextPDF, row); | 220 return this.formatRow(exportContextPDF, row, ExportMode.pdf); |
202 } | 221 } |
203 | 222 |
204 @Override | 223 @Override |
205 protected void addJRTableHeader(final ExportContextPDF exportContextPDF, final MetaAndTableJRDataSource source) { | 224 protected void addJRTableHeader(final ExportContextPDF exportContextPDF, final MetaAndTableJRDataSource source) { |
206 | 225 |
210 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); | 229 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); |
211 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); | 230 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); |
212 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); | 231 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); |
213 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); | 232 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); |
214 | 233 |
215 // TODO Feldnamen ergaenzen und aktivieren wenn Report fertig | 234 // add dynamic headers |
216 // if (this.getMainValueLabel(0) != null) { | 235 |
217 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel); | 236 if (this.waterlevelCount == 0 || this.waterlevelCount == 2) { |
218 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue1Duration); | 237 // source.addMetaData("dummy1", "dummy1"); |
219 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge); | 238 // source.addMetaData("dummy2", "dummy2"); |
220 // if (this.getMainValueLabel(1) != null) { | 239 // source.addMetaData("dummy3", "dummy3"); |
221 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel2); | 240 // source.addMetaData("dummy4", "dummy4"); |
222 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue2Duration); | 241 } |
223 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge2); | 242 |
224 // if (this.getMainValueLabel(2) != null) { | 243 for (int i = 0; i < this.waterlevelCount; i++) { |
225 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel3); | 244 final int naturalIndex = i + 1; |
226 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue3Duration); | 245 |
227 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge3); | 246 final Object[] args = new String[] { new StringBuilder().append("_").append(naturalIndex).toString() }; |
228 // } | 247 exportContextPDF.addJRMetadata(source, getPdfHeader("w", naturalIndex), exportContextPDF.msg(DurationWaterlevel.getHeaderW(), args)); |
229 // } | 248 exportContextPDF.addJRMetadata(source, getPdfHeader("duration", naturalIndex), |
230 // } | 249 exportContextPDF.msg(DurationWaterlevel.getHeaderFloodDurPerYear(), args)); |
250 exportContextPDF.addJRMetadata(source, getPdfHeader("q", naturalIndex), exportContextPDF.msg(DurationWaterlevel.getHeaderQ(), args)); | |
251 exportContextPDF.addJRMetadata(source, getPdfHeader("bezeichnung", naturalIndex), | |
252 exportContextPDF.msg(DurationWaterlevel.getHeaderBezeichn(), args)); | |
253 } | |
231 | 254 |
232 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); | 255 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); |
233 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); | 256 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); |
234 } | 257 } |
258 | |
259 public final int getWaterlevelCount() { | |
260 return this.waterlevelCount; | |
261 } | |
262 | |
263 private final String getPdfHeader(final String rootStr, final int index) { | |
264 final String hd = "_header"; | |
265 final StringBuilder builder = new StringBuilder(); | |
266 return builder.append(rootStr).append("_").append(index).append(hd).toString(); | |
267 } | |
268 | |
269 public String getMainValueLabel(final int j) { | |
270 | |
271 if (this.mainvalueLabels != null && j < this.mainvalueLabels.length) | |
272 return this.mainvalueLabels[j]; | |
273 return ""; | |
274 } | |
235 } | 275 } |