annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9259:66b003701546

Added infrastructure height and Q annotation to S-Info flood duration curve chart
author mschaefer
date Mon, 16 Jul 2018 08:43:07 +0200
parents ef7b65576d4b
children e5367900dd6d
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;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
13 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
14 import java.util.List;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
15 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
16 import java.util.Set;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
17
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
18 import org.apache.commons.lang.math.DoubleRange;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
19 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
20 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
21 import org.dive4elements.river.artifacts.access.ComputationRangeAccess;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.common.GeneralResultType;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.artifacts.common.ResultRow;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
24 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
25 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
26 import org.dive4elements.river.artifacts.model.CalculationResult;
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
27 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
28 import org.dive4elements.river.artifacts.model.WQKms;
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
29 import org.dive4elements.river.artifacts.resources.Resources;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
30 import org.dive4elements.river.artifacts.sinfo.common.GaugeDurationValuesFinder;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
33 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
34 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey;
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
35 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
36 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
37 import org.dive4elements.river.jfree.StickyAxisAnnotation.SimpleAxis;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
38 import org.dive4elements.river.model.Attribute.AttributeKey;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
39 import org.dive4elements.river.model.Gauge;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
40 import org.dive4elements.river.model.sinfo.InfrastructureValue;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
41
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
42 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
43
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
44 /**
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
45 * 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
46 * and selected main value durations
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
47 *
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
48 * @author Matthias Schäfer
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
49 */
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
50 final class FloodDurationCalculator {
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
51
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
52 private final List<ResultRow> rows = new ArrayList<>();
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
53
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
54 private final RiverInfoProvider riverInfoProvider;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
55
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
56 private final CallContext context;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
57
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
58 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
59 this.context = context;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
60 this.riverInfoProvider = riverInfoProvider;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
61 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
62
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
63 /**
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
64 * Calculate the infrastructures flood duration result rows
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
65 */
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
66 public void execute(final Calculation problems, final String label, final DoubleRange calcRange,
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
67 final RiversideChoiceKey riverside, final WINFOArtifact winfo, final FloodDurationCalculationResults results) {
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
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 // 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
70 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new 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
71 Gauge firstGauge = null;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
72 for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) {
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
73 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, 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
74 if (firstGauge == null)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
75 firstGauge = gauge;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
76 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
77
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
78 // 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
79 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
80 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
81 calcRange.getMaximumDouble(), bankKey);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
82
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
83 // 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
84 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
85 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
86 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
87 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
88 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
89 final double[] stationsSorted = sortStations(allStations.keySet());
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
90
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
91 // Calculate W and Q for all stations and the selected discharge states
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
92 // TODO Laut Herrn Reiß: Q und D jeweils konstant für jedes Pegel-Intervall, Q-Änderungen (Zuflüsse etc.) aus .wst
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
93 // ignorieren
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
94 final WQKms[] wqkmsArray = calculateWaterlevels(winfo, stationsSorted, problems);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
95
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
96 // Determine discharge state labels of the main values
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
97 updateMainValueLabels(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
98
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
99 // Create a finder for Q in the {river}.wst km-w-q table
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
100 final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(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
101 calcRange.getMaximumDouble(), problems);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
102
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
103 // Calculate the durations and create the result rows
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
104 for (int i = 0; i <= stationsSorted.length - 1; i++) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
105 final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true);
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
106 final ResultRow row = createRow(stationsSorted[i], gauge, firstGauge, wqkmsArray, durFinders.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
107 if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
108 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wqFinder, durFinders);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
109 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
110 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
111 final ResultRow row2 = ResultRow.create(row);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
112 calculateInfrastructure(row2, gauge, secondBank.get(stationsSorted[i]), wqFinder, durFinders);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
113 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
114 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
115 }
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
116 final String[] mainValueLabels = new String[wqkmsArray.length];
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
117 for (int i = 0; i <= wqkmsArray.length - 1; i++)
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
118 mainValueLabels[i] = wqkmsArray[i].getName();
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
119 results.addResult(new FloodDurationCalculationResult(label, mainValueLabels, this.rows), problems);
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
120
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
121 calcWQDays(problems, stationsSorted[0], AttributeKey.LEFT, winfo, results);
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
122
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
123 calcMainValueAnnotations(problems, 0, AttributeKey.LEFT, wqkmsArray, results);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
124
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
125 calcInfrastructureAnnotations(problems, this.rows.get(0), wqkmsArray, results);
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
126 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
127
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
128 /**
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
129 * Calculate duration curve for a station and add to result collection
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
130 */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
131 private void calcWQDays(final Calculation problems, final double station, final AttributeKey riverside, final WINFOArtifact winfo,
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
132 final FloodDurationCalculationResults results) {
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
133
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
134 // Same processing as in W-Info DurationCurveState
9252
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
135 winfo.addStringData("ld_locations", Double.toString(station));
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
136 final CalculationResult res = winfo.getDurationCurveData();
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
137 final WQDay underflow = (WQDay) res.getData();
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
138 // Transform underflow days into overflow days and re-sort
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
139 final int[] days = new int[underflow.getWs().length];
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
140 final double[] ws = new double[days.length];
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
141 final double[] qs = new double[days.length];
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
142 for (int i = 0, j = days.length - 1; i <= days.length - 1; i++, j--) {
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
143 days[j] = 365 - underflow.getDay(i);
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
144 ws[j] = underflow.getW(i);
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
145 qs[j] = underflow.getQ(i);
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
146 }
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
147 res.setData(new WQDay(days, ws, qs));
c2a0028bfa9f Work on S-Info flood duration curve chart
mschaefer
parents: 9236
diff changeset
148 results.setDurationCurve(res);
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 /**
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
152 * Calculate the data for the W and Q main value lines in the duration curve chart and add to result collection
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
153 */
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
154 private void calcMainValueAnnotations(final Calculation problems, final int stationIndex, final AttributeKey riverside,
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
155 final WQKms[] wqkmsArray, final FloodDurationCalculationResults results) {
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
156
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
157 // Same way as in MainValueWFacet and ..QFacet, but special label handling
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
158 final List<StickyAxisAnnotation> ws = new ArrayList<>();
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
159 final List<StickyAxisAnnotation> qs = new ArrayList<>();
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
160 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
161 final String qLabel = wqkmsArray[i].getName().startsWith("W=") ? "Q(" + wqkmsArray[i].getName() + ")" : wqkmsArray[i].getName();
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
162 final StickyAxisAnnotation qAnnotation = new StickyAxisAnnotation(qLabel, (float) wqkmsArray[i].getQ(stationIndex), SimpleAxis.Y_AXIS,
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
163 FloodDurationCurveGenerator.YAXIS.Q.idx);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
164 qs.add(qAnnotation);
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
165 FloodDurationMainValuesQFacet.setHitPoint((WQDay) results.getDurationCurve().getData(), qAnnotation);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
166 final String wLabel = !wqkmsArray[i].getName().startsWith("W=") ? "W(" + wqkmsArray[i].getName() + ")" : wqkmsArray[i].getName();
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
167 final StickyAxisAnnotation wAnnotation = new StickyAxisAnnotation(wLabel, (float) wqkmsArray[i].getW(stationIndex), SimpleAxis.Y_AXIS,
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
168 FloodDurationCurveGenerator.YAXIS.W.idx);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
169 ws.add(wAnnotation);
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
170 FloodDurationMainValuesWFacet.setHitPoint((WQDay) results.getDurationCurve().getData(), wAnnotation);
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
171 }
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
172 results.getMainValueQAnnotations().clear();
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
173 results.getMainValueQAnnotations().addAll(qs);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
174 results.getMainValueWAnnotations().clear();
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
175 results.getMainValueWAnnotations().addAll(ws);
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
176 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
177
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
178 /**
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
179 * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
180 * collection
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
181 */
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
182 private void calcInfrastructureAnnotations(final Calculation problems, final ResultRow row, final WQKms[] wqkmsArray,
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
183 final FloodDurationCalculationResults results) {
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
184
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
185 if (row.getValue(SInfoResultType.infrastructuretype) == null) {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
186 results.setInfrastructureWAnnotation(null);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
187 results.setInfrastructureQAnnotation(null);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
188 return;
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
189 }
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
190 // Same way as in MainValueWFacet and ..QFacet
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
191 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
192 "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
193 SInfoResultType.infrastructuretype.exportValue(this.context, row.getValue(SInfoResultType.infrastructuretype))
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
194 + ", " + SInfoResultType.riverside.exportValue(this.context, row.getValue(SInfoResultType.riverside)));
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
195 final StickyAxisAnnotation qAnnotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.floodDischarge),
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
196 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.Q.idx);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
197 FloodDurationMainValuesQFacet.setHitPoint((WQDay) results.getDurationCurve().getData(), qAnnotation);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
198 final StickyAxisAnnotation wAnnotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.infrastructureHeight),
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
199 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.W.idx);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
200 FloodDurationMainValuesWFacet.setHitPoint((WQDay) results.getDurationCurve().getData(), wAnnotation);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
201
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
202 results.setInfrastructureQAnnotation(qAnnotation);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
203 results.setInfrastructureWAnnotation(wAnnotation);
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
204 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
205
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents: 9252
diff changeset
206 /**
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
207 * 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
208 */
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
209 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
210 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
211 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
212 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
213
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
214 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
215 * 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
216 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
226 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
227
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
228 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
229 * 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
230 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
231 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
232 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
233 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
234 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
235 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
236 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
237 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
238 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
239 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
240 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
241
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
242 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
243 * 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
244 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
245 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
246 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
247 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
248 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
249 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
250 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
251 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
252
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
253 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
254 * 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
255 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
256 private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final double[] stations, final Calculation problems) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
257 // REMARK aus TkhCalculation - move to WinfoArtifactWrapper?
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
258 // TODO das ist ziemlich langsam - durch den WQBaseTableFinder ersetzen? (vorher W-Optionen in Q umrechnen)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
259 // (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
260 // 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
261 // 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
262 // 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
263 // 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
264 // 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
265 // 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
266
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
267 final CalculationResult waterlevelData = winfo.computeWaterlevelData(stations);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
268
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
269 /* copy all problems */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
270 final Calculation winfoProblems = waterlevelData.getReport();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
271 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
272 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
273 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
274 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
275 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
276 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
277 return (WQKms[]) waterlevelData.getData();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
278 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
279
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
280 /**
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
281 * 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
282 */
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
283 private void updateMainValueLabels(final WQKms[] wqkmsArray, final WINFOArtifact winfo, final Calculation problems) {
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
284
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
285 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
286 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
287 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
288
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
289 /**
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
290 *
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
291 * @param wqkms
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
292 * @param descBuilder
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
293 * @return
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
294 */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
295 private String buildWQDescription(final WQKms wqkms, final WINFOArtifact winfo) {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
296 final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
297 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
298 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
299 if (winfo.isQ())
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
300 return "Q=" + description;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
301 else
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
302 return "W=" + description;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
303 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
304 else
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
305 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
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 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
309 * Create a result row for a station and its gauge, and add w-q-values as selected
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
310 */
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
311 private ResultRow createRow(final Double station, final Gauge gauge, final Gauge firstGauge, final WQKms[] wqkmsArray,
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
312 final GaugeDurationValuesFinder durationFinder, final int kmIndex) {
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
313
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
314 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
315 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
316 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
317 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
318
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
319 final String gaugeLabel = this.riverInfoProvider.findGauge(station, (gauge == firstGauge));
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
320 row.putValue(SInfoResultType.gaugeLabel, gaugeLabel);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
321
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
322 final String location = this.riverInfoProvider.getLocation(station);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
323 row.putValue(SInfoResultType.location, location);
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
324
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
325 final List<DurationWaterlevel> waterlevels = new ArrayList<>(wqkmsArray.length);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
326
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
327 for (final WQKms wqKms : wqkmsArray) {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
328 assert (wqKms.getKm(kmIndex) == station.doubleValue());
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
329
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
330 final int overflowDays = (int) Math.round(underflowDaysToOverflowDays(durationFinder.getDuration(wqKms.getQ(kmIndex))));
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
331
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
332 final DurationWaterlevel dw = new DurationWaterlevel(wqKms.getW(kmIndex), overflowDays, wqKms.getQ(kmIndex), wqKms.getName());
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
333 waterlevels.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
334 }
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
335 row.putValue(SInfoResultType.customMultiRowColWaterlevel, waterlevels);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
336
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 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
338 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
339
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
340 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
341 * 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
342 */
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
343 private void calculateInfrastructure(final ResultRow row, final Gauge gauge, final InfrastructureValue infrastructure, final WQBaseTableFinder wqFinder,
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
344 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
345
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
346 final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight());
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
347 final double qOut = Double.isInfinite(q) ? Double.NaN : q;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
348 final double dur = underflowDaysToOverflowDays(durFinders.get(gauge).getDuration(q));
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
349 row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey());
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
350 row.putValue(SInfoResultType.floodDuration, dur);
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
351 row.putValue(SInfoResultType.floodDischarge, qOut);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
352 row.putValue(SInfoResultType.infrastructureHeight, infrastructure.getHeight());
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
353 row.putValue(SInfoResultType.infrastructuretype, infrastructure.getInfrastructure().getType().getName());
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
354 }
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
355
9202
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 * 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
358 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
359 private double underflowDaysToOverflowDays(final double underflowDays) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
360 return 365 - underflowDays;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
361 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
362 }

http://dive4elements.wald.intevation.org