Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9528:55c187a0a31e
Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
author | mschaefer |
---|---|
date | Tue, 02 Oct 2018 16:39:51 +0200 |
parents | 853f2dafc16e |
children | b380a5693514 |
comparison
equal
deleted
inserted
replaced
9527:7c8d62867876 | 9528:55c187a0a31e |
---|---|
53 final class FloodDurationCalculator { | 53 final class FloodDurationCalculator { |
54 | 54 |
55 private final List<ResultRow> rows = new ArrayList<>(); | 55 private final List<ResultRow> rows = new ArrayList<>(); |
56 | 56 |
57 private final RiverInfoProvider riverInfoProvider; | 57 private final RiverInfoProvider riverInfoProvider; |
58 private RiverInfoProvider riverInfoProvider2; | |
58 | 59 |
59 private final CallContext context; | 60 private final CallContext context; |
60 | 61 |
61 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { | 62 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { |
62 this.context = context; | 63 this.context = context; |
63 this.riverInfoProvider = riverInfoProvider; | 64 this.riverInfoProvider = riverInfoProvider; |
65 this.riverInfoProvider2 = null; | |
64 } | 66 } |
65 | 67 |
66 /** | 68 /** |
67 * Calculate the infrastructures flood duration result rows | 69 * Calculate the infrastructures flood duration result rows |
68 */ | 70 */ |
69 public void execute(final Calculation problems, final String label, final DoubleRange calcRange, final RiversideChoiceKey riverside, final boolean withWspl, | 71 public void execute(final Calculation problems, final String label, final DoubleRange calcRange, final RiversideChoiceKey riverside, final boolean withWspl, |
70 final WINFOArtifact winfo, final FloodDurationCalculationResults results) { | 72 final WINFOArtifact winfo, final FloodDurationCalculationResults results) { |
71 | 73 |
72 // Find all gauges of the calc range, and create the duration finders | 74 // Find all gauges of the calc range, and create the duration finders |
73 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>(); | 75 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>(); |
74 for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) { | 76 for (final Gauge gauge : this.riverInfoProvider.getGauges()) { |
75 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems)); | 77 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems)); |
76 } | 78 } |
77 | 79 |
78 // Find all infrastructures within the calc range | 80 // Find all infrastructures within the calc range |
79 final AttributeKey bankKey = riverside.getAttributeKey(); | 81 final AttributeKey bankKey = riverside.getAttributeKey(); |
88 addInfrastructures(allStations, secondBank, infras); | 90 addInfrastructures(allStations, secondBank, infras); |
89 final double[] stationsSorted = sortStations(allStations.keySet()); | 91 final double[] stationsSorted = sortStations(allStations.keySet()); |
90 | 92 |
91 // Calculate W and Q for all stations and the selected discharge states/waterlevels | 93 // Calculate W and Q for all stations and the selected discharge states/waterlevels |
92 final WQKms[] wqkmsArray = calculateWsts(winfo, withWspl, stationsSorted, problems); | 94 final WQKms[] wqkmsArray = calculateWsts(winfo, withWspl, stationsSorted, problems); |
95 // final WaterlevelData waterlevel = new WaterlevelData(wqkmsArray[0], -1, false, true); | |
96 // this.riverInfoProvider2 = this.riverInfoProvider.forWaterlevel(waterlevel); | |
97 this.riverInfoProvider2 = this.riverInfoProvider.forReferenceRange(calcRange, false); | |
98 // this.riverInfoProvider2.cleanupGaugesAtStart(calcRange); | |
93 | 99 |
94 // Determine discharge state labels of the waterlevels | 100 // Determine discharge state labels of the waterlevels |
95 updateWstLabels(wqkmsArray, winfo, problems); | 101 updateWstLabels(wqkmsArray, winfo, problems); |
96 | 102 |
97 final Map<Gauge, List<Double>> gaugeWstDurations = new HashMap<>(); | 103 final Map<Gauge, List<Double>> gaugeWstDurations = new HashMap<>(); |
98 if (withWspl) | 104 if (withWspl) |
99 calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders); | 105 calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders); |
100 | 106 |
101 // Load base wst table (river).wst | 107 // Load base wst table (river).wst |
102 // (should be in cache since already used in calculateWaterlevels (winfo.computeWaterlevelData) | 108 // (should be in cache since already used in calculateWaterlevels (winfo.computeWaterlevelData) |
103 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); | 109 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider2.getRiver()); |
104 | 110 |
105 // Create the result rows, and calculate and add the flood durations etc. | 111 // Create the result rows, and calculate and add the flood durations etc. |
106 for (int i = 0; i <= stationsSorted.length - 1; i++) { | 112 for (int i = 0; i <= stationsSorted.length - 1; i++) { |
107 final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true); | 113 final Gauge gauge = this.riverInfoProvider2.getGauge(stationsSorted[i], true); |
108 final ResultRow row = createRow(stationsSorted[i], wqkmsArray, gaugeWstDurations.get(gauge), i); | 114 final ResultRow row = createRow(stationsSorted[i], wqkmsArray, gaugeWstDurations.get(gauge), i); |
109 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) | 115 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) |
110 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wst, durFinders); | 116 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wst, durFinders); |
111 this.rows.add(row); | 117 this.rows.add(row); |
112 if (secondBank.containsKey(stationsSorted[i])) { | 118 if (secondBank.containsKey(stationsSorted[i])) { |
130 * are taken from the Q values of the gauge's Q-D-table) | 136 * are taken from the Q values of the gauge's Q-D-table) |
131 */ | 137 */ |
132 public WQDay calcWQDays(final Calculation problems, final double station, final WINFOArtifact winfo) { | 138 public WQDay calcWQDays(final Calculation problems, final double station, final WINFOArtifact winfo) { |
133 | 139 |
134 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); | 140 final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); |
135 final Gauge gauge = this.riverInfoProvider.getRiver().determineGaugeByPosition(station); | 141 final Gauge gauge = this.riverInfoProvider.getGauge(station, true); |
136 final Object[] obj = gauge.fetchDurationCurveData(); | 142 final Object[] obj = gauge.fetchDurationCurveData(); |
137 final int[] udays = (int[]) obj[0]; | 143 final int[] udays = (int[]) obj[0]; |
138 final double[] qs = (double[]) obj[1]; | 144 final double[] qs = (double[]) obj[1]; |
139 final int[] odays = new int[udays.length]; | 145 final int[] odays = new int[udays.length]; |
140 final double[] oqs = new double[udays.length]; | 146 final double[] oqs = new double[udays.length]; |
419 final ResultRow row = ResultRow.create(); | 425 final ResultRow row = ResultRow.create(); |
420 row.putValue(GeneralResultType.station, station); | 426 row.putValue(GeneralResultType.station, station); |
421 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure | 427 row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure |
422 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure | 428 row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure |
423 | 429 |
424 final String gaugeLabel = this.riverInfoProvider.findGauge(station); | 430 final String gaugeLabel = this.riverInfoProvider2.findGauge(station); |
425 row.putValue(GeneralResultType.gaugeLabel, gaugeLabel); | 431 row.putValue(GeneralResultType.gaugeLabel, gaugeLabel); |
426 | 432 |
427 final String location = this.riverInfoProvider.getLocation(station); | 433 final String location = this.riverInfoProvider2.getLocation(station); |
428 row.putValue(GeneralResultType.location, location); | 434 row.putValue(GeneralResultType.location, location); |
429 | 435 |
430 final List<DurationWaterlevel> wsts = new ArrayList<>(wqkmsArray.length); | 436 final List<DurationWaterlevel> wsts = new ArrayList<>(wqkmsArray.length); |
431 | 437 |
432 for (int i = 0; i <= wqkmsArray.length - 1; i++) { | 438 for (int i = 0; i <= wqkmsArray.length - 1; i++) { |