Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9205:3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
author | gernotbelger |
---|---|
date | Mon, 02 Jul 2018 19:01:09 +0200 |
parents | b4402594213b |
children | 0fc9c82e744e |
comparison
equal
deleted
inserted
replaced
9204:4f411c6ee3ae | 9205:3dae6b78e1da |
---|---|
30 import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder; | 30 import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder; |
31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; | 31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; |
32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
33 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder; | 33 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder; |
34 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; | 34 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; |
35 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder; | |
35 import org.dive4elements.river.model.Attribute.AttributeKey; | 36 import org.dive4elements.river.model.Attribute.AttributeKey; |
36 import org.dive4elements.river.model.Gauge; | 37 import org.dive4elements.river.model.Gauge; |
37 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; | 38 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; |
38 import org.dive4elements.river.model.sinfo.InfrastructureValue; | 39 import org.dive4elements.river.model.sinfo.InfrastructureValue; |
39 | 40 |
51 | 52 |
52 private final RiverInfoProvider riverInfoProvider; | 53 private final RiverInfoProvider riverInfoProvider; |
53 | 54 |
54 private final CallContext context; | 55 private final CallContext context; |
55 | 56 |
56 | |
57 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { | 57 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { |
58 this.context = context; | 58 this.context = context; |
59 this.riverInfoProvider = riverInfoProvider; | 59 this.riverInfoProvider = riverInfoProvider; |
60 } | 60 } |
61 | 61 |
95 | 95 |
96 // Create a finder for Q in the {river}.wst km-w-q table | 96 // Create a finder for Q in the {river}.wst km-w-q table |
97 final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), | 97 final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), |
98 calcRange.getMaximumDouble(), problems); | 98 calcRange.getMaximumDouble(), problems); |
99 | 99 |
100 final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context); | |
101 | |
100 // Calculate the durations and create the result rows | 102 // Calculate the durations and create the result rows |
101 for (int i = 0; i <= stationsSorted.length - 1; i++) { | 103 for (int i = 0; i <= stationsSorted.length - 1; i++) { |
102 final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true); | 104 final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true); |
103 final ResultRow row = createRow(stationsSorted[i], gauge, wqkmsArray, durFinders.get(gauge), i); | 105 final ResultRow row = createRow(descBuilder, stationsSorted[i], gauge, wqkmsArray, durFinders.get(gauge), i); |
104 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) | 106 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) |
105 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wqFinder, durFinders); | 107 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wqFinder, durFinders); |
106 this.rows.add(row); | 108 this.rows.add(row); |
107 if (secondBank.containsKey(stationsSorted[i])) { | 109 if (secondBank.containsKey(stationsSorted[i])) { |
108 final ResultRow row2 = ResultRow.create(row); | 110 final ResultRow row2 = ResultRow.create(row); |
188 } | 190 } |
189 | 191 |
190 /** | 192 /** |
191 * Determines the discharge state labels for the selected Q or W values | 193 * Determines the discharge state labels for the selected Q or W values |
192 */ | 194 */ |
195 // FIXME: use WaterlevelDescriptionBuilder instead! | |
193 private String[] findMainValueLabels(final WQKms[] wqkmsArray, final double[] qs, final Gauge gauge, final Calculation problems) { | 196 private String[] findMainValueLabels(final WQKms[] wqkmsArray, final double[] qs, final Gauge gauge, final Calculation problems) { |
197 | |
194 final String[] mainValueLabels = new String[wqkmsArray.length]; | 198 final String[] mainValueLabels = new String[wqkmsArray.length]; |
195 if (wqkmsArray.length >= 1) { | 199 if (wqkmsArray.length >= 1) { |
196 // Labels like Q=123 or W=123 | 200 // Labels like Q=123 or W=123 |
197 for (int i = 0; i <= wqkmsArray.length - 1; i++) | 201 for (int i = 0; i <= wqkmsArray.length - 1; i++) |
198 mainValueLabels[i] = wqkmsArray[i].getName(); | 202 mainValueLabels[i] = wqkmsArray[i].getName(); |
206 return mainValueLabels; | 210 return mainValueLabels; |
207 } | 211 } |
208 | 212 |
209 /** | 213 /** |
210 * Create a result row for a station and its gauge, and add w-q-values as selected | 214 * Create a result row for a station and its gauge, and add w-q-values as selected |
211 */ | 215 * |
212 private ResultRow createRow(final Double station, final Gauge gauge, final WQKms[] wqkmsArray, | 216 * @param descBuilder |
217 */ | |
218 private ResultRow createRow(final WaterlevelDescriptionBuilder descBuilder, final Double station, final Gauge gauge, final WQKms[] wqkmsArray, | |
213 final GaugeDurationValuesFinder durationFinder, final int kmIndex) { | 219 final GaugeDurationValuesFinder durationFinder, final int kmIndex) { |
214 | 220 |
215 final ResultRow row = ResultRow.create(); | 221 final ResultRow row = ResultRow.create(); |
216 row.putValue(GeneralResultType.station, station); | 222 row.putValue(GeneralResultType.station, station); |
217 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure | 223 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure |
218 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure | 224 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure |
219 row.putValue(SInfoResultType.gaugeLabel, gauge.getName()); | 225 |
226 // row.putValue(SInfoResultType.gaugeLabel, gauge.getName()); | |
227 final String gaugeLabel = this.riverInfoProvider.findGauge(station); | |
228 row.putValue(SInfoResultType.gaugeLabel, gaugeLabel); | |
229 | |
220 final String location = this.riverInfoProvider.getLocation(station); | 230 final String location = this.riverInfoProvider.getLocation(station); |
221 row.putValue(SInfoResultType.location, location); | 231 row.putValue(SInfoResultType.location, location); |
222 | 232 |
223 if (wqkmsArray.length >= 1) { | 233 final List<DurationWaterlevel> waterlevels = new ArrayList<>(wqkmsArray.length); |
224 assert (wqkmsArray[0].getKm(kmIndex) == station.doubleValue()); | 234 |
225 row.putValue(SInfoResultType.waterlevel1, wqkmsArray[0].getW(kmIndex)); | 235 for (final WQKms wqKm : wqkmsArray) { |
226 row.putValue(SInfoResultType.discharge1, wqkmsArray[0].getQ(kmIndex)); | 236 assert (wqKm.getKm(kmIndex) == station.doubleValue()); |
227 row.putValue(SInfoResultType.mainValue1Duration, underflowDaysToOverflowDays(durationFinder.getDuration(wqkmsArray[0].getQ(kmIndex)))); | 237 |
228 if (wqkmsArray.length >= 2) { | 238 final int overflowDays = (int) Math.round(underflowDaysToOverflowDays(durationFinder.getDuration(wqKm.getQ(kmIndex)))); |
229 assert (wqkmsArray[1].getKm(kmIndex) == station.doubleValue()); | 239 |
230 row.putValue(SInfoResultType.waterlevel2, wqkmsArray[1].getW(kmIndex)); | 240 final String waterlevelLabel = descBuilder.getDesc(wqKm); |
231 row.putValue(SInfoResultType.discharge2, wqkmsArray[1].getQ(kmIndex)); | 241 |
232 row.putValue(SInfoResultType.mainValue2Duration, underflowDaysToOverflowDays(durationFinder.getDuration(wqkmsArray[1].getQ(kmIndex)))); | 242 final DurationWaterlevel dw = new DurationWaterlevel(wqKm.getW(kmIndex), overflowDays, wqKm.getQ(kmIndex), waterlevelLabel); |
233 if (wqkmsArray.length >= 3) { | 243 waterlevels.add(dw); |
234 assert (wqkmsArray[2].getKm(kmIndex) == station.doubleValue()); | 244 } |
235 row.putValue(SInfoResultType.waterlevel3, wqkmsArray[2].getW(kmIndex)); | 245 row.putValue(SInfoResultType.customMultiRowColWaterlevel, waterlevels); |
236 row.putValue(SInfoResultType.discharge3, wqkmsArray[2].getQ(kmIndex)); | 246 |
237 row.putValue(SInfoResultType.mainValue3Duration, underflowDaysToOverflowDays(durationFinder.getDuration(wqkmsArray[2].getQ(kmIndex)))); | |
238 } | |
239 } | |
240 } | |
241 return row; | 247 return row; |
242 } | 248 } |
243 | 249 |
244 /** | 250 /** |
245 * Calculate the result row fields for one infrastructure | 251 * Calculate the result row fields for one infrastructure |
246 */ | 252 */ |
247 private void calculateInfrastructure(final ResultRow row, final Gauge gauge, final InfrastructureValue infrastructure, | 253 private void calculateInfrastructure(final ResultRow row, final Gauge gauge, final InfrastructureValue infrastructure, final WQBaseTableFinder wqFinder, |
248 final WQBaseTableFinder wqFinder, final Map<Gauge, GaugeDurationValuesFinder> durFinders) { | 254 final Map<Gauge, GaugeDurationValuesFinder> durFinders) { |
249 | 255 |
250 final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight()); | 256 final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight()); |
251 final double qOut = Double.isInfinite(q) ? Double.NaN : q; | 257 final double qOut = Double.isInfinite(q) ? Double.NaN : q; |
252 final double dur = underflowDaysToOverflowDays(durFinders.get(gauge).getDuration(q)); | 258 final double dur = underflowDaysToOverflowDays(durFinders.get(gauge).getDuration(q)); |
253 row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey().getName()); // TODO i18n | 259 row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey().getName()); // TODO i18n |