[PATCH 2 of 4] Fixed: no rounding during calculations (Meilenstein-2 2.9)

Wald Commits scm-commit at wald.intevation.org
Fri Sep 28 10:16:40 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1538122266 -7200
# Node ID 83e6acdf8fc6a0ba9593f4637ad8e77333cef576
# Parent  69a7edd7d1e158c416b349d3cc0466677f2c0f8b
Fixed: no rounding during calculations (Meilenstein-2 2.9)

diff -r 69a7edd7d1e1 -r 83e6acdf8fc6 artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractExportContext.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractExportContext.java	Fri Sep 28 10:02:28 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractExportContext.java	Fri Sep 28 10:11:06 2018 +0200
@@ -26,6 +26,7 @@
     private NumberFormat floodDurationFormat = null;
     private NumberFormat salixScenFormat = null;
     private NumberFormat kmFormat = null;
+    private NumberFormat intFormat = null;
 
     /** The CallContext object. */
     private final CallContext context;
@@ -85,6 +86,13 @@
         return this.salixScenFormat;
     }
 
+    public final NumberFormat getIntegerFormatter() {
+        if (this.intFormat == null)
+            this.intFormat = Formatter.getIntegerFormatter(this.context);
+
+        return this.intFormat;
+    }
+
     protected String msg(final String key) {
         return Resources.getMsg(this.context.getMeta(), key, key);
     }
diff -r 69a7edd7d1e1 -r 83e6acdf8fc6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java	Fri Sep 28 10:02:28 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java	Fri Sep 28 10:11:06 2018 +0200
@@ -212,15 +212,6 @@
         @Override
         public String exportValue(final CallContext context, final Object value) {
             final double doubleValue = asDouble(value);
-            String rm;
-            try {
-                rm = getFormatter(context).getRoundingMode().toString();
-            }
-            catch (final Exception e) {
-                rm = "?";
-            }
-            log.trace(String.format("meanBedHeight.exportValue roundingmode: %s value: %f doubleValue: %f formatted to: %s",
-                    rm, value, doubleValue, exportDoubleValue(context, doubleValue)));
             return exportDoubleValue(context, doubleValue);
         }
 
diff -r 69a7edd7d1e1 -r 83e6acdf8fc6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java	Fri Sep 28 10:02:28 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java	Fri Sep 28 10:11:06 2018 +0200
@@ -10,7 +10,6 @@
 package org.dive4elements.river.artifacts.sinfo.flowdepth;
 
 import org.dive4elements.river.artifacts.model.Calculation;
-import org.dive4elements.river.utils.Formatter;
 
 /**
  * @author Gernot Belger
@@ -58,11 +57,11 @@
     }
 
     /**
-     * Calculates a flow depth, rounded to the active scale
+     * Calculates a flow depth
      */
     public static double calcFlowDepth(final double wst, final double bedHeight) {
         if (Double.isNaN(wst) || Double.isInfinite(wst) || Double.isNaN(bedHeight) || Double.isInfinite(bedHeight))
             return Math.max(wst - bedHeight, 0.0);
-        return Math.max(Formatter.roundFlowDepth(wst).subtract(Formatter.roundFlowDepth(bedHeight)).doubleValue(), 0.0);
+        return Math.max(wst - bedHeight, 0.0);
     }
 }
\ No newline at end of file
diff -r 69a7edd7d1e1 -r 83e6acdf8fc6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java	Fri Sep 28 10:02:28 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java	Fri Sep 28 10:11:06 2018 +0200
@@ -16,7 +16,6 @@
 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder;
 import org.dive4elements.river.model.River;
-import org.dive4elements.river.utils.Formatter;
 
 /**
  * @author Gernot Belger
@@ -140,7 +139,7 @@
         if (Double.isNaN(meanBedHeight))
             return TkhCalculateState.NO_BED_HEIGHT;
 
-        final double flowDepth = Formatter.roundFlowDepth(wst).subtract(Formatter.roundFlowDepth(meanBedHeight)).doubleValue();
+        final double flowDepth = wst - meanBedHeight;
         row.putValue(SInfoResultType.flowdepth, flowDepth);
 
         final double discharge = this.dischargeProvider.getDischarge(km);
diff -r 69a7edd7d1e1 -r 83e6acdf8fc6 artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Fri Sep 28 10:02:28 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Fri Sep 28 10:11:06 2018 +0200
@@ -8,8 +8,6 @@
 
 package org.dive4elements.river.utils;
 
-import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.text.DateFormat;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
@@ -385,27 +383,11 @@
         return Formatter.getFormatter(context, FLOWDEPTH_MAX_DIGITS, FLOWDEPTH_MAX_DIGITS);
     }
 
-    /**
-     * Decimal half even rounding of a flow depth value
-     * (ATTENTION: throws an exception for NaN or Infinity!)
-     */
-    public static BigDecimal roundFlowDepth(final double value) {
-        return BigDecimal.valueOf(value).setScale(FLOWDEPTH_MAX_DIGITS, RoundingMode.HALF_EVEN);
-    }
-
     public static NumberFormat getW(final CallContext context) {
         return Formatter.getFormatter(context, 2, 2);
     }
 
     /**
-     * Decimal half even rounding of a W value
-     * (ATTENTION: throws an exception for NaN or Infinity!)
-     */
-    public static BigDecimal roundW(final double value) {
-        return BigDecimal.valueOf(value).setScale(WATERLEVEL_W_MAX_DIGITS, RoundingMode.HALF_EVEN);
-    }
-
-    /**
      * Another waterlevel formatter with fixed digits (always 2)
      */
     public static NumberFormat getWaterlevelW2(final CallMeta meta) {


More information about the Dive4Elements-commits mailing list