[PATCH] Softwaretests...20181219 10.1: changed handling of special cases at km range limits according to added specification by BfG

Wald Commits scm-commit at wald.intevation.org
Tue Feb 12 10:34:57 CET 2019


# HG changeset patch
# User mschaefer
# Date 1549964073 -3600
# Node ID 4c73fe16533dd656783293c5a48a796b4d682e65
# Parent  17414e70746e5d09a12370a963c4b46abcaaae82
Softwaretests...20181219 10.1: changed handling of special cases at km range limits according to added specification by BfG

diff -r 17414e70746e -r 4c73fe16533d artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java	Tue Feb 05 15:51:35 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java	Tue Feb 12 10:34:33 2019 +0100
@@ -329,7 +329,7 @@
                     areas.add(Double.valueOf(0.0));
                 }
                 if (chDepth - getFieldValue(i, BunduResultType.depthFields, j) > 0.0001) {
-                    vExcav += computeMissingVolume(null, null, i, first, last, j, ExcavationMissingAreaComputer.Instance);
+                    vExcav += computeMissingVolume(null, null, i, first, last, j, ExcavationMissingHeightComputer.Instance);
                 }
             }
             final double[] meanBedVolumeArea = computeMeanBedMissingAreaAndVolume(i, first, last);
@@ -352,13 +352,15 @@
         final double dhCurr = heightcomputer.missingHeight(this.rows.get(current), current, first, last, field);
         final double dhPrev = heightcomputer.missingHeight(this.rows.get(current - 1), current - 1, first, last, field);
         final double dhNext = heightcomputer.missingHeight(this.rows.get(current + 1), current + 1, first, last, field);
-        final double kmCurr = missingKm(current);
-        final double kmPrev = missingKm(current - 1);
-        final double kmNext = missingKm(current + 1);
+        final double kmCurr = kmOfRow(current);
+        final double kmPrev = kmOfRow(current - 1);
+        final double kmNext = kmOfRow(current + 1);
         final double width = getFieldValue(current, BunduResultType.missWidthFields, field);
