Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9398:929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
author | mschaefer |
---|---|
date | Mon, 13 Aug 2018 17:27:52 +0200 |
parents | f318359b81a2 |
children | 8562c60371b8 |
comparison
equal
deleted
inserted
replaced
9397:6e7094368e97 | 9398:929d645691ae |
---|---|
65 | 65 |
66 /** | 66 /** |
67 * Calculate the infrastructures flood duration result rows | 67 * Calculate the infrastructures flood duration result rows |
68 */ | 68 */ |
69 public void execute(final Calculation problems, final String label, final DoubleRange calcRange, final RiversideChoiceKey riverside, | 69 public void execute(final Calculation problems, final String label, final DoubleRange calcRange, final RiversideChoiceKey riverside, |
70 final WINFOArtifact winfo, final FloodDurationCalculationResults results) { | 70 final boolean withWspl, final WINFOArtifact winfo, final FloodDurationCalculationResults results) { |
71 | 71 |
72 // Find all gauges of the calc range, and create the duration finders | 72 // Find all gauges of the calc range, and create the duration finders |
73 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>(); | 73 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>(); |
74 Gauge firstGauge = null; | |
75 for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) { | 74 for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) { |
76 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems)); | 75 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems)); |
77 if (firstGauge == null) | |
78 firstGauge = gauge; | |
79 } | 76 } |
80 | 77 |
81 // Find all infrastructures within the calc range | 78 // Find all infrastructures within the calc range |
82 final AttributeKey bankKey = riverside.getAttributeKey(); | 79 final AttributeKey bankKey = riverside.getAttributeKey(); |
83 final List<InfrastructureValue> infras = InfrastructureValue.getValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), | 80 final List<InfrastructureValue> infras = InfrastructureValue.getValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), |
90 addGaugeLimits(allStations, durFinders.keySet(), calcRange.getMinimumDouble(), calcRange.getMaximumDouble()); | 87 addGaugeLimits(allStations, durFinders.keySet(), calcRange.getMinimumDouble(), calcRange.getMaximumDouble()); |
91 addInfrastructures(allStations, secondBank, infras); | 88 addInfrastructures(allStations, secondBank, infras); |
92 final double[] stationsSorted = sortStations(allStations.keySet()); | 89 final double[] stationsSorted = sortStations(allStations.keySet()); |
93 | 90 |
94 // Calculate W and Q for all stations and the selected discharge states/waterlevels | 91 // Calculate W and Q for all stations and the selected discharge states/waterlevels |
95 final WQKms[] wqkmsArray = calculateWsts(winfo, stationsSorted, problems); | 92 final WQKms[] wqkmsArray = calculateWsts(winfo, withWspl, stationsSorted, problems); |
96 | 93 |
97 // Determine discharge state labels of the waterlevels | 94 // Determine discharge state labels of the waterlevels |
98 updateWstLabels(wqkmsArray, winfo, problems); | 95 updateWstLabels(wqkmsArray, winfo, problems); |
99 | 96 |
100 final Map<Gauge, List<Double>> gaugeWstDurations = new HashMap<>(); | 97 final Map<Gauge, List<Double>> gaugeWstDurations = new HashMap<>(); |
101 calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders); | 98 if (withWspl) |
99 calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders); | |
102 | 100 |
103 // Load base wst table (river).wst | 101 // Load base wst table (river).wst |
104 // (should be in cache since already used in calculateWaterlevels (winfo.computeWaterlevelData) | 102 // (should be in cache since already used in calculateWaterlevels (winfo.computeWaterlevelData) |
105 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); | 103 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); |
106 | 104 |
107 // Create the result rows, and calculate and add the flood durations etc. | 105 // Create the result rows, and calculate and add the flood durations etc. |
108 for (int i = 0; i <= stationsSorted.length - 1; i++) { | 106 for (int i = 0; i <= stationsSorted.length - 1; i++) { |
109 final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true); | 107 final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true); |
110 final ResultRow row = createRow(stationsSorted[i], gauge, firstGauge, wqkmsArray, gaugeWstDurations.get(gauge), i); | 108 final ResultRow row = createRow(stationsSorted[i], wqkmsArray, gaugeWstDurations.get(gauge), i); |
111 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) | 109 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) |
112 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wst, durFinders); | 110 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wst, durFinders); |
113 this.rows.add(row); | 111 this.rows.add(row); |
114 if (secondBank.containsKey(stationsSorted[i])) { | 112 if (secondBank.containsKey(stationsSorted[i])) { |
115 final ResultRow row2 = ResultRow.create(row); | 113 final ResultRow row2 = ResultRow.create(row); |
212 } | 210 } |
213 return annotations; | 211 return annotations; |
214 } | 212 } |
215 | 213 |
216 /** | 214 /** |
217 * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result | 215 * Find and return the W or Q annotation(s) of a station and a riverside in a previously calculated result |
218 * collection | |
219 */ | 216 */ |
220 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, final AttributeKey riverside, | 217 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, final AttributeKey riverside, |
221 final boolean isW, final FloodDurationCalculationResult result) { | 218 final boolean isW, final FloodDurationCalculationResult result) { |
222 | 219 |
223 // Search the station in the previously calculated result rows and terminate if no infrastructure row found | 220 // Search the station in the previously calculated result rows and terminate if no infrastructure row found |
336 } | 333 } |
337 | 334 |
338 /** | 335 /** |
339 * Calculates an array of w-q-longitudinal sections for all artifact W/Q options | 336 * Calculates an array of w-q-longitudinal sections for all artifact W/Q options |
340 */ | 337 */ |
341 private WQKms[] calculateWsts(final WINFOArtifact winfo, final double[] stations, final Calculation problems) { | 338 private WQKms[] calculateWsts(final WINFOArtifact winfo, final boolean withWspl, final double[] stations, final Calculation problems) { |
342 // First run may take long, further runs are faster since WstValueTable is in cache then | 339 // First run may take long, further runs are faster since WstValueTable is in cache then |
343 // (So funktioniert computeWaterlevelData wohl: | 340 // (So funktioniert computeWaterlevelData wohl: |
344 // Es sucht die Spalte(n) zum Bezugspegel-Q in der W-Q-Tabelle ({river}.wst in Wst etc.), | 341 // Es sucht die Spalte(n) zum Bezugspegel-Q in der W-Q-Tabelle ({river}.wst in Wst etc.), |
345 // interpoliert die horizontale Tabellenposition (Q) und dann die vertikale Tabellenposition der station; | 342 // interpoliert die horizontale Tabellenposition (Q) und dann die vertikale Tabellenposition der station; |
346 // das ergibt das W einer station für einen Abflusszustand; | 343 // das ergibt das W einer station für einen Abflusszustand; |
347 // bei Vorgabe eines Pegel-W wird vorher anhand der W-Q-Tabelle des Pegels ({gauge}.at in DischargeTable) das Q | 344 // bei Vorgabe eines Pegel-W wird vorher anhand der W-Q-Tabelle des Pegels ({gauge}.at in DischargeTable) das Q |
348 // interpoliert; | 345 // interpoliert; |
349 // bei Vorgabe eines W auf freier Strecke wird wohl vorher noch die .wst-Interpolation eingesetzt, um das Q zu bekommen. | 346 // bei Vorgabe eines W auf freier Strecke wird wohl vorher noch die .wst-Interpolation eingesetzt, um das Q zu bekommen. |
347 | |
348 if (!withWspl) | |
349 return new WQKms[] {}; | |
350 | 350 |
351 final CalculationResult wstsData = winfo.computeWaterlevelData(stations); | 351 final CalculationResult wstsData = winfo.computeWaterlevelData(stations); |
352 | 352 |
353 /* copy all problems */ | 353 /* copy all problems */ |
354 final Calculation winfoProblems = wstsData.getReport(); | 354 final Calculation winfoProblems = wstsData.getReport(); |
408 } | 408 } |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 /** | 412 /** |
413 * Create a result row for a station and its gauge, and add w-q-values as selected | 413 * Create a result row for a station, and add w-q-values as selected |
414 */ | 414 */ |
415 private ResultRow createRow(final Double station, final Gauge gauge, final Gauge firstGauge, final WQKms[] wqkmsArray, final List<Double> gaugeDurations, | 415 private ResultRow createRow(final Double station, final WQKms[] wqkmsArray, final List<Double> gaugeDurations, final int kmIndex) { |
416 final int kmIndex) { | |
417 | 416 |
418 final ResultRow row = ResultRow.create(); | 417 final ResultRow row = ResultRow.create(); |
419 row.putValue(GeneralResultType.station, station); | 418 row.putValue(GeneralResultType.station, station); |
420 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure | 419 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure |
421 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure | 420 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure |
422 | 421 |
423 final String gaugeLabel = this.riverInfoProvider.findGauge(station, (gauge == firstGauge)); | 422 final String gaugeLabel = this.riverInfoProvider.findGauge(station); |
424 row.putValue(GeneralResultType.gaugeLabel, gaugeLabel); | 423 row.putValue(GeneralResultType.gaugeLabel, gaugeLabel); |
425 | 424 |
426 final String location = this.riverInfoProvider.getLocation(station); | 425 final String location = this.riverInfoProvider.getLocation(station); |
427 row.putValue(GeneralResultType.location, location); | 426 row.putValue(GeneralResultType.location, location); |
428 | 427 |