Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java @ 8993:0adc6d04de95
SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
author | gernotbelger |
---|---|
date | Wed, 11 Apr 2018 14:09:13 +0200 |
parents | b194fa64506a |
children | d5802f22e4f5 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java Fri Apr 06 11:55:36 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java Wed Apr 11 14:09:13 2018 +0200 @@ -23,7 +23,7 @@ import org.dive4elements.river.artifacts.sinfo.common.SInfoResultRow; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthUtils; -import org.dive4elements.river.artifacts.sinfo.flowdepthminmax.FlowDepthMinMaxAccess.MinMaxIdPair; +import org.dive4elements.river.artifacts.sinfo.flowdepth.WstSoundingIdPair; import org.dive4elements.river.artifacts.sinfo.tkhcalculation.DischargeValuesFinder; import org.dive4elements.river.artifacts.sinfo.tkhcalculation.WaterlevelValuesFinder; import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder; @@ -55,7 +55,7 @@ final River river = access.getRiver(); final RiverInfo riverInfo = new RiverInfo(river); - final Collection<MinMaxIdPair> minMaxPairs = access.getMinMaxPairs(); + final Collection<WstSoundingIdPair> minMaxPairs = access.getMinMaxPairs(); final DoubleRange calcRange = access.getRange(); @@ -68,7 +68,7 @@ final FlowDepthMinMaxCalculationResults results = new FlowDepthMinMaxCalculationResults(calcModeLabel, user, riverInfo, calcRange); - for (final MinMaxIdPair minMaxPair : minMaxPairs) { + for (final WstSoundingIdPair minMaxPair : minMaxPairs) { final FlowDepthMinMaxCalculationResult result = calculateResult(calcRange, minMaxPair, problems, infoProvider); results.addResult(result, problems); } @@ -81,20 +81,16 @@ * * @param infoProvider */ - private FlowDepthMinMaxCalculationResult calculateResult(final DoubleRange calcRange, final MinMaxIdPair minMaxPair, final Calculation problems, + private FlowDepthMinMaxCalculationResult calculateResult(final DoubleRange calcRange, final WstSoundingIdPair minMaxPair, final Calculation problems, final RiverInfoProvider infoProvider) { /* access real input data from database */ final String wstId = minMaxPair.getWstId(); - // FIXME: bfg überzeugen dass man immer nur pärchen auswählen kann --> min/max id ist gleich! + final String soundingId = minMaxPair.getSoundingId(); - final String minSoundingId = minMaxPair.getMinSoundingId(); - final String maxSoundingId = minMaxPair.getMaxSoundingId(); - - final BedHeightsFinder minBedHeight = minSoundingId == null ? null : BedHeightsFinder.forId(this.context, minSoundingId, calcRange, problems); - final BedHeightsFinder maxBedHeight = maxSoundingId == null ? null : BedHeightsFinder.forId(this.context, maxSoundingId, calcRange, problems); - if (minBedHeight == null && maxBedHeight == null) + final BedHeightsFinder bedHeight = BedHeightsFinder.forId(this.context, soundingId, calcRange, problems); + if (bedHeight == null) return null; /* REMARK: fetch ALL wst kms, because we want to determine the original reference gauge */ @@ -102,11 +98,13 @@ if (waterlevel == null) return null; - final String label = createLabel(waterlevel, minBedHeight, maxBedHeight); + final String label = createLabel(waterlevel, bedHeight); final WKms wstKms = waterlevel.getWkms(); - final int soundingYear = checkSoundingYear(minBedHeight, maxBedHeight, problems); + final BedHeightInfo bedHeightInfo = bedHeight.getInfo(); + + final int soundingYear = bedHeightInfo.getYear(); FlowDepthUtils.checkYearDifference(label, waterlevel.getYear(), soundingYear, problems); /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */ @@ -119,28 +117,24 @@ final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wstKms); final String waterlevelLabel = waterlevel.getName(); - final String soundingLabel = buildSoundingLabel(minBedHeight, maxBedHeight); + final String soundingLabel = bedHeightInfo.getDescription(); /* real calculation loop */ final Collection<SInfoResultRow> rows = new ArrayList<>(); - // FIXME: we use the stations of one of the bed heights atm, because we probably will later use only data from one bed heights datasets! - final Collection<Double> stations = minBedHeight == null ? maxBedHeight.getStations() : minBedHeight.getStations(); + final Collection<Double> stations = bedHeight.getStations(); for (final double station : stations) { if (calcRange.containsDouble(station)) { final double wst = waterlevelProvider.getWaterlevel(station); final double discharge = dischargeProvider.getDischarge(station); - final double minBedHeightValue = minBedHeight == null ? Double.NaN : minBedHeight.getMeanBedHeight(station); - final double maxBedHeightValue = maxBedHeight == null ? Double.NaN : maxBedHeight.getMeanBedHeight(station); + final double minBedHeightValue = bedHeight.getMinBedHeight(station); + final double maxBedHeightValue = bedHeight.getMaxBedHeight(station); + final double meanBedHeight = bedHeight.getMeanBedHeight(station); - final double minFlowDepth = wst - minBedHeightValue; - final double maxFlowDepth = wst - maxBedHeightValue; - - // FIXME: unclear what is meant here... - // FIXME: this will simply the bed height of 'the' bed height if we reduce this to simply using one sounding dataset - final double meanBedHeight = Double.NaN; + final double minFlowDepth = wst - maxBedHeightValue; + final double maxFlowDepth = wst - minBedHeightValue; // REMARK: access the location once only during calculation final String location = riverInfoProvider.getLocation(station); @@ -167,52 +161,14 @@ } } - final BedHeightInfo minBedHeightInfo = minBedHeight == null ? null : minBedHeight.getInfo(); - final BedHeightInfo maxBedHeightInfo = maxBedHeight == null ? null : maxBedHeight.getInfo(); - - return new FlowDepthMinMaxCalculationResult(label, wstInfo, minBedHeightInfo, maxBedHeightInfo, rows); - } - - private String buildSoundingLabel(final BedHeightsFinder minBedHeight, final BedHeightsFinder maxBedHeight) { - - if (minBedHeight == null) - return maxBedHeight.getInfo().getDescription(); - - if (maxBedHeight == null) - return minBedHeight.getInfo().getDescription(); - - return String.format("%s / %s", minBedHeight.getInfo().getDescription(), maxBedHeight.getInfo().getDescription()); + return new FlowDepthMinMaxCalculationResult(label, wstInfo, bedHeightInfo, rows); } - private String createLabel(final WaterlevelData waterlevel, final BedHeightsFinder minBedHeight, final BedHeightsFinder maxBedHeight) { - - final StringBuilder buffer = new StringBuilder(waterlevel.getName()); - - if (minBedHeight != null) - buffer.append(" - "). // - append(minBedHeight.getInfo().getDescription()); - - if (maxBedHeight != null) - buffer.append(" - "). // - append(maxBedHeight.getInfo().getDescription()); - - return buffer.toString(); - } + private String createLabel(final WaterlevelData waterlevel, final BedHeightsFinder bedHeight) { - private int checkSoundingYear(final BedHeightsFinder minBedHeight, final BedHeightsFinder maxBedHeight, final Calculation problems) { - - if (maxBedHeight == null) - return minBedHeight.getInfo().getYear(); - - if (minBedHeight == null) - return maxBedHeight.getInfo().getYear(); - - final int minYear = minBedHeight.getInfo().getYear(); - final int maxYear = minBedHeight.getInfo().getYear(); - - if (minYear != maxYear) - problems.addProblem("sinfo.flowdepthminmaxcalculation.soundingyear.different"); - - return minYear; + return new StringBuilder(waterlevel.getName()). // + append(" - "). // + append(bedHeight.getInfo().getDescription()). // + toString(); } } \ No newline at end of file