changeset 9398:929d645691ae

Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
author mschaefer
date Mon, 13 Aug 2018 17:27:52 +0200
parents 6e7094368e97
children 77367e8da74d
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java
diffstat 4 files changed, 28 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationAccess.java	Mon Aug 13 17:26:33 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationAccess.java	Mon Aug 13 17:27:52 2018 +0200
@@ -44,4 +44,8 @@
     public RiversideChoiceKey getRiverside() {
         return RiversideChoiceKey.fromKey(super.getString("riverside"));
     }
+
+    public boolean getIsWspl() {
+        return super.getBoolean("wspl").booleanValue();
+    }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java	Mon Aug 13 17:26:33 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java	Mon Aug 13 17:27:52 2018 +0200
@@ -20,7 +20,6 @@
 import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
-import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey;
 import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper;
 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
@@ -51,7 +50,7 @@
         final RiverInfo riverInfo = new RiverInfo(river);
         final DoubleRange calcRange = access.getRange();
 
-        final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
+        final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange, true);
         final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name());
         final String label = Resources.getMsg(this.context.getMeta(), access.getRiverside().getKey());
 
@@ -65,7 +64,7 @@
 
         final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange);
 
-        calculateResult(label, calcRange, infoProvider, access.getRiverside(), problems, winfo, results);
+        calculateResult(label, calcRange, infoProvider, access, problems, winfo, results);
 
         return new CalculationResult(results, problems);
     }
@@ -74,10 +73,10 @@
      * Calculates the flood durations of the infrastructures of a km range of a river
      */
     private void calculateResult(final String label, final DoubleRange calcRange, final RiverInfoProvider riverInfoProvider,
-            final RiversideChoiceKey riverside, final Calculation problems, final WINFOArtifact winfo, final FloodDurationCalculationResults results) {
+            final FloodDurationAccess access, final Calculation problems, final WINFOArtifact winfo, final FloodDurationCalculationResults results) {
 
         final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, riverInfoProvider);
-        calculator.execute(problems, label, calcRange, riverside, winfo, results);
+        calculator.execute(problems, label, calcRange, access.getRiverside(), access.getIsWspl(), winfo, results);
     }
 
     /**
@@ -89,7 +88,7 @@
         final FloodDurationAccess access = new FloodDurationAccess(sinfo);
         final River river = access.getRiver();
         final DoubleRange calcRange = access.getRange();
-        final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
+        final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange, true);
 
         final Calculation problems = new Calculation();
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java	Mon Aug 13 17:26:33 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java	Mon Aug 13 17:27:52 2018 +0200
@@ -67,15 +67,12 @@
      * Calculate the infrastructures flood duration result rows
      */
     public void execute(final Calculation problems, final String label, final DoubleRange calcRange, final RiversideChoiceKey riverside,
-            final WINFOArtifact winfo, final FloodDurationCalculationResults results) {
+            final boolean withWspl, final WINFOArtifact winfo, final FloodDurationCalculationResults results) {
 
         // Find all gauges of the calc range, and create the duration finders
         final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>();
-        Gauge firstGauge = null;
         for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) {
             durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems));
-            if (firstGauge == null)
-                firstGauge = gauge;
         }
 
         // Find all infrastructures within the calc range
@@ -92,13 +89,14 @@
         final double[] stationsSorted = sortStations(allStations.keySet());
 
         // Calculate W and Q for all stations and the selected discharge states/waterlevels
-        final WQKms[] wqkmsArray = calculateWsts(winfo, stationsSorted, problems);
+        final WQKms[] wqkmsArray = calculateWsts(winfo, withWspl, stationsSorted, problems);
 
         // Determine discharge state labels of the waterlevels
         updateWstLabels(wqkmsArray, winfo, problems);
 
         final Map<Gauge, List<Double>> gaugeWstDurations = new HashMap<>();
-        calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders);
+        if (withWspl)
+            calcGaugeWstDurations(winfo, new ArrayList<>(durFinders.keySet()), gaugeWstDurations, durFinders);
 
         // Load base wst table (river).wst
         // (should be in cache since already used in calculateWaterlevels (winfo.computeWaterlevelData)
