comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java @ 9361:2aec052d4088

Refactoring on SalixLineCalculationResult etc., calculation using MQ etc., scenario (regional+supra) csv columns and meta data added
author mschaefer
date Wed, 01 Aug 2018 18:01:11 +0200
parents b3d3c958a594
children 6f7e92c16050
comparison
equal deleted inserted replaced
9360:ddcd52d239cd 9361:2aec052d4088
22 import org.dive4elements.river.artifacts.common.ResultRow; 22 import org.dive4elements.river.artifacts.common.ResultRow;
23 import org.dive4elements.river.artifacts.model.Calculation; 23 import org.dive4elements.river.artifacts.model.Calculation;
24 import org.dive4elements.river.artifacts.model.WstValueTable; 24 import org.dive4elements.river.artifacts.model.WstValueTable;
25 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition; 25 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;
26 import org.dive4elements.river.artifacts.model.WstValueTableFactory; 26 import org.dive4elements.river.artifacts.model.WstValueTableFactory;
27 import org.dive4elements.river.artifacts.sinfo.common.GaugeDischargeValuesFinder;
28 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; 27 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
29 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; 28 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
30 import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper; 29 import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper;
31 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; 30 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
32 import org.dive4elements.river.artifacts.uinfo.common.UInfoResultType; 31 import org.dive4elements.river.artifacts.uinfo.common.UInfoResultType;
33 import org.dive4elements.river.artifacts.uinfo.salix.SalixLineAccess.ScenarioType; 32 import org.dive4elements.river.artifacts.uinfo.salix.SalixLineAccess.ScenarioType;
34 import org.dive4elements.river.model.Gauge; 33 import org.dive4elements.river.model.Gauge;
35 import org.dive4elements.river.model.MainValue; 34 import org.dive4elements.river.model.MainValue;
36 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; 35 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
36 import org.dive4elements.river.utils.Formatter;
37 37
38 /** 38 /**
39 * Calculation of the result rows of the u-info salix line calc mode 39 * Calculation of the result rows of the u-info salix line calc mode
40 * 40 *
41 * @author Matthias Schäfer 41 * @author Matthias Schäfer
63 63
64 /** 64 /**
65 * Calculate the salix line result rows 65 * Calculate the salix line result rows
66 */ 66 */
67 public void execute(final Calculation problems, final UINFOArtifact uinfo, final NavigableMap<Double, List<Double>> rangeScenarios, 67 public void execute(final Calculation problems, final UINFOArtifact uinfo, final NavigableMap<Double, List<Double>> rangeScenarios,
68 final ScenarioType scenarioType, final String[] scenarioLabels, final SalixLineCalculationResults results) { 68 final ScenarioType scenarioType, final String[] scenarioLabels, final String rangeString, final String additionalString,
69 final SalixLineCalculationResults results) {
69 70
70 this.problems = problems; 71 this.problems = problems;
71 this.wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); 72 this.wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver());
72 73
73 fetchGaugeMainValuePositions(); 74 fetchGaugeMainValuePositions();
77 winfo.addStringData("ld_step", "100"); 78 winfo.addStringData("ld_step", "100");
78 for (final double station : new ComputationRangeAccess(winfo).getKms()) { 79 for (final double station : new ComputationRangeAccess(winfo).getKms()) {
79 this.rows.add(createRow(station, rangeScenarios)); 80 this.rows.add(createRow(station, rangeScenarios));
80 } 81 }
81 if (scenarioType == ScenarioType.REGIONAL) 82 if (scenarioType == ScenarioType.REGIONAL)
82 results.addResult(new SalixLineCalculationRegionalResult("Salix", scenarioLabels, this.rows), problems); 83 results.addResult(new SalixLineCalculationRegionalResult("Salix-regional", scenarioLabels, rangeString, additionalString, this.rows), problems);
83 else if (scenarioType == ScenarioType.SUPRAREGIONAL) 84 else if (scenarioType == ScenarioType.SUPRAREGIONAL)
84 results.addResult(new SalixLineCalculationSupraRegionalResult("Salix", this.rows), problems); 85 results.addResult(new SalixLineCalculationSupraRegionalResult("Salix-supra", scenarioLabels, rangeString, additionalString, this.rows), problems);
85 else if (scenarioType == ScenarioType.HISTORICAL) 86 else if (scenarioType == ScenarioType.HISTORICAL)
86 results.addResult(new SalixLineCalculationHistoricalResult("Salix", this.rows), problems); 87 results.addResult(new SalixLineCalculationHistoricalResult("Salix-hist", scenarioLabels, rangeString, additionalString, this.rows), problems);
87 else 88 else
88 results.addResult(new SalixLineCalculationNoScenarioResult("Salix", this.rows), problems); 89 results.addResult(new SalixLineCalculationResult("Salix-simple", this.rows), problems);
89 } 90 }
90 91
91 /** 92 /**
92 * Fetch MW, MNW and MHW of all gauges and determine the wst QPosition for each one 93 * Fetch MQ, MNQ and MHQ of all gauges and determine the wst QPosition for each one
93 */ 94 */
94 private void fetchGaugeMainValuePositions() { 95 private void fetchGaugeMainValuePositions() {
95 this.gaugeMwPos.clear(); 96 this.gaugeMwPos.clear();
96 this.gaugeMnwPos.clear(); 97 this.gaugeMnwPos.clear();
97 this.gaugeMhwPos.clear(); 98 this.gaugeMhwPos.clear();
98 for (final Gauge gauge : this.riverInfoProvider.getGauges()) { 99 for (final Gauge gauge : this.riverInfoProvider.getGauges()) {
99 this.gaugeMwPos.put(gauge, null); 100 this.gaugeMwPos.put(gauge, null);
100 this.gaugeMnwPos.put(gauge, null); 101 this.gaugeMnwPos.put(gauge, null);
101 this.gaugeMhwPos.put(gauge, null); 102 this.gaugeMhwPos.put(gauge, null);
102 final GaugeDischargeValuesFinder finder = GaugeDischargeValuesFinder.loadValues(gauge, this.problems);
103 if (finder == null)
104 continue;
105 final double gaugeKm = gauge.getStation().doubleValue(); 103 final double gaugeKm = gauge.getStation().doubleValue();
106 for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.W)) { 104 for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q)) {
107 if (mv.getMainValue().getName().equalsIgnoreCase("mw")) 105 if (mv.getMainValue().getName().equalsIgnoreCase("mq"))
108 this.gaugeMwPos.put(gauge, this.wst.getQPosition(gaugeKm, finder.getDischarge(mv.getValue().doubleValue()))); 106 this.gaugeMwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue()));
109 else if (mv.getMainValue().getName().equalsIgnoreCase("mnw")) 107 else if (mv.getMainValue().getName().equalsIgnoreCase("mnq"))
110 this.gaugeMnwPos.put(gauge, this.wst.getQPosition(gaugeKm, finder.getDischarge(mv.getValue().doubleValue()))); 108 this.gaugeMnwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue()));
111 else if (mv.getMainValue().getName().equalsIgnoreCase("mhw")) 109 else if (mv.getMainValue().getName().equalsIgnoreCase("mhq"))
112 this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, finder.getDischarge(mv.getValue().doubleValue()))); 110 this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue()));
113 } 111 }
114 } 112 }
115 } 113 }
116 114
117 /** 115 /**
132 row.putValue(SInfoResultType.waterlevel, mnw); 130 row.putValue(SInfoResultType.waterlevel, mnw);
133 row.putValue(SInfoResultType.waterlevel1, mw); 131 row.putValue(SInfoResultType.waterlevel1, mw);
134 row.putValue(SInfoResultType.waterlevel2, mhw); 132 row.putValue(SInfoResultType.waterlevel2, mhw);
135 // Calc salix-line and mw-mnw 133 // Calc salix-line and mw-mnw
136 row.putValue(UInfoResultType.salixline, calcSalix(mhw, mw)); 134 row.putValue(UInfoResultType.salixline, calcSalix(mhw, mw));
137 row.putValue(UInfoResultType.salix_delta_mw, calcMwmnw(mw, mnw)); 135 row.putValue(UInfoResultType.salix_mw_mnw, calcMwmnw(mw, mnw));
138 // Calc scenario values (always all scenario types set, Result variant extracts the fields needed) 136 // Calc scenario values (always all scenario types set, Result variant extracts the fields needed)
139 final List<SalixScenario> scenarios = new ArrayList<>(); 137 final List<SalixScenario> scenarios = new ArrayList<>();
140 final double[] deltaws = getDeltaWs(station, rangeScenarios); 138 final double[] deltaws = getDeltaWs(station, rangeScenarios);
141 for (int i = 0; i <= deltaws.length - 1; i++) { 139 for (int i = 0; i <= deltaws.length - 1; i++) {
142 if (Math.abs(deltaws[i]) < 0.0001) { 140 if (Math.abs(deltaws[i]) > 0.0001) {
143 row.putValue(UInfoResultType.salix_line_scenario, Double.NaN);
144 row.putValue(UInfoResultType.salix_line_scenario_dwspl, 0); // TODO NaN when changed from int to double
145 /* always need to add a member, so the exporter will produce empty columns */
146 scenarios.add(null);
147 } else {
148 final double salix = calcSalix(mhw, mw + deltaws[i]); 141 final double salix = calcSalix(mhw, mw + deltaws[i]);
149 row.putValue(UInfoResultType.salix_line_scenario, salix);
150 row.putValue(UInfoResultType.salix_line_scenario_dwspl, (int) (deltaws[i] * 100));
151 scenarios.add(new SalixScenario((int) (deltaws[i] * 100), salix)); 142 scenarios.add(new SalixScenario((int) (deltaws[i] * 100), salix));
152 } 143 }
144 else {
145 scenarios.add(null);
146 }
153 } 147 }
154 row.putValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl, scenarios); 148 row.putValue(UInfoResultType.customMultiRowColSalixScenarios, scenarios);
155 return row; 149 return row;
156 } 150 }
157 151
158 /** 152 /**
159 * Interpolates the W for a station with a fixed (virtual) wst column position 153 * Interpolates the W for a station with a fixed (virtual) wst column position
167 161
168 /** 162 /**
169 * Calculates the salix value 163 * Calculates the salix value
170 */ 164 */
171 private double calcSalix(final double mhw, final double mw) { 165 private double calcSalix(final double mhw, final double mw) {
172 return mhw - 2.31 - mw; 166 return Formatter.roundW(mhw) - 2.31 - Formatter.roundW(mw);
173 } 167 }
174 168
175 /** 169 /**
176 * Calculates the inverse MW-MNW difference 170 * Calculates the inverse MW-MNW difference
177 */ 171 */
178 private double calcMwmnw(final double mw, final double mnw) { 172 private double calcMwmnw(final double mw, final double mnw) {
179 return mnw - mw; 173 return Formatter.roundW(mnw) - Formatter.roundW(mw);
180 } 174 }
181 175
182 /** 176 /**
183 * Gets the station-specific list of delta-ws of the active scenario, at least with one 0 item in any case 177 * Gets the station-specific list of delta-ws of the active scenario, at least with one 0 item in any case
184 * 178 *

http://dive4elements.wald.intevation.org