Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9176:1614cb14308f
Work on calculations for S-Info flood duration workflow
author | mschaefer |
---|---|
date | Mon, 25 Jun 2018 19:21:11 +0200 |
parents | 9b2e46090099 |
children | a4121ec450d6 |
comparison
equal
deleted
inserted
replaced
9175:34dc0163ad2d | 9176:1614cb14308f |
---|---|
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; | |
13 import java.util.ArrayList; | 12 import java.util.ArrayList; |
14 import java.util.Collection; | 13 import java.util.Collection; |
15 import java.util.List; | |
16 | 14 |
15 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | |
17 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 16 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
18 import org.dive4elements.river.artifacts.common.GeneralResultType; | 17 import org.dive4elements.river.artifacts.common.GeneralResultType; |
19 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | 18 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
20 import org.dive4elements.river.artifacts.common.ResultRow; | 19 import org.dive4elements.river.artifacts.common.ResultRow; |
21 import org.dive4elements.river.artifacts.sinfo.common.AbstractTkhCalculationResult; | |
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 20 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 21 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
24 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; | |
25 | 22 |
26 /** | 23 /** |
27 * Contains the results of a {@link FloodDurationCalculation}. | 24 * Contains the result of a {@link FloodDurationCalculation}. |
28 * | 25 * |
29 * @author Gernot Belger | 26 * @author Gernot Belger |
30 */ | 27 */ |
31 final class FloodDurationCalculationResult extends AbstractTkhCalculationResult<FloodDurationCalculationResults> { | 28 final class FloodDurationCalculationResult extends AbstractCalculationExportableResult<FloodDurationCalculationResults> { |
32 | 29 |
33 private static final long serialVersionUID = 1L; | 30 private static final long serialVersionUID = 1L; |
34 private final int waterlevelCount; // TODO: ggf 2 verschiedene Result-Klassen? | |
35 // private final WstInfo wstInfo; | |
36 private final int maxWaterlevelPdf = 3; | |
37 | 31 |
38 private enum ExportMode { | 32 private static final String JASPER_FILE = "/jasper/templates/sinfo.floodduration.jrxml"; |
39 pdf, csv | 33 |
34 | |
35 public FloodDurationCalculationResult(final String label, final Collection<ResultRow> rows) { | |
36 super(label, rows); | |
40 } | 37 } |
41 | 38 |
42 public FloodDurationCalculationResult(final String label, final WstInfo wstInfo, final Collection<ResultRow> rows, final boolean hasTkh, | 39 |
43 final int waterlevelCount) { | 40 @Override |
44 super(label, wstInfo, hasTkh, rows); | 41 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results) { |
45 this.waterlevelCount = waterlevelCount; | 42 // TODO Metadaten der Wasserspiegellage(n) falls gewählt |
46 // this.wstInfo = wstInfo; | 43 // exportContextCSV.writeCSVWaterlevelMetadata(this.wstInfo); |
44 // exportContextCSV.writeBlankLine(); | |
45 // writer.writeNext(new String[] { "" }); // break line | |
46 } | |
47 | |
48 @Override | |
49 protected String getJasperFile() { | |
50 // TODO Variante mit Wasserspiegellage(n) | |
51 return JASPER_FILE; | |
52 } | |
53 | |
54 protected String[] formatRow(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final ResultRow row) { | |
55 | |
56 final Collection<String> lines = new ArrayList<>(10); | |
57 | |
58 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | |
59 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); | |
60 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); | |
61 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); | |
62 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); | |
63 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); | |
64 | |
65 // TODO Wasserspiegellage(n) und Dauerzahlen falls gewählt | |
66 | |
67 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); | |
68 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); | |
69 | |
70 return lines.toArray(new String[lines.size()]); | |
47 } | 71 } |
48 | 72 |
49 @Override | 73 @Override |
50 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final RiverInfo river) { | 74 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final RiverInfo river) { |
51 | 75 |
52 final Collection<String> header = new ArrayList<>(99); | 76 final Collection<String> header = new ArrayList<>(20); |
53 | 77 |
54 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); | 78 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); |
55 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.riverside)); | 79 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.riverside)); |
56 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.inundationduration)); | 80 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); |
57 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.inundationdurationq)); | 81 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); |
58 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructureHeight)); | 82 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit())); |
59 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); | 83 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); |
60 | 84 |
61 // add dynamic headers | 85 // TODO Je vier Spalten der bis zu drei Wasserspiegellagen |
62 final int waterlevelCount = // results. | |
63 getWaterlevelCount(); | |
64 for (int i = 0; i < waterlevelCount; i++) { | |
65 final int naturalIndex = i + 1; | |
66 final String appendIndex = new StringBuilder().append("_").append(naturalIndex).toString(); | |
67 final Object[] args = new Object[] { appendIndex }; | |
68 // new StringBuilder().append('\u2081').toString(); // schlechter UTF-8-Support für subscript ints | |
69 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderW(), new Object[] { appendIndex, "results.getRiver().getWstUnit()" })); | |
70 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderFloodDurPerYear(), args)); | |
71 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderQ(), args)); | |
72 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderBezeichn(), args)); | |
73 } | |
74 | 86 |
75 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); | 87 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); |
76 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); | 88 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); |
77 | 89 |
78 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); | 90 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); |
79 } | |
80 | |
81 @Override | |
82 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results) { | |
83 | |
84 exportContextCSV.writeCSVWaterlevelMetadata(super.getWst()); // -> export in super? -> TODO | |
85 exportContextCSV.writeBlankLine(); | |
86 // writer.writeNext(new String[] { "" }); // break line | |
87 | 91 |
88 } | 92 } |
89 | 93 |
90 @Override | 94 @Override |
91 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final ResultRow row) { | 95 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final ResultRow row) { |
92 // TODO Auto-generated method stub | 96 |
93 return formatRow(exportContextCSV, results, row, ExportMode.csv); | 97 return this.formatRow(exportContextCSV, results, row); |
94 } | 98 } |
95 | 99 |
96 @Override | 100 @Override |
97 protected String[] formatPDFRow(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final ResultRow row) { | 101 protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final FloodDurationCalculationResults results, final ResultRow row) { |
98 | 102 |
99 return formatRow(exportContextCSV, results, row, ExportMode.pdf); | 103 return this.formatRow(exportContextPDF, results, row); |
100 } | 104 } |
101 | 105 |
102 @Override | 106 @Override |
103 protected String getJasperFile() { | 107 protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source, |
104 if (this.waterlevelCount <= 1) | 108 final FloodDurationCalculationResults results) { |
105 return "/jasper/templates/sinfo.floodduration.jrxml"; // TODO 2 different result-classes? | |
106 else | |
107 return "/jasper/templates/sinfo.floodduration2.jrxml"; | |
108 } | |
109 | 109 |
110 @Override | |
111 protected void addJRTableHeader(final ExportContextCSV exportContextCSV, final MetaAndTableJRDataSource source, | |
112 final FloodDurationCalculationResults results) { | |
113 /* column headings */ | 110 /* column headings */ |
114 exportContextCSV.addJRMetadata(source, "station_header", GeneralResultType.station); | 111 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station); |
115 exportContextCSV.addJRMetadata(source, "riverside_header", SInfoResultType.riverside); | 112 exportContextPDF.addJRMetadata(source, "riverside_header", SInfoResultType.riverside); |
116 exportContextCSV.addJRMetadata(source, "inundationduration_header", SInfoResultType.inundationduration); | 113 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); |
117 exportContextCSV.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.inundationdurationq); | 114 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); |
118 exportContextCSV.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeightFloodDur); | 115 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeightFloodDur); |
119 exportContextCSV.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); | 116 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); |
120 | 117 |
121 // add dynamic headers | 118 // TODO Je vier Spalten der bis zu drei Wasserspiegellagen |
122 | 119 |
123 if (this.waterlevelCount == 0 || this.waterlevelCount == 2) { | 120 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); |
124 source.addMetaData("dummy", "dummy"); | 121 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); |
125 source.addMetaData("dummy", "dummy"); | |
126 source.addMetaData("dummy", "dummy"); | |
127 source.addMetaData("dummy", "dummy"); | |
128 } | |
129 | |
130 for (int i = 0; i < this.waterlevelCount; i++) { | |
131 final int naturalIndex = i + 1; | |
132 | |
133 final Object[] args = new String[] { new StringBuilder().append("_").append(naturalIndex).toString() }; | |
134 exportContextCSV.addJRMetadata(source, getPdfHeader("w", naturalIndex), exportContextCSV.msg(DurationWaterlevel.getHeaderW(), args)); | |
135 exportContextCSV.addJRMetadata(source, getPdfHeader("duration", naturalIndex), | |
136 exportContextCSV.msg(DurationWaterlevel.getHeaderFloodDurPerYear(), args)); | |
137 exportContextCSV.addJRMetadata(source, getPdfHeader("q", naturalIndex), exportContextCSV.msg(DurationWaterlevel.getHeaderQ(), args)); | |
138 exportContextCSV.addJRMetadata(source, getPdfHeader("bezeichnung", naturalIndex), | |
139 exportContextCSV.msg(DurationWaterlevel.getHeaderBezeichn(), args)); | |
140 | |
141 } | |
142 | |
143 exportContextCSV.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); | |
144 exportContextCSV.addJRMetadata(source, "location_header", SInfoResultType.location); | |
145 | |
146 } | |
147 | |
148 public int getWaterlevelCount() { // der exporter muss daran, um spalten auszublenden | |
149 return this.waterlevelCount; | |
150 } | |
151 | |
152 private String[] formatRow(final ExportContextCSV exportContextCSV, final FloodDurationCalculationResults results, final ResultRow row, | |
153 final ExportMode mode) { | |
154 | |
155 final Collection<String> lines = new ArrayList<>(99); | |
156 | |
157 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | |
158 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); | |
159 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.inundationduration)); | |
160 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.inundationdurationq)); | |
161 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); | |
162 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); | |
163 | |
164 final List<DurationWaterlevel> waterlevelList = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); | |
165 if (waterlevelList != null) { | |
166 final NumberFormat wFormatter = exportContextCSV.getFlowDepthFormatter(); | |
167 final NumberFormat qFormatter = exportContextCSV.getQFormatter(); | |
168 | |
169 for (int i = 0; i < waterlevelList.size(); i++) { | |
170 | |
171 if (i == this.maxWaterlevelPdf && mode == ExportMode.pdf) | |
172 break; | |
173 | |
174 final DurationWaterlevel item = waterlevelList.get(i); | |
175 lines.add(item.getWFormatted(wFormatter)); | |
176 lines.add(item.getFloodDurDaysPerYearFormatted()); | |
177 lines.add(item.getQFormatted(qFormatter)); | |
178 lines.add(item.getBezeichnung()); | |
179 } | |
180 } | |
181 | |
182 if ((this.waterlevelCount == 0 || this.waterlevelCount == 2) && mode == ExportMode.pdf) { | |
183 lines.add("dummy"); | |
184 lines.add("dummy"); | |
185 lines.add("dummy"); | |
186 lines.add("dummy"); | |
187 } | |
188 | |
189 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); | |
190 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); | |
191 return lines.toArray(new String[lines.size()]); | |
192 } | |
193 | |
194 private String getPdfHeader(final String rootStr, final int index) { | |
195 final String hd = "_header"; | |
196 final StringBuilder builder = new StringBuilder(); | |
197 return builder.append(rootStr).append("_").append(index).append(hd).toString(); | |
198 } | 122 } |
199 } | 123 } |