annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents
children a4f1ac81f26d
rev   line source
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
2 * Software engineering by
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
5 *
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
9 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
11
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
12 import java.util.ArrayList;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
13 import java.util.Collection;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
14
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
15 import org.apache.commons.lang.math.DoubleRange;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
16 import org.dive4elements.artifacts.CallContext;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
17 import org.dive4elements.river.artifacts.model.Calculation;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.CalculationResult;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
19 import org.dive4elements.river.artifacts.model.WKms;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.artifacts.resources.Resources;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthUtils;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.artifacts.sinfo.flowdepthminmax.FlowDepthMinMaxAccess.MinMaxIdPair;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
25 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.DischargeValuesFinder;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
26 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.WaterlevelValuesFinder;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
27 import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
28 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
29 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
30 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
31 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
32 import org.dive4elements.river.artifacts.states.WaterlevelData;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
33 import org.dive4elements.river.artifacts.states.WaterlevelFetcher;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
34 import org.dive4elements.river.model.River;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
35
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
36 /**
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
37 * @author Gernot Belger
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
38 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
39 final class FlowDepthMinMaxCalculation {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
40
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
41 private final CallContext context;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
42
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
43 public FlowDepthMinMaxCalculation(final CallContext context) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
44 this.context = context;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
45 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
46
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
47 public CalculationResult calculate(final SINFOArtifact sinfo) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
48
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
49 final String user = CalculationUtils.findArtifactUser(this.context, sinfo);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
50
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
51 /* access input data */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
52 final FlowDepthMinMaxAccess access = new FlowDepthMinMaxAccess(sinfo);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
53 final River river = access.getRiver();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
54 final RiverInfo riverInfo = new RiverInfo(river);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
55
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
56 final Collection<MinMaxIdPair> minMaxPairs = access.getMinMaxPairs();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
57
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
58 final DoubleRange calcRange = access.getRange();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
59
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
60 /* calculate results for each diff pair */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
61 final Calculation problems = new Calculation();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
62
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
63 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
64
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
65 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
66
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
67 final FlowDepthMinMaxCalculationResults results = new FlowDepthMinMaxCalculationResults(calcModeLabel, user, riverInfo, calcRange);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
68
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
69 for (final MinMaxIdPair minMaxPair : minMaxPairs) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
70 final FlowDepthMinMaxCalculationResult result = calculateResult(calcRange, minMaxPair, problems, infoProvider);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
71 if (result != null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
72 results.addResult(result);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
73 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
74
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
75 return new CalculationResult(results, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
76 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
77
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
78 /**
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
79 * Calculates one W-MSH differences pair.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
80 *
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
81 * @param infoProvider
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
82 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
83 private FlowDepthMinMaxCalculationResult calculateResult(final DoubleRange calcRange, final MinMaxIdPair minMaxPair, final Calculation problems,
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
84 final RiverInfoProvider infoProvider) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
85
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
86 /* access real input data from database */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
87 final String wstId = minMaxPair.getWstId();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
88 final String minSoundingId = minMaxPair.getMinSoundingId();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
89 final String maxSoundingId = minMaxPair.getMinSoundingId();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
90
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
91 final BedHeightsFinder minBedHeight = minSoundingId == null ? null : BedHeightsFinder.forId(this.context, minSoundingId, calcRange, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
92 final BedHeightsFinder maxBedHeight = maxSoundingId == null ? null : BedHeightsFinder.forId(this.context, maxSoundingId, calcRange, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
93 if (minBedHeight == null && maxBedHeight == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
94 return null;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
95
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
96 /* REMARK: fetch ALL wst kms, because we want to determine the original reference gauge */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
97 final WaterlevelData waterlevel = new WaterlevelFetcher().findWaterlevel(this.context, wstId, Double.NaN, Double.NaN, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
98 if (waterlevel == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
99 return null;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
100
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
101 final String label = createLabel(waterlevel, minBedHeight, maxBedHeight);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
102
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
103 final WKms wstKms = waterlevel.getWkms();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
104
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
105 final int soundingYear = checkSoundingYear(minBedHeight, maxBedHeight, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
106 FlowDepthUtils.checkYearDifference(label, waterlevel, soundingYear, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
107 // FIXME
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
108 // checkWaterlevelDiscretisation(wstKms, calcRange, problems);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
109 // TODO: prüfen, ob sohlhöhen die calcRange abdecken/überschneiden
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
110
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
111 /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
112 final RiverInfoProvider riverInfoProvider = infoProvider.forWaterlevel(waterlevel);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
113
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
114 final int wspYear = waterlevel.getYear();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
115 final WstInfo wstInfo = new WstInfo(waterlevel.getName(), wspYear, riverInfoProvider.getReferenceGauge());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
116
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
117 final WaterlevelValuesFinder waterlevelProvider = WaterlevelValuesFinder.fromKms(wstKms);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
118 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wstKms);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
119
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
120 final String waterlevelLabel = waterlevel.getName();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
121 final String soundingLabel = buildSoundingLabel(minBedHeight, maxBedHeight);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
122
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
123 /* real calculation loop */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
124 final Collection<FlowDepthMinMaxRow> rows = new ArrayList<>();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
125
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
126 // FIXME: determine what is the spatial discretisation that we will use...
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
127 final double[] allKms = wstKms.allKms().toNativeArray();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
128 for (final double station : allKms) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
129 if (calcRange.containsDouble(station)) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
130
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
131 final double wst = waterlevelProvider.getWaterlevel(station);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
132 final double discharge = dischargeProvider.getDischarge(station);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
133
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
134 final double minBedHeightValue = minBedHeight == null ? Double.NaN : minBedHeight.getMeanBedHeight(station);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
135 final double maxBedHeightValue = maxBedHeight == null ? Double.NaN : maxBedHeight.getMeanBedHeight(station);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
136
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
137 final double minFlowDepth = wst - minBedHeightValue;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
138 final double maxFlowDepth = wst - maxBedHeightValue;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
139
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
140 // FIXME: unclear what is meant here...
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
141 final double meanBedHeight = Double.NaN;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
142
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
143 // REMARK: access the location once only during calculation
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
144 final String location = riverInfoProvider.getLocation(station);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
145
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
146 // REMARK: access the gauge once only during calculation
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
147 final String gaugeLabel = riverInfoProvider.findGauge(station);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
148
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
149 rows.add(new FlowDepthMinMaxRow(station, minFlowDepth, maxFlowDepth, wst, discharge, waterlevelLabel, gaugeLabel, meanBedHeight, soundingLabel,
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
150 location));
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
151 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
152 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
153
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
154 final BedHeightInfo minBedHeightInfo = minBedHeight == null ? null : minBedHeight.getInfo();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
155 final BedHeightInfo maxBedHeightInfo = maxBedHeight == null ? null : maxBedHeight.getInfo();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
156 return new FlowDepthMinMaxCalculationResult(label, wstInfo, minBedHeightInfo, maxBedHeightInfo, rows);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
157 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
158
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
159 private String buildSoundingLabel(final BedHeightsFinder minBedHeight, final BedHeightsFinder maxBedHeight) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
160
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
161 if (minBedHeight == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
162 return maxBedHeight.getInfo().getDescription();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
163
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
164 if (maxBedHeight == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
165 return minBedHeight.getInfo().getDescription();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
166
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
167 return String.format("%s / %s", minBedHeight.getInfo().getDescription(), maxBedHeight.getInfo().getDescription());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
168 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
169
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
170 private String createLabel(final WaterlevelData waterlevel, final BedHeightsFinder minBedHeight, final BedHeightsFinder maxBedHeight) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
171
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
172 final StringBuilder buffer = new StringBuilder(waterlevel.getName());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
173
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
174 if (minBedHeight != null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
175 buffer.append(" - "). //
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
176 append(minBedHeight.getInfo().getDescription());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
177
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
178 if (maxBedHeight != null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
179 buffer.append(" - "). //
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
180 append(maxBedHeight.getInfo().getDescription());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
181
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
182 return buffer.toString();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
183 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
184
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
185 private int checkSoundingYear(final BedHeightsFinder minBedHeight, final BedHeightsFinder maxBedHeight, final Calculation problems) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
186
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
187 if (maxBedHeight == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
188 return minBedHeight.getInfo().getYear();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
189
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
190 if (minBedHeight == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
191 return maxBedHeight.getInfo().getYear();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
192
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
193 final int minYear = minBedHeight.getInfo().getYear();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
194 final int maxYear = minBedHeight.getInfo().getYear();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
195
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
196 if (minYear != maxYear)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
197 problems.addProblem("sinfo.flowdepthminmaxcalculation.soundingyear.different");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
198
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
199 return minYear;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
200 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
201 }

http://dive4elements.wald.intevation.org