Mercurial > dive4elements > river
changeset 9759:a83029cc7e6a 3.2.x
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.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 10 Nov 2022 15:39:07 +0100 |
parents | 0a2e1e604f43 |
children | 9bbb29142ddb |
files | artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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; }