comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9376:f318359b81a2

S-Info flood duration theme rename, and more infrastructure themes in the duration curve
author mschaefer
date Fri, 03 Aug 2018 17:02:38 +0200
parents 5ce50640688c
children 929d645691ae
comparison
equal deleted inserted replaced
9375:a0a2e68a1e11 9376:f318359b81a2
164 for (final ResultRow row : result.getAllRows()) { 164 for (final ResultRow row : result.getAllRows()) {
165 station1 = row.getDoubleValue(GeneralResultType.station); 165 station1 = row.getDoubleValue(GeneralResultType.station);
166 break; 166 break;
167 } 167 }
168 } 168 }
169 final List<ResultRow> stationRows = searchStation(station1, result.getAllRows()); 169 final List<ResultRow> stationRows = searchStation(station1, AttributeKey.NONE, result.getAllRows());
170 if (stationRows.isEmpty()) { 170 if (stationRows.isEmpty()) {
171 return new ArrayList<>(); 171 return new ArrayList<>();
172 } 172 }
173 final ResultRow row = stationRows.get(0); 173 final ResultRow row = stationRows.get(0);
174 final List<StickyAxisAnnotation> annotations = new ArrayList<>(); 174 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
194 for (final ResultRow row : result.getAllRows()) { 194 for (final ResultRow row : result.getAllRows()) {
195 station1 = row.getDoubleValue(GeneralResultType.station); 195 station1 = row.getDoubleValue(GeneralResultType.station);
196 break; 196 break;
197 } 197 }
198 } 198 }
199 final List<ResultRow> stationRows = searchStation(station1, result.getAllRows()); 199 final List<ResultRow> stationRows = searchStation(station1, AttributeKey.NONE, result.getAllRows());
200 if (stationRows.isEmpty()) { 200 if (stationRows.isEmpty()) {
201 return new ArrayList<>(); 201 return new ArrayList<>();
202 } 202 }
203 final List<StickyAxisAnnotation> annotations = new ArrayList<>(); 203 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
204 final ResultRow row = stationRows.get(0); 204 final ResultRow row = stationRows.get(0);
215 215
216 /** 216 /**
217 * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result 217 * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result
218 * collection 218 * collection
219 */ 219 */
220 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, 220 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, final AttributeKey riverside,
221 final FloodDurationCalculationResult result) { 221 final boolean isW, final FloodDurationCalculationResult result) {
222 222
223 // Search the station in the previously calculated result rows and terminate if no infrastructure row found 223 // Search the station in the previously calculated result rows and terminate if no infrastructure row found
224 double station1 = station; 224 double station1 = station;
225 if (Double.isNaN(station)) { 225 if (Double.isNaN(station)) {
226 for (final ResultRow row : result.getRows()) { 226 for (final ResultRow row : result.getRows()) {
227 station1 = row.getDoubleValue(GeneralResultType.station); 227 if (row.getValue(SInfoResultType.riverside) == riverside) {
228 break; 228 station1 = row.getDoubleValue(GeneralResultType.station);
229 } 229 break;
230 } 230 }
231 final List<ResultRow> stationRows = searchStation(station1, result.getRows()); 231 }
232 }
233 final List<ResultRow> stationRows = searchStation(station1, riverside, result.getRows());
232 if (stationRows.isEmpty() || (stationRows.get(0).getValue(SInfoResultType.infrastructuretype) == null)) { 234 if (stationRows.isEmpty() || (stationRows.get(0).getValue(SInfoResultType.infrastructuretype) == null)) {
233 return new ArrayList<>(); 235 return new ArrayList<>();
234 } 236 }
235 // Same way as in MainValueWFacet and ..QFacet 237 // Same way as in MainValueWFacet and ..QFacet
236 final List<StickyAxisAnnotation> annotations = new ArrayList<>(); 238 final List<StickyAxisAnnotation> annotations = new ArrayList<>();
237 for (final ResultRow row : stationRows) { 239 for (final ResultRow row : stationRows) {
238 annotations.add(calcInfrastructureWAnnotation(row)); 240 if (isW)
239 annotations.add(calcInfrastructureQAnnotation(row)); 241 annotations.add(calcInfrastructureWAnnotation(row));
242 else
243 annotations.add(calcInfrastructureQAnnotation(row));
240 } 244 }
241 return annotations; 245 return annotations;
242 } 246 }
243 247
244 /** 248 /**
245 * Searches the one or two rows of a station in a result rows collection 249 * Searches the one or two rows of a station in a result rows collection
246 */ 250 */
247 private List<ResultRow> searchStation(final double station, final Collection<ResultRow> rows) { 251 private List<ResultRow> searchStation(final double station, final AttributeKey riverside, final Collection<ResultRow> rows) {
248 final List<ResultRow> found = new ArrayList<>(); 252 final List<ResultRow> found = new ArrayList<>();
249 for (final ResultRow row : rows) { 253 for (final ResultRow row : rows) {
250 if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001) 254 if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001)
251 break; 255 break;
252 else if (row.getDoubleValue(GeneralResultType.station) > station - 0.0001) 256 else if ((row.getDoubleValue(GeneralResultType.station) > station - 0.0001)
257 && ((riverside == AttributeKey.NONE) || (row.getValue(SInfoResultType.riverside) == riverside)))
253 found.add(row); 258 found.add(row);
254 } 259 }
255 return found; 260 return found;
256 } 261 }
257 262

http://dive4elements.wald.intevation.org