[PATCH 1 of 2] Do not require identical values when searching for a main value
Wald Commits
scm-commit at wald.intevation.org
Thu Nov 10 15:49:26 CET 2022
# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1668091147 -3600
# Thu Nov 10 15:39:07 2022 +0100
# Branch 3.2.x
# Node ID a83029cc7e6afd3e7198006259600cea890248ac
# Parent 0a2e1e604f43cc2a470a0140b83dc0120f5dd73d
Do not require identical values when searching for a main value
E.g. a value obtained using WQ.getRawValue() is not necessarily
numerically identical, but nevertheless to be considered equal,
to a matching Q main value.
Fixes wrong descriptions in the result of a water level calculation,
where not finding a matching main value led to the value being used
as description instead of the name of the matching main value.
diff -r 0a2e1e604f43 -r a83029cc7e6a artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java Wed Oct 12 16:54:12 2022 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java Thu Nov 10 15:39:07 2022 +0100
@@ -27,6 +27,7 @@
import org.dive4elements.river.model.Gauge;
import org.dive4elements.river.model.MainValue;
import org.dive4elements.river.model.River;
+import org.dive4elements.river.backend.utils.EpsilonComparator;
import org.dive4elements.river.backend.utils.StringUtil;
import gnu.trove.TDoubleArrayList;
@@ -63,6 +64,12 @@
private static Logger log = LogManager.getLogger(RiverUtils.class);
/**
+ * Comparator to compare Q values with Q main values.
+ */
+ private static final EpsilonComparator MAIN_VALUE_Q_COMP =
+ new EpsilonComparator(1e-3);
+
+ /**
* Enum that represents the 5 possible WQ modes in FLYS. The 5 values are
* <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>.
*/
@@ -574,17 +581,15 @@
public static String getNamedMainValue(Gauge gauge, double value) {
List<MainValue> mainValues = gauge.getMainValues();
- log.debug("Search named main value for: " + value);
for (MainValue mv: mainValues) {
- if (mv.getValue().doubleValue() == value) {
- log.debug("Found named main value: "
- + mv.getMainValue().getName());
+ if (MAIN_VALUE_Q_COMP.compare(
+ mv.getValue().doubleValue(), value) == 0
+ ) {
return mv.getMainValue().getName();
}
}
- log.debug("Did not find a named main value for: " + value);
return null;
}
More information about the Dive4Elements-commits
mailing list