diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java @ 9394:439699ff9b2d

Added U-Info iota (prev. salix) calculation for historical scenario
author mschaefer
date Fri, 10 Aug 2018 17:31:46 +0200
parents 8ae7137b67d7
children 6e7094368e97
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java	Fri Aug 10 17:07:30 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java	Fri Aug 10 17:31:46 2018 +0200
@@ -139,7 +139,7 @@
 
         final ResultRow row = ResultRow.create();
         row.putValue(GeneralResultType.station, station);
-        // Find station's gauge
+        // Find station's gauge (obsolete version which calculates gauge-wise)
         // final Gauge gauge = this.riverInfoProvider.getGauge(station, true);
         // Interpolate mnw, mw, and mhw
         // final double mnw = interpolateW(station, this.gaugeMnwPos.get(gauge));
@@ -156,11 +156,11 @@
         row.putValue(UInfoResultType.salix_mw_mnw, calcMwmnw(mw, mnw));
         // Calc scenario values (always all scenario types set, Result variant extracts the fields needed)
         final List<SalixScenario> scenarios = new ArrayList<>();
-        final double[] deltaws = getDeltaWs(station, rangeScenarios);
-        for (int i = 0; i <= deltaws.length - 1; i++) {
-            if (Math.abs(deltaws[i]) > 0.0001) {
-                final double salix = calcSalix(mhw, mw + deltaws[i]);
-                scenarios.add(new SalixScenario((int) (deltaws[i] * 100), salix));
+        final List<Double> deltaws = getDeltaWs(station, rangeScenarios);
+        for (final Double deltaw : deltaws) {
+            if (deltaw != null) {
+                final double salix = calcSalix(mhw, mw + deltaw);
+                scenarios.add(new SalixScenario((int) (deltaw * 100), salix));
             }
             else {
                 scenarios.add(null);
@@ -198,16 +198,15 @@
     }
 
     /**
-     * Gets the station-specific list of delta-ws of the active scenario, at least with one 0 item in any case
+     * Gets the station-specific list of delta-ws of the active scenario, at least with one null item in any case
      */
-    private double[] getDeltaWs(final double station, final NavigableMap<Double, List<Double>> rangeScenarios) {
+    private List<Double> getDeltaWs(final double station, final NavigableMap<Double, List<Double>> rangeScenarios) {
         final Entry<Double, List<Double>> stationScenarios = rangeScenarios.floorEntry(station);
-        if (stationScenarios == null)
-            return new double[] { 0.0 };
-
-        final double[] deltaws = new double[stationScenarios.getValue().size()];
-        for (int i = 0; i <= stationScenarios.getValue().size() - 1; i++)
-            deltaws[i] = stationScenarios.getValue().get(i);
-        return deltaws;
+        if (stationScenarios != null) {
+            return stationScenarios.getValue();
+        }
+        final List<Double> noScen = new ArrayList<>();
+        noScen.add(null);
+        return noScen;
     }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org