Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 9597:5395c6d4ca50
Softwaretests...20181219 7.3: no interpolation of missing bed heights for Uinfo/Salix historical scenario and B&U/Bzws
author | mschaefer |
---|---|
date | Tue, 05 Feb 2019 15:47:58 +0100 |
parents | b9c87bbff6a4 |
children |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java Tue Feb 05 15:43:27 2019 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java Tue Feb 05 15:47:58 2019 +0100 @@ -44,6 +44,8 @@ private final boolean isNull; + private final boolean doInterpolate; + /** * Create bed level finders from a collection of bed levels. */ @@ -52,7 +54,22 @@ final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size()); for (final BedHeight bedHeight : bedHeights) { - final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range); + final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range, true); + result.add(finder); + } + + return result; + } + + /** + * Create not-interpolated bed level finders from a collection of bed levels. + */ + public static Collection<BedHeightsFinder> createScenarioBedHeights(final Calculation problems, final DoubleRange range, + final Collection<BedHeight> bedHeights) { + final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size()); + + for (final BedHeight bedHeight : bedHeights) { + final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range, false); result.add(finder); } @@ -110,7 +127,22 @@ if (bedHeight == null) return null; - return BedHeightsFinder.createBedHeights(problems, bedHeight, range); + return BedHeightsFinder.createBedHeights(problems, bedHeight, range, true); + } + + /** + * Creates a interpolated or not-interpolated {@link BedHeightsFinder} for a dataset from the database, specified by its + * id. + * + * @return <code>null</code> if no bed level with the given id exists. + */ + public static BedHeightsFinder forId(final Calculation problems, final int id, final DoubleRange range, final boolean doInterpolate) { + + final BedHeight bedHeight = BedHeight.getBedHeightById(id); + if (bedHeight == null) + return null; + + return BedHeightsFinder.createBedHeights(problems, bedHeight, range, doInterpolate); } /** @@ -118,14 +150,15 @@ */ public static BedHeightsFinder NullFinder() { final NavigableMap<Double, BedHeightValue> values = new TreeMap<>(); - return new BedHeightsFinder(null, null, values, true); + return new BedHeightsFinder(null, null, values, true, false); } /** * Create a finder for a given bed level. * */ - private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range) { + private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range, + final boolean doInterpolate) { // FIXME: sort by station, but in what direction? // FIXME: using river.getKmUp()? @@ -142,14 +175,16 @@ final BedHeightInfo info = BedHeightInfo.from(bedHeight); - return new BedHeightsFinder(problems, info, values, false); + return new BedHeightsFinder(problems, info, values, false, doInterpolate); } - private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull) { + private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull, + final boolean doInterpolate) { this.info = info; this.values = values; this.problems = problems; this.isNull = isNull; + this.doInterpolate = doInterpolate; } /** @@ -207,13 +242,23 @@ if (floorEntry == null || ceilingEntry == null) return Double.NaN; + // return NaN if value not found and no-interpolation mode, and report once + if (!this.doInterpolate && (floorEntry != ceilingEntry)) { + if (this.problems != null) { + this.problems.addProblem(km, "sinfo.bedheightsfinder.missing_bedheights"); + this.problems = null; + } + return Double.NaN; + } + final double floorKm = floorEntry.getKey().doubleValue(); final double ceilKm = ceilingEntry.getKey().doubleValue(); - /* report once if the interpolation distance exceeds 1000m */ - if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM && this.problems != null) { - this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000); - this.problems = null; + if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM) { + if (this.problems != null) { + this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000); + this.problems = null; + } return Double.NaN; }