diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9229:0dcd1cd41915

Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
author mschaefer
date Thu, 05 Jul 2018 16:49:42 +0200
parents 0fc9c82e744e
children d47f6641f597
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java	Thu Jul 05 13:46:36 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java	Thu Jul 05 16:49:42 2018 +0200
@@ -27,7 +27,6 @@
 import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.WQKms;
 import org.dive4elements.river.artifacts.sinfo.common.GaugeDurationValuesFinder;
-import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder;
 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder;
@@ -35,7 +34,6 @@
 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder;
 import org.dive4elements.river.model.Attribute.AttributeKey;
 import org.dive4elements.river.model.Gauge;
-import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
 import org.dive4elements.river.model.sinfo.InfrastructureValue;
 
 import gnu.trove.TDoubleArrayList;
@@ -82,17 +80,19 @@
         // Merge all stations (range/step, borders of gauge ranges, infrastructures)
         final Map<Double, InfrastructureValue> allStations = new HashMap<>();
         final Map<Double, InfrastructureValue> secondBank = new HashMap<>(); // any second infrastructure in case of both-banks-option
-        // FIXME: check, do we really need all stations? compare with tkh...
         addRangeStations(allStations, winfo);
         addGaugeLimits(allStations, durFinders.keySet(), calcRange.getMinimumDouble(), calcRange.getMaximumDouble());
         addInfrastructures(allStations, secondBank, infras);
         final double[] stationsSorted = sortStations(allStations.keySet());
 
         // Calculate W and Q for all stations and the selected discharge states
+        // TODO Laut Herrn Reiß: Q und D jeweils konstant für jedes Pegel-Intervall, Q-Änderungen (Zuflüsse etc.) aus .wst
+        // ignorieren
         final WQKms[] wqkmsArray = calculateWaterlevels(winfo, stationsSorted, problems);
 
         // Determine discharge state labels of the main values
-        final String[] mainValueLabels = findMainValueLabels(wqkmsArray, winfo.getQs(), firstGauge, problems);
+        final WaterlevelDescriptionBuilder wdescBuilder = new WaterlevelDescriptionBuilder(winfo, this.context);
+        final String[] mainValueLabels = findMainValueLabels(wqkmsArray, winfo.getQs(), wdescBuilder, problems);
 
         // Create a finder for Q in the {river}.wst km-w-q table
         final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(),
@@ -103,7 +103,7 @@
         // Calculate the durations and create the result rows
         for (int i = 0; i <= stationsSorted.length - 1; i++) {
             final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true);
-            final ResultRow row = createRow(descBuilder, stationsSorted[i], gauge, wqkmsArray, durFinders.get(gauge), i);
+            final ResultRow row = createRow(descBuilder, stationsSorted[i], gauge, firstGauge, wqkmsArray, durFinders.get(gauge), i);
             if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null))
                 calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wqFinder, durFinders);
             this.rows.add(row);
@@ -171,12 +171,13 @@
         // REMARK aus TkhCalculation - move to WinfoArtifactWrapper?
         // TODO das ist ziemlich langsam - durch den WQBaseTableFinder ersetzen? (vorher W-Optionen in Q umrechnen)
         // (So funktioniert computeWaterlevelData wohl:
-        // Es sucht die Spalte(n) zum Bezugspegel-Q in der W-Q-Tabelle ({river}.wst in Wst etc.)
-        // und interpoliert für diese horizontale Tabellenposition jeweils die vertikale Tabellenposition der station;
+        // Es sucht die Spalte(n) zum Bezugspegel-Q in der W-Q-Tabelle ({river}.wst in Wst etc.),
+        // interpoliert die horizontale Tabellenposition (Q) und dann die vertikale Tabellenposition der station;
         // das ergibt das W einer station für einen Abflusszustand;
         // bei Vorgabe eines Pegel-W wird vorher anhand der W-Q-Tabelle des Pegels ({gauge}.at in DischargeTable) das Q
         // interpoliert;
-        // bei Vorgabe eines W auf freier Strecke wird wohl vorher noch die .wst-Interpolation eingesetzt.
+        // bei Vorgabe eines W auf freier Strecke wird wohl vorher noch die .wst-Interpolation eingesetzt, um das Q zu bekommen.
+
         final CalculationResult waterlevelData = winfo.computeWaterlevelData(stations);
 
         /* copy all problems */
@@ -191,31 +192,14 @@
     }
 
     /**
-     * Determines the discharge state labels for the selected Q or W values
+     * Determines the waterlevel/discharge state labels for the selected Q or W values
      */
-    // FIXME: use WaterlevelDescriptionBuilder instead!
-    private String[] findMainValueLabels(final WQKms[] wqkmsArray, final double[] qs, final Gauge gauge, final Calculation problems) {
+    private String[] findMainValueLabels(final WQKms[] wqkmsArray, final double[] qs, final WaterlevelDescriptionBuilder descBuilder,
+            final Calculation problems) {
 
         final String[] mainValueLabels = new String[wqkmsArray.length];
-        if (wqkmsArray.length >= 1) {
-
-            // FIXME
-            // WaterlevelDescriptionBuilder builder = new WaterlevelDescriptionBuilder(artifact, context);
-
-            // Labels like Q=123 or W=123
-            for (int i = 0; i <= wqkmsArray.length - 1; i++) {
-                // FIXME
-                // String label = builder.getDesc(wqkmsArray[i]);
-
-                mainValueLabels[i] = wqkmsArray[i].getName();
-            }
-            // Replace labels for named main Q values
-            final GaugeMainValueFinder zoneFinder = GaugeMainValueFinder.loadValues(MainValueTypeKey.Q, gauge, problems);
-            if ((zoneFinder != null) && (qs != null)) {
-                for (int i = 0; i <= qs.length - 1; i++)
-                    mainValueLabels[i] = zoneFinder.findExactZoneName(qs[i], mainValueLabels[i]);
-            }
-        }
+        for (int i = 0; i <= wqkmsArray.length - 1; i++)
+            mainValueLabels[i] = descBuilder.getDesc(wqkmsArray[i]);
         return mainValueLabels;
     }
 
@@ -224,16 +208,15 @@
      *
      * @param descBuilder
      */
-    private ResultRow createRow(final WaterlevelDescriptionBuilder descBuilder, final Double station, final Gauge gauge, final WQKms[] wqkmsArray,
-            final GaugeDurationValuesFinder durationFinder, final int kmIndex) {
+    private ResultRow createRow(final WaterlevelDescriptionBuilder descBuilder, final Double station, final Gauge gauge, final Gauge firstGauge,
+            final WQKms[] wqkmsArray, final GaugeDurationValuesFinder durationFinder, 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
 
-        // row.putValue(SInfoResultType.gaugeLabel, gauge.getName());
-        final String gaugeLabel = this.riverInfoProvider.findGauge(station);
+        final String gaugeLabel = this.riverInfoProvider.findGauge(station, (gauge == firstGauge));
         row.putValue(SInfoResultType.gaugeLabel, gaugeLabel);
 
         final String location = this.riverInfoProvider.getLocation(station);
@@ -265,7 +248,7 @@
         final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight());
         final double qOut = Double.isInfinite(q) ? Double.NaN : q;
         final double dur = underflowDaysToOverflowDays(durFinders.get(gauge).getDuration(q));
-        row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey().getName()); // TODO i18n
+        row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey());
         row.putValue(SInfoResultType.floodDuration, dur);
         row.putValue(SInfoResultType.floodDischarge, qOut);
         row.putValue(SInfoResultType.infrastructureHeight, infrastructure.getHeight());

http://dive4elements.wald.intevation.org