comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java @ 9397:6e7094368e97

Added gauge name column for uinfo iota
author mschaefer
date Mon, 13 Aug 2018 17:26:33 +0200
parents 439699ff9b2d
children bd5f5d2220fa
comparison
equal deleted inserted replaced
9396:6ebc9357550c 9397:6e7094368e97
9 */ 9 */
10 package org.dive4elements.river.artifacts.uinfo.salix; 10 package org.dive4elements.river.artifacts.uinfo.salix;
11 11
12 import java.math.BigDecimal; 12 import java.math.BigDecimal;
13 import java.util.ArrayList; 13 import java.util.ArrayList;
14 import java.util.Collection;
14 import java.util.HashMap; 15 import java.util.HashMap;
15 import java.util.List; 16 import java.util.List;
16 import java.util.Map; 17 import java.util.Map;
17 import java.util.Map.Entry; 18 import java.util.Map.Entry;
18 import java.util.NavigableMap; 19 import java.util.NavigableMap;
19 20
20 import org.dive4elements.river.artifacts.WINFOArtifact; 21 import org.dive4elements.river.artifacts.WINFOArtifact;
21 import org.dive4elements.river.artifacts.access.ComputationRangeAccess; 22 import org.dive4elements.river.artifacts.access.ComputationRangeAccess;
23 import org.dive4elements.river.artifacts.common.AbstractResultType;
22 import org.dive4elements.river.artifacts.common.GeneralResultType; 24 import org.dive4elements.river.artifacts.common.GeneralResultType;
23 import org.dive4elements.river.artifacts.common.ResultRow; 25 import org.dive4elements.river.artifacts.common.ResultRow;
24 import org.dive4elements.river.artifacts.model.Calculation; 26 import org.dive4elements.river.artifacts.model.Calculation;
25 import org.dive4elements.river.artifacts.model.WstValueTable; 27 import org.dive4elements.river.artifacts.model.WstValueTable;
26 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition; 28 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;
52 private final Map<Gauge, QPosition> gaugeMnwPos; 54 private final Map<Gauge, QPosition> gaugeMnwPos;
53 private final Map<Gauge, QPosition> gaugeMhwPos; 55 private final Map<Gauge, QPosition> gaugeMhwPos;
54 private QPosition refGaugeMwPos; 56 private QPosition refGaugeMwPos;
55 private QPosition refGaugeMnwPos; 57 private QPosition refGaugeMnwPos;
56 private QPosition refGaugeMhwPos; 58 private QPosition refGaugeMhwPos;
59 private Gauge firstGauge;
57 60
58 private Calculation problems; 61 private Calculation problems;
59 62
60 private WstValueTable wst; 63 private WstValueTable wst;
61 64
99 */ 102 */
100 private void fetchGaugeMainValuePositions() { 103 private void fetchGaugeMainValuePositions() {
101 this.gaugeMwPos.clear(); 104 this.gaugeMwPos.clear();
102 this.gaugeMnwPos.clear(); 105 this.gaugeMnwPos.clear();
103 this.gaugeMhwPos.clear(); 106 this.gaugeMhwPos.clear();
104 boolean first = true; 107 this.firstGauge = null;
105 for (final Gauge gauge : this.riverInfoProvider.getGauges()) { 108 for (final Gauge gauge : this.riverInfoProvider.getGauges()) {
106 this.gaugeMwPos.put(gauge, null); 109 this.gaugeMwPos.put(gauge, null);
107 this.gaugeMnwPos.put(gauge, null); 110 this.gaugeMnwPos.put(gauge, null);
108 this.gaugeMhwPos.put(gauge, null); 111 this.gaugeMhwPos.put(gauge, null);
109 final double gaugeKm = gauge.getStation().doubleValue(); 112 final double gaugeKm = gauge.getStation().doubleValue();
113 else if (mv.getMainValue().getName().equalsIgnoreCase("mnq")) 116 else if (mv.getMainValue().getName().equalsIgnoreCase("mnq"))
114 this.gaugeMnwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue())); 117 this.gaugeMnwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue()));
115 else if (mv.getMainValue().getName().equalsIgnoreCase("mhq")) 118 else if (mv.getMainValue().getName().equalsIgnoreCase("mhq"))
116 this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue())); 119 this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue()));
117 } 120 }
118 if (first) { 121 if (this.firstGauge == null) {
119 this.refGaugeMwPos = this.gaugeMwPos.get(gauge); 122 this.refGaugeMwPos = this.gaugeMwPos.get(gauge);
120 this.refGaugeMnwPos = this.gaugeMnwPos.get(gauge); 123 this.refGaugeMnwPos = this.gaugeMnwPos.get(gauge);
121 this.refGaugeMhwPos = this.gaugeMhwPos.get(gauge); 124 this.refGaugeMhwPos = this.gaugeMhwPos.get(gauge);
122 first = false; 125 this.firstGauge = gauge;
123 } 126 }
124 } 127 }
125 if (this.refGaugeMwPos == null) 128 if (this.refGaugeMwPos == null)
126 this.problems.addProblem("uinfo_salix_calc.warning.missing_mq"); 129 this.problems.addProblem("uinfo_salix_calc.warning.missing_mq");
127 else { 130 else {
165 else { 168 else {
166 scenarios.add(null); 169 scenarios.add(null);
167 } 170 }
168 } 171 }
169 row.putValue(UInfoResultType.customMultiRowColSalixScenarios, scenarios); 172 row.putValue(UInfoResultType.customMultiRowColSalixScenarios, scenarios);
173 row.putValue(GeneralResultType.gaugeLabel, this.riverInfoProvider.findGauge(station));
170 return row; 174 return row;
171 } 175 }
172 176
173 /** 177 /**
174 * Interpolates the W for a station with a fixed (virtual) wst column position 178 * Interpolates the W for a station with a fixed (virtual) wst column position
207 } 211 }
208 final List<Double> noScen = new ArrayList<>(); 212 final List<Double> noScen = new ArrayList<>();
209 noScen.add(null); 213 noScen.add(null);
210 return noScen; 214 return noScen;
211 } 215 }
216
217 /**
218 * Find and return a height (iota, w main value) of a station in a previously calculated result
219 */
220 public double fetchStationHeight(final Calculation problems, final double station, final AbstractResultType resultType,
221 final SalixLineCalculationResult result) {
222
223 // Search the station in the previously calculated result rows
224 final ResultRow stationRow = searchStation(station, result.getRows());
225 if (stationRow != null)
226 return stationRow.getDoubleValue(resultType);
227 return Double.NaN;
228 }
229
230 /**
231 * Searches the row of a station in a result rows collection
232 */
233 private ResultRow searchStation(final double station, final Collection<ResultRow> rows) {
234 for (final ResultRow row : rows) {
235 if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001)
236 return row;
237 }
238 return null;
239 }
212 } 240 }

http://dive4elements.wald.intevation.org