@@ -107,7 +105,7 @@
         // Create the result rows, and calculate and add the flood durations etc.
         for (int i = 0; i <= stationsSorted.length - 1; i++) {
             final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true);
-            final ResultRow row = createRow(stationsSorted[i], gauge, firstGauge, wqkmsArray, gaugeWstDurations.get(gauge), i);
+            final ResultRow row = createRow(stationsSorted[i], wqkmsArray, gaugeWstDurations.get(gauge), i);
             if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null))
                 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wst, durFinders);
             this.rows.add(row);
@@ -214,8 +212,7 @@
     }
 
     /**
-     * Calculate the data for the W and Q lines in the duration curve chart for the infrastructure height and add to result
-     * collection
+     * Find and return the W or Q annotation(s) of a station and a riverside in a previously calculated result
      */
     public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, final AttributeKey riverside,
             final boolean isW, final FloodDurationCalculationResult result) {
@@ -338,7 +335,7 @@
     /**
      * Calculates an array of w-q-longitudinal sections for all artifact W/Q options
      */
-    private WQKms[] calculateWsts(final WINFOArtifact winfo, final double[] stations, final Calculation problems) {
+    private WQKms[] calculateWsts(final WINFOArtifact winfo, final boolean withWspl, final double[] stations, final Calculation problems) {
         // First run may take long, further runs are faster since WstValueTable is in cache then
         // (So funktioniert computeWaterlevelData wohl:
         // Es sucht die Spalte(n) zum Bezugspegel-Q in der W-Q-Tabelle ({river}.wst in Wst etc.),
@@ -348,6 +345,9 @@
         // interpoliert;
         // bei Vorgabe eines W auf freier Strecke wird wohl vorher noch die .wst-Interpolation eingesetzt, um das Q zu bekommen.
 
+        if (!withWspl)
+            return new WQKms[] {};
+
         final CalculationResult wstsData = winfo.computeWaterlevelData(stations);
 
         /* copy all problems */
@@ -410,17 +410,16 @@
     }
 
     /**
-     * Create a result row for a station and its gauge, and add w-q-values as selected
+     * Create a result row for a station, and add w-q-values as selected
      */
-    private ResultRow createRow(final Double station, final Gauge gauge, final Gauge firstGauge, final WQKms[] wqkmsArray, final List<Double> gaugeDurations,
-            final int kmIndex) {
+    private ResultRow createRow(final Double station, final WQKms[] wqkmsArray, final List<Double> gaugeDurations, final int kmIndex) {
 
         final ResultRow row = ResultRow.create();
         row.putValue(GeneralResultType.station, station);
         row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure
         row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure
 
-        final String gaugeLabel = this.riverInfoProvider.findGauge(station, (gauge == firstGauge));
+        final String gaugeLabel = this.riverInfoProvider.findGauge(station);
         row.putValue(GeneralResultType.gaugeLabel, gaugeLabel);
 
         final String location = this.riverInfoProvider.getLocation(station);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java	Mon Aug 13 17:26:33 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java	Mon Aug 13 17:27:52 2018 +0200
@@ -1,11 +1,12 @@
-/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
- * Software engineering by Intevation GmbH
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
  *
  * This file is Free Software under the GNU AGPL (>=v3)
  * and comes with ABSOLUTELY NO WARRANTY! Check out the
  * documentation coming with Dive4Elements River for details.
  */
-
 package org.dive4elements.river.artifacts.sinfo.flood_duration;
 
 import java.awt.Font;
@@ -32,9 +33,8 @@
 import org.w3c.dom.Document;
 
 /**
- * An OutGenerator that generates duration curves.
- *
- * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ * An OutGenerator that generates flood duration curves.
+ * (based upon a copy of DurationCurveGenerator)
  */
 public class FloodDurationCurveGenerator extends XYChartGenerator implements FacetTypes {
     public static enum YAXIS {

http://dive4elements.wald.intevation.org