Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java @ 8946:5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
author | gernotbelger |
---|---|
date | Tue, 13 Mar 2018 18:49:33 +0100 |
parents | 82998242ba84 |
children | a4f1ac81f26d |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java Tue Mar 13 09:55:53 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java Tue Mar 13 18:49:33 2018 +0100 @@ -13,16 +13,11 @@ import java.util.Collection; import org.apache.commons.lang.math.DoubleRange; -import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; -import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; -import org.dive4elements.river.artifacts.sinfo.tkhcalculation.DischargeValuesFinder; import org.dive4elements.river.artifacts.sinfo.tkhcalculation.Tkh; import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator; import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder; import org.dive4elements.river.artifacts.sinfo.util.WstInfo; -import org.dive4elements.river.utils.DoubleUtil; /** * @author Gernot Belger @@ -31,33 +26,26 @@ private final Collection<FlowDepthRow> rows = new ArrayList<>(); - private final DischargeValuesFinder dischargeProvider; - private final BedHeightsFinder bedHeight; private final TkhCalculator tkhCalculator; - private final PolynomialSplineFunction wstInterpolator; - private final RiverInfoProvider riverInfoProvider; private final String bedHeightLabel; private final String wstLabel; - public FlowDepthCalculator(final RiverInfoProvider riverInfoProvider, final WKms wstKms, - final DischargeValuesFinder dischargeProvider, final BedHeightsFinder bedHeight, final TkhCalculator tkhCalculator) { + public FlowDepthCalculator(final RiverInfoProvider riverInfoProvider, final String wstLabel, final BedHeightsFinder bedHeight, + final TkhCalculator tkhCalculator) { this.riverInfoProvider = riverInfoProvider; + this.wstLabel = wstLabel; - this.dischargeProvider = dischargeProvider; this.bedHeight = bedHeight; this.tkhCalculator = tkhCalculator; - this.wstInterpolator = DoubleUtil.getLinearInterpolator(wstKms.allKms(), wstKms.allWs()); - this.bedHeightLabel = bedHeight.getInfo().getDescription(); - this.wstLabel = wstKms.getName(); } public FlowDepthCalculationResult execute(final String label, final WstInfo wstInfo, final DoubleRange calcRange) { @@ -68,40 +56,21 @@ calculateResultRow(station); } - return new FlowDepthCalculationResult(label, wstInfo, this.bedHeight.getInfo(), this.tkhCalculator != null, this.rows); + final boolean hasTkh = this.tkhCalculator.hasTkh(); + + return new FlowDepthCalculationResult(label, wstInfo, this.bedHeight.getInfo(), hasTkh, this.rows); } private void calculateResultRow(final double station) { - try { - // FIXME: check out of range of waterlevel? - final double wst = this.wstInterpolator.value(station); - - final Tkh tkh = calculateTkh(station, wst); - - // REMARK: access the location once only during calculation - final String location = this.riverInfoProvider.getLocation(station); - - // REMARK: access the gauge once only during calculation - final String gaugeLabel = this.riverInfoProvider.findGauge(station); + final Tkh tkh = this.tkhCalculator.getTkh(station); - this.rows.add(new FlowDepthRow(tkh, this.wstLabel, gaugeLabel, this.bedHeightLabel, location)); - } - catch (final FunctionEvaluationException e) { - /* should only happen if out of range */ - e.printStackTrace(); - /* simply ignore */ - } - } + // REMARK: access the location once only during calculation + final String location = this.riverInfoProvider.getLocation(station); - private Tkh calculateTkh(final double station, final double wst) throws FunctionEvaluationException { - if (this.tkhCalculator == null) { - final double discharge = this.dischargeProvider.getDischarge(station); - final double meanBedHeight = this.bedHeight.getMeanBedHeight(station); - final double flowDepth = wst - meanBedHeight; - return new Tkh(station, wst, meanBedHeight, flowDepth, discharge); - } + // REMARK: access the gauge once only during calculation + final String gaugeLabel = this.riverInfoProvider.findGauge(station); - return this.tkhCalculator.getTkh(station, wst); + this.rows.add(new FlowDepthRow(tkh, this.wstLabel, gaugeLabel, this.bedHeightLabel, location)); } } \ No newline at end of file