Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 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 | a41f9c355204 |
children | c088f7a5797d |
comparison
equal
deleted
inserted
replaced
9758:0a2e1e604f43 | 9759:a83029cc7e6a |
---|---|
25 import org.dive4elements.river.artifacts.states.WaterlevelSelectState; | 25 import org.dive4elements.river.artifacts.states.WaterlevelSelectState; |
26 import org.dive4elements.river.backend.SessionFactoryProvider; | 26 import org.dive4elements.river.backend.SessionFactoryProvider; |
27 import org.dive4elements.river.model.Gauge; | 27 import org.dive4elements.river.model.Gauge; |
28 import org.dive4elements.river.model.MainValue; | 28 import org.dive4elements.river.model.MainValue; |
29 import org.dive4elements.river.model.River; | 29 import org.dive4elements.river.model.River; |
30 import org.dive4elements.river.backend.utils.EpsilonComparator; | |
30 import org.dive4elements.river.backend.utils.StringUtil; | 31 import org.dive4elements.river.backend.utils.StringUtil; |
31 | 32 |
32 import gnu.trove.TDoubleArrayList; | 33 import gnu.trove.TDoubleArrayList; |
33 import gnu.trove.TIntArrayList; | 34 import gnu.trove.TIntArrayList; |
34 import gnu.trove.TLongArrayList; | 35 import gnu.trove.TLongArrayList; |
59 @Deprecated | 60 @Deprecated |
60 public class RiverUtils { | 61 public class RiverUtils { |
61 | 62 |
62 /** The log that is used in this utility. */ | 63 /** The log that is used in this utility. */ |
63 private static Logger log = LogManager.getLogger(RiverUtils.class); | 64 private static Logger log = LogManager.getLogger(RiverUtils.class); |
65 | |
66 /** | |
67 * Comparator to compare Q values with Q main values. | |
68 */ | |
69 private static final EpsilonComparator MAIN_VALUE_Q_COMP = | |
70 new EpsilonComparator(1e-3); | |
64 | 71 |
65 /** | 72 /** |
66 * Enum that represents the 5 possible WQ modes in FLYS. The 5 values are | 73 * Enum that represents the 5 possible WQ modes in FLYS. The 5 values are |
67 * <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>. | 74 * <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>. |
68 */ | 75 */ |
572 } | 579 } |
573 | 580 |
574 | 581 |
575 public static String getNamedMainValue(Gauge gauge, double value) { | 582 public static String getNamedMainValue(Gauge gauge, double value) { |
576 List<MainValue> mainValues = gauge.getMainValues(); | 583 List<MainValue> mainValues = gauge.getMainValues(); |
577 log.debug("Search named main value for: " + value); | |
578 | 584 |
579 for (MainValue mv: mainValues) { | 585 for (MainValue mv: mainValues) { |
580 if (mv.getValue().doubleValue() == value) { | 586 if (MAIN_VALUE_Q_COMP.compare( |
581 log.debug("Found named main value: " | 587 mv.getValue().doubleValue(), value) == 0 |
582 + mv.getMainValue().getName()); | 588 ) { |
583 return mv.getMainValue().getName(); | 589 return mv.getMainValue().getName(); |
584 } | 590 } |
585 } | 591 } |
586 | 592 |
587 log.debug("Did not find a named main value for: " + value); | |
588 return null; | 593 return null; |
589 } | 594 } |
590 | 595 |
591 | 596 |
592 /** | 597 /** |