changeset 9599:4c73fe16533d

Softwaretests...20181219 10.1: changed handling of special cases at km range limits according to added specification by BfG
author mschaefer
date Tue, 12 Feb 2019 10:34:33 +0100
parents 17414e70746e
children bf79a865f6df
files artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java
diffstat 1 files changed, 62 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }

http://dive4elements.wald.intevation.org