annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9594:225e48df608c

Softwaretests...20181219 6.1: overflow day compute with 365.25 instead of 365.0
author mschaefer
date Tue, 05 Feb 2019 15:24:22 +0100
parents b380a5693514
children f8308db94634
rev   line source
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
2 * Software engineering by
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
5 *
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
9 */
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.sinfo.flood_duration;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
11
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
12 import java.util.ArrayList;
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
13 import java.util.Collection;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
14 import java.util.HashMap;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
15 import java.util.List;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
16 import java.util.Map;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
17 import java.util.Set;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
18
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
19 import org.apache.commons.lang.math.DoubleRange;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
20 import org.dive4elements.artifacts.CallContext;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
21 import org.dive4elements.river.artifacts.WINFOArtifact;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
22 import org.dive4elements.river.artifacts.access.ComputationRangeAccess;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.artifacts.common.GeneralResultType;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.artifacts.common.ResultRow;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
25 import org.dive4elements.river.artifacts.model.Calculation;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
26 import org.dive4elements.river.artifacts.model.Calculation.Problem;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
27 import org.dive4elements.river.artifacts.model.CalculationResult;
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
28 import org.dive4elements.river.artifacts.model.WQDay;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
29 import org.dive4elements.river.artifacts.model.WQKms;
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
30 import org.dive4elements.river.artifacts.model.WstValueTable;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
31 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
32 import org.dive4elements.river.artifacts.model.WstValueTableFactory;
9499
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents: 9492
diff changeset
33 import org.dive4elements.river.artifacts.model.river.RiverInfoProvider;
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
34 import org.dive4elements.river.artifacts.resources.Resources;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
35 import org.dive4elements.river.artifacts.sinfo.common.GaugeDurationValuesFinder;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
36 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
37 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey;
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
38 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder;
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
39 import org.dive4elements.river.jfree.StickyAxisAnnotation;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
40 import org.dive4elements.river.jfree.StickyAxisAnnotation.SimpleAxis;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
41 import org.dive4elements.river.model.Attribute.AttributeKey;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
42 import org.dive4elements.river.model.Gauge;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
43 import org.dive4elements.river.model.sinfo.InfrastructureValue;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
44
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
45 import gnu.trove.TDoubleArrayList;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
46
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
47 /**
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
48 * Calculation of the result rows of the flood duration of the infrastructures in a river km range
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
49 * and selected main value durations
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
50 *
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
51 * @author Matthias Schäfer
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
52 */
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
53 final class FloodDurationCalculator {
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
54
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
55 private final List<ResultRow> rows = new ArrayList<>();
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
56
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
57 private final RiverInfoProvider riverInfoProvider;
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
58 private RiverInfoProvider riverInfoProvider2;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
59
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
60 private final CallContext context;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
61
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
62 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
63 this.context = context;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
64 this.riverInfoProvider = riverInfoProvider;
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
65 this.riverInfoProvider2 = null;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
66 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
67
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
68 /**
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
69 * Calculate the infrastructures flood duration result rows
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
70 */
9492
10530f1d7dd5 Meilenstein-2-Rücklauf Punkt 2.2.4 Angabe des Bezugspegels
gernotbelger
parents: 9489
diff changeset
71 public void execute(final Calculation problems, final String label, final DoubleRange calcRange, final RiversideChoiceKey riverside, final boolean withWspl,
10530f1d7dd5 Meilenstein-2-Rücklauf Punkt 2.2.4 Angabe des Bezugspegels
gernotbelger
parents: 9489
diff changeset
72 final WINFOArtifact winfo, final FloodDurationCalculationResults results) {
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
73
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
74 // Find all gauges of the calc range, and create the duration finders
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
75 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>();
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
76 for (final Gauge gauge : this.riverInfoProvider.getGauges()) {
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
77 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
78 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
79
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
80 // Find all infrastructures within the calc range
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
81 final AttributeKey bankKey = riverside.getAttributeKey();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
82 final List<InfrastructureValue> infras = InfrastructureValue.getValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(),
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
83 calcRange.getMaximumDouble(), bankKey);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
84
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
85 // Merge all stations (range/step, borders of gauge ranges, infrastructures)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
86 final Map<Double, InfrastructureValue> allStations = new HashMap<>();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
87 final Map<Double, InfrastructureValue> secondBank = new HashMap<>(); // any second infrastructure in case of both-banks-option
9236
b515ed950d39 S-Info flood durations with automatic km step width
mschaefer
parents: 9235
diff changeset
88 addRangeStations(allStations, winfo);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
89 addGaugeLimits(allStations, durFinders.keySet(), calcRange.getMinimumDouble(), calcRange.getMaximumDouble());
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
90 addInfrastructures(allStations, secondBank, infras);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
91 final double[] stationsSorted = sortStations(allStations.keySet());
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
92
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
93 // Calculate W and Q for all stations and the selected discharge states/waterlevels
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
94 final WQKms[] wqkmsArray = calculateWsts(winfo, withWspl, stationsSorted, problems);
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
95 // final WaterlevelData waterlevel = new WaterlevelData(wqkmsArray[0], -1, false, true);
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
96 // this.riverInfoProvider2 = this.riverInfoProvider.forWaterlevel(waterlevel);
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
97 this.riverInfoProvider2 = this.riverInfoProvider.forReferenceRange(calcRange, false);
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
98 // this.riverInfoProvider2.cleanupGaugesAtStart(calcRange);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
99
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
100 // Determine discharge state labels of the waterlevels
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
101 updateWstLabels(wqkmsArray, winfo, problems);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
102
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
103 final Map<Gauge, List<Double>> gaugeWstDurations = new HashMap<>();
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
104 if (withWspl)
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
105 calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders);
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
106
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
107 // Load base wst table (river).wst
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
108 // (should be in cache since already used in calculateWaterlevels (winfo.computeWaterlevelData)
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
109 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider2.getRiver());
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
110
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
111 // Create the result rows, and calculate and add the flood durations etc.
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
112 for (int i = 0; i <= stationsSorted.length - 1; i++) {
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
113 final Gauge gauge = this.riverInfoProvider2.getGauge(stationsSorted[i], true);
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
114 final ResultRow row = createRow(stationsSorted[i], wqkmsArray, gaugeWstDurations.get(gauge), i);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
115 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null))
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
116 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wst, durFinders);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
117 this.rows.add(row);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
118 if (secondBank.containsKey(stationsSorted[i])) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
119 final ResultRow row2 = ResultRow.create(row);
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
120 calculateInfrastructure(row2, gauge, secondBank.get(stationsSorted[i]), wst, durFinders);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
121 this.rows.add(row2);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
122 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
123 }
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
124
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
125 // Get the labels of the selected waterlevels
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
126 final String[] wstLabels = new String[wqkmsArray.length];
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
127 for (int i = 0; i <= wqkmsArray.length - 1; i++)
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
128 wstLabels[i] = wqkmsArray[i].getName();
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
129
9492
10530f1d7dd5 Meilenstein-2-Rücklauf Punkt 2.2.4 Angabe des Bezugspegels
gernotbelger
parents: 9489
diff changeset
130 results.addResult(new FloodDurationCalculationResult(label, wstLabels, this.rows, withWspl), problems);
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
131 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
132
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
133 /**
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
134 * Calculates the duration curve for a station
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
135 * (other than the version 3.2.1 W-Info Dauerlinie the wst column positions
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
136 * are taken from the Q values of the gauge's Q-D-table)
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
137 */
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
138 public WQDay calcWQDays(final Calculation problems, final double station, final WINFOArtifact winfo) {
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
139
9534
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
140 final CalculationResult res = winfo.getDurationCurveData();
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
141 final WQDay wqday = (WQDay) res.getData();
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
142 if (wqday == null)
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
143 return null;
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
144
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
145 final int[] odays = new int[wqday.size()];
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
146 for (int i = 0; i <= odays.length - 1; i++)
9594
225e48df608c Softwaretests...20181219 6.1: overflow day compute with 365.25 instead of 365.0
mschaefer
parents: 9534
diff changeset
147 odays[i] = 365 - wqday.getDay(i); // TODO Eigentlich 365.25, ist aber mit getDay als int sinnlos
9534
b380a5693514 Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge);
mschaefer
parents: 9528
diff changeset
148 return new WQDay(odays, wqday.getWs(), wqday.getQs());
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
149 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
150
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
151 /**
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
152 * Calculates the data for the Q main value lines in the duration curve chart
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
153 */
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
154 public List<StickyAxisAnnotation> calcMainValueQAnnotations(final Calculation problems, final double station, final FloodDurationCalculationResult result) {
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
155
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
156 // Search the station in the previously calculated result rows and terminate if no infrastructure row found
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
157 double station1 = station;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
158 if (Double.isNaN(station)) {
9298
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
159 for (final ResultRow row : result.getAllRows()) {
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
160 station1 = row.getDoubleValue(GeneralResultType.station);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
161 break;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
162 }
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
163 }
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
164 final List<ResultRow> stationRows = searchStation(station1, AttributeKey.NONE, result.getAllRows());
9297
7100a555607c Small fixes of the S-Info flood duration outputs
mschaefer
parents: 9286
diff changeset
165 if (stationRows.isEmpty()) {
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
166 return new ArrayList<>();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
167 }
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
168 final ResultRow row = stationRows.get(0);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
169 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
170 final List<DurationWaterlevel> wqds = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
171 for (final DurationWaterlevel wqd : wqds) {
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
172 final String label = wqd.getBezeichnung().startsWith("W=") ? "Q(" + wqd.getBezeichnung() + ")" : wqd.getBezeichnung();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
173 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) wqd.getDischarge(), SimpleAxis.Y_AXIS,
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
174 FloodDurationCurveGenerator.YAXIS.Q.idx);
9357
5ce50640688c S-Info flood duration: fixed error report output name, changed duration from int to double, added formatter
mschaefer
parents: 9318
diff changeset
175 annotation.setHitPoint((float) wqd.getFloodDurDaysPerYear());
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
176 annotations.add(annotation);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
177 }
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
178 return annotations;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
179 }
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
180
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
181 /**
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
182 * Calculates the data for the W main value lines in the duration curve chart
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
183 */
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
184 public List<StickyAxisAnnotation> calcMainValueWAnnotations(final Calculation problems, final double station, final FloodDurationCalculationResult result) {
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
185
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
186 // Search the station in the previously calculated result rows and terminate if no infrastructure row found
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
187 double station1 = station;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
188 if (Double.isNaN(station)) {
9298
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
189 for (final ResultRow row : result.getAllRows()) {
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
190 station1 = row.getDoubleValue(GeneralResultType.station);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
191 break;
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
192 }
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
193 }
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
194 final List<ResultRow> stationRows = searchStation(station1, AttributeKey.NONE, result.getAllRows());
9297
7100a555607c Small fixes of the S-Info flood duration outputs
mschaefer
parents: 9286
diff changeset
195 if (stationRows.isEmpty()) {
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
196 return new ArrayList<>();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
197 }
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
198 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
199 final ResultRow row = stationRows.get(0);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
200 final List<DurationWaterlevel> wqds = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
201 for (final DurationWaterlevel wqd : wqds) {
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
202 final String label = !wqd.getBezeichnung().startsWith("W=") ? "W(" + wqd.getBezeichnung() + ")" : wqd.getBezeichnung();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
203 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) wqd.getWaterlevel(), SimpleAxis.Y_AXIS,
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
204 FloodDurationCurveGenerator.YAXIS.W.idx);
9357
5ce50640688c S-Info flood duration: fixed error report output name, changed duration from int to double, added formatter
mschaefer
parents: 9318
diff changeset
205 annotation.setHitPoint((float) wqd.getFloodDurDaysPerYear());
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
206 annotations.add(annotation);
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
207 }
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
208 return annotations;
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
209 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
210
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
211 /**
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
212 * Find and return the W or Q annotation(s) of a station and a riverside in a previously calculated result
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
213 */
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
214 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, final AttributeKey riverside,
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
215 final boolean isW, final FloodDurationCalculationResult result) {
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
216
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
217 // Search the station in the previously calculated result rows and terminate if no infrastructure row found
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
218 double station1 = station;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
219 if (Double.isNaN(station)) {
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
220 for (final ResultRow row : result.getRows()) {
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
221 if (row.getValue(SInfoResultType.riverside) == riverside) {
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
222 station1 = row.getDoubleValue(GeneralResultType.station);
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
223 break;
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
224 }
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
225 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
226 }
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
227 final List<ResultRow> stationRows = searchStation(station1, riverside, result.getRows());
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
228 if (stationRows.isEmpty() || (stationRows.get(0).getValue(SInfoResultType.infrastructuretype) == null)) {
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
229 return new ArrayList<>();
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
230 }
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
231 // Same way as in MainValueWFacet and ..QFacet
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
232 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
233 for (final ResultRow row : stationRows) {
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
234 if (isW)
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
235 annotations.add(calcInfrastructureWAnnotation(row));
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
236 else
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
237 annotations.add(calcInfrastructureQAnnotation(row));
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
238 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
239 return annotations;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
240 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
241
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
242 /**
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
243 * Searches the one or two rows of a station in a result rows collection
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
244 */
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
245 private List<ResultRow> searchStation(final double station, final AttributeKey riverside, final Collection<ResultRow> rows) {
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
246 final List<ResultRow> found = new ArrayList<>();
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
247 for (final ResultRow row : rows) {
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
248 if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001)
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
249 break;
9376
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
250 else if ((row.getDoubleValue(GeneralResultType.station) > station - 0.0001)
f318359b81a2 S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents: 9357
diff changeset
251 && ((riverside == AttributeKey.NONE) || (row.getValue(SInfoResultType.riverside) == riverside)))
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
252 found.add(row);
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
253 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
254 return found;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
255 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
256
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
257 /**
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
258 * Calculates the Q annotation lines of an infrastructure
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
259 */
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
260 private StickyAxisAnnotation calcInfrastructureQAnnotation(final ResultRow row) {
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
261 final String label = Resources.getMsg(this.context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure",
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
262 "sinfo.chart.flood_duration.curve.infrastructure",
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
263 SInfoResultType.infrastructuretype.exportValue(this.context, row.getValue(SInfoResultType.infrastructuretype)) + ", "
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
264 + SInfoResultType.riverside.exportValue(this.context, row.getValue(SInfoResultType.riverside)));
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
265 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.floodDischarge), SimpleAxis.Y_AXIS,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
266 FloodDurationCurveGenerator.YAXIS.Q.idx);
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
267 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration));
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
268 return annotation;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
269 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
270
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
271 /**
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
272 * Calculates the W annotation lines of an infrastructure
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
273 */
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
274 private StickyAxisAnnotation calcInfrastructureWAnnotation(final ResultRow row) {
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
275 final String label = Resources.getMsg(this.context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure",
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
276 "sinfo.chart.flood_duration.curve.infrastructure",
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
277 SInfoResultType.infrastructuretype.exportValue(this.context, row.getValue(SInfoResultType.infrastructuretype)) + ", "
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
278 + SInfoResultType.riverside.exportValue(this.context, row.getValue(SInfoResultType.riverside)));
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
279 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.infrastructureHeight),
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
280 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.W.idx);
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
281 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration));
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9265
diff changeset
282 return annotation;
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
283 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
284
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
285 /**
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
286 * Adds to a stations map all stations corresponding to the active range and step
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
287 */
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
288 private void addRangeStations(final Map<Double, InfrastructureValue> allStations, final WINFOArtifact winfo) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
289 for (final double station : new ComputationRangeAccess(winfo).getKms())
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
290 allStations.put(Double.valueOf(station), null);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
291 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
292
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
293 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
294 * Adds to a stations map all range limits of the gauges within the calc range
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
295 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
296 private void addGaugeLimits(final Map<Double, InfrastructureValue> allStations, final Set<Gauge> gauges, final double fromKm, final double toKm) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
297 for (final Gauge gauge : gauges) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
298 final Double kmA = Double.valueOf(gauge.getRange().getA().doubleValue());
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
299 final Double kmB = Double.valueOf(gauge.getRange().getB().doubleValue());
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
300 if (kmA > fromKm - 0.0001)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
301 allStations.put(kmA, null);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
302 if (kmB < toKm + 0.0001)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
303 allStations.put(kmB, null);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
304 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
305 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
306
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
307 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
308 * Adds to a stations map all (first) infrastructures of a station, and the second, if any, to another map
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
309 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
310 private void addInfrastructures(final Map<Double, InfrastructureValue> allStations, final Map<Double, InfrastructureValue> secondBank,
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
311 final List<InfrastructureValue> infrastructures) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
312 for (final InfrastructureValue infrastructure : infrastructures) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
313 final Double station = infrastructure.getStation();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
314 if (!allStations.containsKey(station) || !(allStations.get(station) instanceof InfrastructureValue))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
315 allStations.put(station, infrastructure);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
316 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
317 secondBank.put(station, infrastructure);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
318 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
319 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
320
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
321 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
322 * Returns a double array with a sorted stations set
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
323 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
324 private double[] sortStations(final Set<Double> stations) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
325 final TDoubleArrayList sorted = new TDoubleArrayList();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
326 for (final Double station : stations)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
327 sorted.add(station.doubleValue());
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
328 sorted.sort();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
329 return sorted.toNativeArray();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
330 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
331
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
332 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
333 * Calculates an array of w-q-longitudinal sections for all artifact W/Q options
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
334 */
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
335 private WQKms[] calculateWsts(final WINFOArtifact winfo, final boolean withWspl, final double[] stations, final Calculation problems) {
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
336 // First run may take long, further runs are faster since WstValueTable is in cache then
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
337 // (So funktioniert computeWaterlevelData wohl:
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
338 // Es sucht die Spalte(n) zum Bezugspegel-Q in der W-Q-Tabelle ({river}.wst in Wst etc.),
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
339 // interpoliert die horizontale Tabellenposition (Q) und dann die vertikale Tabellenposition der station;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
340 // das ergibt das W einer station für einen Abflusszustand;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
341 // bei Vorgabe eines Pegel-W wird vorher anhand der W-Q-Tabelle des Pegels ({gauge}.at in DischargeTable) das Q
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
342 // interpoliert;
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
343 // bei Vorgabe eines W auf freier Strecke wird wohl vorher noch die .wst-Interpolation eingesetzt, um das Q zu bekommen.
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
344
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
345 if (!withWspl)
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
346 return new WQKms[] {};
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
347
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
348 final CalculationResult wstsData = winfo.computeWaterlevelData(stations);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
349
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
350 /* copy all problems */
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
351 final Calculation winfoProblems = wstsData.getReport();
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
352 final List<Problem> problems2 = winfoProblems.getProblems();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
353 if (problems2 != null) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
354 for (final Problem problem : problems2) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
355 problems.addProblem(problem);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
356 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
357 }
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
358 return (WQKms[]) wstsData.getData();
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
359 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
360
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
361 /**
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
362 * Determines the waterlevel/discharge state labels for the selected Q or W values and sets them in the WQKms array
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
363 */
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
364 private void updateWstLabels(final WQKms[] wqkmsArray, final WINFOArtifact winfo, final Calculation problems) {
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
365
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
366 for (int i = 0; i <= wqkmsArray.length - 1; i++)
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
367 wqkmsArray[i].setName(buildWQDescription(wqkmsArray[i], winfo));
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
368 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
369
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
370 /**
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
371 * Builds the description label of a waterlevel
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
372 */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
373 private String buildWQDescription(final WQKms wqkms, final WINFOArtifact winfo) {
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
374
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
375 final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context);
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
376 // TODO Zwischen numerischem Q-Wert und Dauerzahl-Hauptwert (0..364) unterscheiden
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
377 final String description = descBuilder.getDesc(wqkms);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
378 if (!description.isEmpty() && Character.isDigit(description.charAt(0))) {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
379 if (winfo.isQ())
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
380 return "Q=" + description;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
381 else
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
382 return "W=" + description;
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
383 } else
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
384 return description;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
385 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
386
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
387 /**
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
388 * Calculates the flood durations of the Qs of the waterlevels/discharge states for a map of gauges
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
389 */
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
390 private void calcGaugeWstDurations(final WINFOArtifact winfo, final List<Gauge> gauges, final Map<Gauge, List<Double>> gaugeWstDurations,
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
391 final Map<Gauge, GaugeDurationValuesFinder> durFinders) {
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
392
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
393 final double[] gaugeKms = new double[gauges.size()];
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
394 for (int i = 0; i <= gauges.size() - 1; i++) {
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
395 gaugeKms[i] = gauges.get(i).getStation().doubleValue();
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
396 gaugeWstDurations.put(gauges.get(i), new ArrayList<Double>());
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
397 }
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
398 final CalculationResult wstsData = winfo.computeWaterlevelData(gaugeKms);
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
399 final WQKms[] wsts = (WQKms[]) wstsData.getData();
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
400 for (int i = 0; i <= gauges.size() - 1; i++) {
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
401 final GaugeDurationValuesFinder durFinder = durFinders.get(gauges.get(i));
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
402 for (int j = 0; j <= wsts.length - 1; j++) {
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
403 final double d = durFinder.getDuration(wsts[j].getQ(i));
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
404 gaugeWstDurations.get(gauges.get(i)).add(Double.valueOf(underflowDaysToOverflowDays(d)));
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
405 }
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
406 }
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
407 }
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
408
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
409 /**
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
410 * Create a result row for a station, and add w-q-values as selected
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
411 */
9398
929d645691ae Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents: 9376
diff changeset
412 private ResultRow createRow(final Double station, final WQKms[] wqkmsArray, final List<Double> gaugeDurations, final int kmIndex) {
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
413
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
414 final ResultRow row = ResultRow.create();
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
415 row.putValue(GeneralResultType.station, station);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
416 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
417 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
418
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
419 final String gaugeLabel = this.riverInfoProvider2.findGauge(station);
9318
7b2b086e45f0 collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents: 9312
diff changeset
420 row.putValue(GeneralResultType.gaugeLabel, gaugeLabel);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
421
9528
55c187a0a31e Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents: 9499
diff changeset
422 final String location = this.riverInfoProvider2.getLocation(station);
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 9308
diff changeset
423 row.putValue(GeneralResultType.location, location);
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
424
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
425 final List<DurationWaterlevel> wsts = new ArrayList<>(wqkmsArray.length);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
426
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
427 for (int i = 0; i <= wqkmsArray.length - 1; i++) {
9357
5ce50640688c S-Info flood duration: fixed error report output name, changed duration from int to double, added formatter
mschaefer
parents: 9318
diff changeset
428 final DurationWaterlevel dw = new DurationWaterlevel(wqkmsArray[i].getW(kmIndex), gaugeDurations.get(i), wqkmsArray[i].getQ(kmIndex),
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
429 wqkmsArray[i].getName());
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
430 wsts.add(dw);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
431 }
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
432 row.putValue(SInfoResultType.customMultiRowColWaterlevel, wsts);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
433
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
434 return row;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
435 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
436
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
437 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
438 * Calculate the result row fields for one infrastructure
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
439 */
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
440 private void calculateInfrastructure(final ResultRow row, final Gauge gauge, final InfrastructureValue infrastructure, final WstValueTable wst,
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
441 final Map<Gauge, GaugeDurationValuesFinder> durFinders) {
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
442
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
443 // Interpolate the infrastructure height in the wst table to get the corresponding Q
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
444 final Calculation problems = new Calculation();
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
445 final double[] qs = wst.findQsForW(infrastructure.getStation().doubleValue(), infrastructure.getHeight().doubleValue(), problems);
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
446 // TODO Fehlerbehandlung (kein Q gefunden)
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
447 final double q = (qs.length >= 1) ? qs[0] : Double.NaN;
9308
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
448 // Set the result row
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
449 row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey());
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
450 row.putValue(SInfoResultType.floodDischarge, q);
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
451 row.putValue(SInfoResultType.infrastructureHeight, infrastructure.getHeight());
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
452 row.putValue(SInfoResultType.infrastructuretype, infrastructure.getInfrastructure().getType().getName());
9286
bcbae86ce7b3 Improved flood duration curve calculation as specified by BfG
mschaefer
parents: 9269
diff changeset
453 // Determine the relative column position of the Q of the infrastructure height
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
454 final QPosition qPos = wst.getQPosition(infrastructure.getStation().doubleValue(), q);
9308
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
455 if (qPos == null)
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
456 return;
9269
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
457 // Get the Q for the found column position for the station of the gauge
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
458 final double qGauge = wst.getQ(qPos, gauge.getStation().doubleValue());
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
459 // Interpolate the Q-D-table of the gauge
83ebeb620b5a Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
mschaefer
parents: 9266
diff changeset
460 final double dur = underflowDaysToOverflowDays(durFinders.get(gauge).getDuration(qGauge));
9308
9055afc19ec6 Fixed capturing invalid heights/discharges in S-Info flood duration calculation
mschaefer
parents: 9298
diff changeset
461 // Set D in the result row
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
462 row.putValue(SInfoResultType.floodDuration, dur);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
463 }
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
464
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
465 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
466 * Translates underflow duration into overflow duration
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
467 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
468 private double underflowDaysToOverflowDays(final double underflowDays) {
9594
225e48df608c Softwaretests...20181219 6.1: overflow day compute with 365.25 instead of 365.0
mschaefer
parents: 9534
diff changeset
469 return 365.25 - underflowDays;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
470 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
471 }

http://dive4elements.wald.intevation.org