-        final double area1 = Double.isNaN(kmPrev) ? 0.0 : (0.25 * dhPrev + 0.75 * dhCurr) * width;
-        final double area2 = Double.isNaN(kmNext) ? 0.0 : (0.75 * dhCurr + 0.25 * dhNext) * width;
-        final double volume = Double.valueOf((Math.abs(kmCurr - kmPrev) * KM_TO_M / 2 * area1) + (Math.abs(kmNext - kmCurr) * KM_TO_M / 2 * area2));
+        final double area1 = (0.25 * dhPrev + 0.75 * dhCurr) * width;
+        final double dist1 = Double.isNaN(kmPrev) ? 0.0 : Math.abs(kmCurr - kmPrev) * KM_TO_M / 2;
+        final double area2 = (0.75 * dhCurr + 0.25 * dhNext) * width;
+        final double dist2 = Double.isNaN(kmNext) ? 0.0 : Math.abs(kmNext - kmCurr) * KM_TO_M / 2;
+        final double volume = dist1 * area1 + dist2 * area2;
         if (volumes != null)
             volumes.add(volume);
         if (areas != null) {
@@ -371,13 +373,17 @@
     }
 
     /**
-     * Interface for the function that computes the missing height of a field
+     * Interface for the function that computes/gets the missing height of a field
      */
     private interface MissingHeightComputer {
         /**
-         * Gets the missing area of a field and a row if in range, otherwise 0.0
+         * Gets the missing height of a field and a row if in range, otherwise 0.0
          */
         double missingHeight(final ResultRow row, final int rowIndex, final int first, final int last, final int fieldIndex);
+        /**
+         * Gets the mean missing height of a row if in range, otherwise 0.0
+         */
+        double missingMeanHeight(final ResultRow row, final int rowIndex, final int first, final int last);
     }
 
     /**
@@ -393,7 +399,21 @@
         @Override
         public double missingHeight(final ResultRow row, final int rowIndex, final int first, final int last, final int fieldIndex) {
             if ((first <= rowIndex) && (rowIndex <= last)) {
-                return ((List<Double>) row.getValue(BunduResultType.missDepthFields)).get(fieldIndex - 1).doubleValue();
+                final double dh = ((List<Double>) row.getValue(BunduResultType.missDepthFields)).get(fieldIndex - 1).doubleValue();
+                return (!Double.isNaN(dh) ? dh : 0.0);
+            }
+            else
+                return 0.0;
+        }
+
+        /**
+         * Gets the missing mean height of a row if in range, otherwise 0.0
+         */
+        @Override
+        public double missingMeanHeight(final ResultRow row, final int rowIndex, final int first, final int last) {
+            if ((first <= rowIndex) && (rowIndex <= last)) {
+                final double dh = row.getDoubleValue(BunduResultType.missDepthMeanBed);
+                return (!Double.isNaN(dh) ? dh : 0.0);
             }
             else
                 return 0.0;
@@ -403,8 +423,8 @@
     /**
      * Computation of the excavation height of a field
      */
-    private static class ExcavationMissingAreaComputer implements MissingHeightComputer {
-        public static MissingHeightComputer Instance = new ExcavationMissingAreaComputer();
+    private static class ExcavationMissingHeightComputer implements MissingHeightComputer {
+        public static MissingHeightComputer Instance = new ExcavationMissingHeightComputer();
 
         /**
          * Gets the excavation height of a field and a row if in range, otherwise 0.0
@@ -415,7 +435,21 @@
             if ((first <= rowIndex) && (rowIndex <= last)) {
                 final double channeldepth = row.getDoubleValue(BunduResultType.channelDepth) + EXCAVATION_DEPTH;
                 final double fielddepth = ((List<Double>) row.getValue(BunduResultType.depthFields)).get(fieldIndex - 1).doubleValue();
-                return (channeldepth - fielddepth);
+                return (!Double.isNaN(channeldepth - fielddepth) ? Math.max(channeldepth - fielddepth, 0.0) : 0.0);
+            }
+            else
+                return 0.0;
+        }
+
+        /**
+         * Gets the excavation mean height of a row if in range, otherwise 0.0
+         */
+        @Override
+        public double missingMeanHeight(final ResultRow row, final int rowIndex, final int first, final int last) {
+            if ((first <= rowIndex) && (rowIndex <= last)) {
+                final double channeldepth = row.getDoubleValue(BunduResultType.channelDepth) + EXCAVATION_DEPTH;
+                final double flowdepth = row.getDoubleValue(BunduResultType.flowdepthMeanBed);
+                return (!Double.isNaN(channeldepth - flowdepth) ? Math.max(channeldepth - flowdepth, 0.0) : 0.0);
             }
             else
                 return 0.0;
@@ -427,41 +461,29 @@
      */
     private double[] computeMeanBedMissingAreaAndVolume(final int current, final int first, final int last) {
 
-        final double dhCurr = meanBedMissingHeight(current, first, last);
+        final double dhCurr = ActualMissingHeightComputer.Instance.missingMeanHeight(this.rows.get(current), current, first, last);
         if (dhCurr < 0.0001)
             return new double[] { 0.0, 0.0 };
-        final double dhPrev = meanBedMissingHeight(current - 1, first, last);
-        final double dhNext = meanBedMissingHeight(current + 1, first, last);
-        final double kmCurr = missingKm(current);
-        final double kmPrev = missingKm(current - 1);
-        final double kmNext = missingKm(current + 1);
+        final double dhPrev = ActualMissingHeightComputer.Instance.missingMeanHeight(this.rows.get(current - 1), current - 1, first, last);
+        final double dhNext = ActualMissingHeightComputer.Instance.missingMeanHeight(this.rows.get(current + 1), current + 1, first, last);
+        final double kmCurr = kmOfRow(current);
+        final double kmPrev = kmOfRow(current - 1);
+        final double kmNext = kmOfRow(current + 1);
         final double width = this.rows.get(current).getDoubleValue(BunduResultType.channelWidth);
-        final double area1 = Double.isNaN(kmPrev) ? 0.0 : (0.25 * dhPrev + 0.75 * dhCurr) * width;
-        final double area2 = Double.isNaN(kmNext) ? 0.0 : (0.75 * dhCurr + 0.25 * dhNext) * width;
-        final double volume = Double.valueOf((Math.abs(kmCurr - kmPrev) * KM_TO_M / 2 * area1) + (Math.abs(kmNext - kmCurr) * KM_TO_M / 2 * area2));
-        final double area = Double.isNaN(volume) ? Double.NaN : Double.valueOf(area1 + area2);
+        final double area1 = (0.25 * dhPrev + 0.75 * dhCurr) * width;
+        final double dist1 = Double.isNaN(kmPrev) ? 0.0 : Math.abs(kmCurr - kmPrev) * KM_TO_M / 2;
+        final double area2 = (0.75 * dhCurr + 0.25 * dhNext) * width;
+        final double dist2 = Double.isNaN(kmNext) ? 0.0 : Math.abs(kmNext - kmCurr) * KM_TO_M / 2;
+        final double volume = dist1 * area1 + dist2 * area2;
+        final double area = Double.isNaN(volume) ? Double.NaN : area1 + area2;
         return new double[] { volume, area };
     }
 
     /**
-     * Gets the missing height of the mean bed level and a row if in range, otherwise 0.0
+     * Gets the km of a row index if within range, otherwise NaN
      */
-    private double meanBedMissingHeight(final int rowIndex, final int first, final int last) {
-        if ((first <= rowIndex) && (rowIndex <= last)) {
-            final double dh = this.rows.get(rowIndex).getDoubleValue(BunduResultType.channelDepth)
-                    - this.rows.get(rowIndex).getDoubleValue(BunduResultType.flowdepthMeanBed);
-            if (dh > 0.0)
-                return dh;
-            return 0.0;
-        }
-        return 0.0;
-    }
-
-    /**
-     * Gets the km of a row if within range, otherwise NaN
-     */
-    private double missingKm(final int rowIndex) {
-        if ((0 <= rowIndex) && (rowIndex <= this.rows.size() - 1) && (this.rows.get(rowIndex).getValue(BunduResultType.hasMissingDepth) != null))
+    private double kmOfRow(final int rowIndex) {
+        if ((0 <= rowIndex) && (rowIndex <= this.rows.size() - 1)) // && (this.rows.get(rowIndex).getValue(BunduResultType.hasMissingDepth) != null))
             return this.rows.get(rowIndex).getDoubleValue(GeneralResultType.station);
         return Double.NaN;
     }


More information about the Dive4Elements-commits mailing list