comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9266:465347d12990

Station specific calculation of flood duration curve and infrastructure annotations
author mschaefer
date Wed, 18 Jul 2018 12:20:01 +0200
parents e5367900dd6d
children 83ebeb620b5a
comparison
equal deleted inserted replaced
9265:e5367900dd6d 9266:465347d12990
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; 10 package org.dive4elements.river.artifacts.sinfo.flood_duration;
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.Collection;
13 import java.util.HashMap; 14 import java.util.HashMap;
14 import java.util.List; 15 import java.util.List;
15 import java.util.Map; 16 import java.util.Map;
16 import java.util.Set; 17 import java.util.Set;
17 18
116 final String[] mainValueLabels = new String[wqkmsArray.length]; 117 final String[] mainValueLabels = new String[wqkmsArray.length];
117 for (int i = 0; i <= wqkmsArray.length - 1; i++) 118 for (int i = 0; i <= wqkmsArray.length - 1; i++)
118 mainValueLabels[i] = wqkmsArray[i].getName(); 119 mainValueLabels[i] = wqkmsArray[i].getName();
119 results.addResult(new FloodDurationCalculationResult(label, mainValueLabels, this.rows), problems); 120 results.addResult(new FloodDurationCalculationResult(label, mainValueLabels, this.rows), problems);
120 121
121 calcWQDays(problems, stationsSorted[0], AttributeKey.LEFT, winfo, results); 122 // calcWQDays(problems, stationsSorted[0], AttributeKey.LEFT, winfo, results);
122 123 //
123 calcMainValueAnnotations(problems, 0, AttributeKey.LEFT, wqkmsArray, results); 124 // calcMainValueAnnotations(problems, 0, AttributeKey.LEFT, wqkmsArray, results);
124 125 //
125 calcInfrastructureAnnotations(problems, this.rows.get(0), wqkmsArray, results); 126 // calcInfrastructureAnnotations(problems, this.rows.get(0), wqkmsArray, results);
126 } 127 }
127 128
128 /** 129 /**
129 * Calculate duration curve for a station and add to result collection 130 * Calculates the duration curve for a station
130 */ 131 */
131 private void calcWQDays(final Calculation problems, final double station, final AttributeKey riverside, final WINFOArtifact winfo, 132 public WQDay calcWQDays(final Calculation problems, final double station, final WINFOArtifact winfo) {
132 final FloodDurationCalculationResults results) {
133 133
134 // Same processing as in W-Info DurationCurveState 134 // Same processing as in W-Info DurationCurveState
135 winfo.addStringData("ld_locations", Double.toString(station)); 135 winfo.addStringData("ld_locations", Double.toString(station));
136 final CalculationResult res = winfo.getDurationCurveData(); 136 final CalculationResult res = winfo.getDurationCurveData();
137 final WQDay underflow = (WQDay) res.getData(); 137 final WQDay underflow = (WQDay) res.getData();
142 for (int i = 0, j = days.length - 1; i <= days.length - 1; i++, j--) { 142 for (int i = 0, j = days.length - 1; i <= days.length - 1; i++, j--) {
143 days[j] = 365 - underflow.getDay(i); 143 days[j] = 365 - underflow.getDay(i);
144 ws[j] = underflow.getW(i); 144 ws[j] = underflow.getW(i);
145 qs[j] = underflow.getQ(i); 145 qs[j] = underflow.getQ(i);
146 } 146 }
147 results.setDurationCurve(new WQDay(days, ws, qs)); 147 return new WQDay(days, ws, qs);
148 } 148 }
149 149
150 /** 150 /**
151 * Calculate the data for the W and Q main value lines in the duration curve chart and add to result collection 151 * Calculate the data for the W and Q main value lines in the duration curve chart and add to result collection
152 */ 152 */
153 private void calcMainValueAnnotations(final Calculation problems, final int stationIndex, final AttributeKey riverside, 153 public void calcMainValueAnnotations(final Calculation problems, final int stationIndex, final AttributeKey riverside,
154 final WQKms[] wqkmsArray, final FloodDurationCalculationResults results) { 154 final WQKms[] wqkmsArray, final FloodDurationCalculationResults results) {
155 155
156 // Same way as in MainValueWFacet and ..QFacet, but special label handling 156 // Same way as in MainValueWFacet and ..QFacet, but special label handling
157 final List<StickyAxisAnnotation> ws = new ArrayList<>(); 157 final List<StickyAxisAnnotation> ws = new ArrayList<>();
158 final List<StickyAxisAnnotation> qs = new ArrayList<>(); 158 final List<StickyAxisAnnotation> qs = new ArrayList<>();
176 176
177 /** 177 /**
178 * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result 178 * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result
179 * collection 179 * collection
180 */ 180 */
181 private void calcInfrastructureAnnotations(final Calculation problems, final ResultRow row, final WQKms[] wqkmsArray, 181 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station,
182 final FloodDurationCalculationResults results) { 182 final FloodDurationCalculationResult result) {
183 183
184 if (row.getValue(SInfoResultType.infrastructuretype) == null) { 184 // Search the station in the previously calculated result rows and terminate if no infrastructure row found
185 results.setInfrastructureWAnnotation(null); 185 double station1 = station;
186 results.setInfrastructureQAnnotation(null); 186 if (Double.isNaN(station)) {
187 return; 187 for (final ResultRow row : result.getRows()) {
188 station1 = row.getDoubleValue(GeneralResultType.station);
189 break;
190 }
191 }
192 final List<ResultRow> stationRows = searchStation(station1, result.getRows());
193 if (stationRows.isEmpty() || (stationRows.get(0).getValue(SInfoResultType.infrastructuretype) == null)) {
194 return null;
188 } 195 }
189 // Same way as in MainValueWFacet and ..QFacet 196 // Same way as in MainValueWFacet and ..QFacet
197 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
198 for (final ResultRow row : stationRows) {
199 annotations.add(calcWAnnotation(row));
200 annotations.add(calcQAnnotation(row));
201 }
202 return annotations;
203 }
204
205 /**
206 * Searches the one or two rows of a station in a result rows collection
207 */
208 private List<ResultRow> searchStation(final double station, final Collection<ResultRow> rows) {
209 final List<ResultRow> found = new ArrayList<>();
210 for (final ResultRow row : rows) {
211 if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001)
212 break;
213 else if (row.getDoubleValue(GeneralResultType.station) > station - 0.0001)
214 found.add(row);
215 }
216 return found;
217 }
218
219 /**
220 * Calculates the Q annotation lines of an infrastructure
221 */
222 private StickyAxisAnnotation calcQAnnotation(final ResultRow row) {
190 final String label = Resources.getMsg(this.context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure", 223 final String label = Resources.getMsg(this.context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure",
191 "sinfo.chart.flood_duration.curve.infrastructure", 224 "sinfo.chart.flood_duration.curve.infrastructure",
192 SInfoResultType.infrastructuretype.exportValue(this.context, row.getValue(SInfoResultType.infrastructuretype)) 225 SInfoResultType.infrastructuretype.exportValue(this.context, row.getValue(SInfoResultType.infrastructuretype))
193 + ", " + SInfoResultType.riverside.exportValue(this.context, row.getValue(SInfoResultType.riverside))); 226 + ", " + SInfoResultType.riverside.exportValue(this.context, row.getValue(SInfoResultType.riverside)));
194 final StickyAxisAnnotation qAnnotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.floodDischarge), 227 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.floodDischarge),
195 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.Q.idx); 228 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.Q.idx);
196 FloodDurationMainValuesQFacet.setHitPoint(results.getDurationCurve(), qAnnotation); 229 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration));
197 final StickyAxisAnnotation wAnnotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.infrastructureHeight), 230 return annotation;
231 }
232
233 /**
234 * Calculates the W annotation lines of an infrastructure
235 */
236 private StickyAxisAnnotation calcWAnnotation(final ResultRow row) {
237 final String label = Resources.getMsg(this.context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure",
238 "sinfo.chart.flood_duration.curve.infrastructure",
239 SInfoResultType.infrastructuretype.exportValue(this.context, row.getValue(SInfoResultType.infrastructuretype))
240 + ", " + SInfoResultType.riverside.exportValue(this.context, row.getValue(SInfoResultType.riverside)));
241 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.infrastructureHeight),
198 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.W.idx); 242 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.W.idx);
199 FloodDurationMainValuesWFacet.setHitPoint(results.getDurationCurve(), wAnnotation); 243 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration));
200 244 return annotation;
201 results.setInfrastructureQAnnotation(qAnnotation);
202 results.setInfrastructureWAnnotation(wAnnotation);
203 } 245 }
204 246
205 /** 247 /**
206 * Adds to a stations map all stations corresponding to the active range and step 248 * Adds to a stations map all stations corresponding to the active range and step
207 */ 249 */

http://dive4elements.wald.intevation.org