Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java @ 9527:7c8d62867876
Cleanup of MainWstValue code. Cache qPositions once determined.
author | gernotbelger |
---|---|
date | Tue, 02 Oct 2018 13:25:52 +0200 |
parents | ee6508687e3f |
children | 429b62373633 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Mon Oct 01 18:08:31 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Tue Oct 02 13:25:52 2018 +0200 @@ -19,12 +19,13 @@ import org.dive4elements.river.artifacts.common.GeneralResultType; import org.dive4elements.river.artifacts.common.ResultRow; import org.dive4elements.river.artifacts.model.Calculation; -import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator; +import org.dive4elements.river.artifacts.model.river.MainWstValues; import org.dive4elements.river.artifacts.model.river.RiverInfoProvider; import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper; import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; import org.dive4elements.river.artifacts.uinfo.common.UInfoResultType; import org.dive4elements.river.artifacts.uinfo.salix.SalixLineAccess.ScenarioType; +import org.dive4elements.river.model.River; /** * Calculation of the result rows of the u-info salix line calc mode @@ -56,7 +57,7 @@ final ScenarioType scenarioType, final String[] scenarioLabels, final String rangeString, final String additionalString, final SalixLineCalculationResults results) { - final MainWstValuesCalculator mainWstValues = fetchGaugeMainValuePositions2(problems); + final MainWstValues mainWstValues = fetchWstMainValues(problems); final WINFOArtifact winfo = new WinfoArtifactWrapper(uinfo); winfo.addStringData("ld_mode", "distance"); @@ -87,39 +88,36 @@ } } - private MainWstValuesCalculator fetchGaugeMainValuePositions2(final Calculation problems) { - final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiverInfo(this.riverInfoProvider, MAIN_VALUE_MQ, MAIN_VALUE_MNQ, - MAIN_VALUE_MHQ, MAIN_VALUE_HQ5); + private MainWstValues fetchWstMainValues(final Calculation problems) { - if (!mainWstValues.hasPosition(MAIN_VALUE_MQ)) + final MainWstValues values = MainWstValues.forRiver(this.riverInfoProvider.getRiver()); + + if (!values.hasPosition(MAIN_VALUE_MQ)) problems.addProblem("uinfo_salix_calc.warning.missing_mq"); else { - if (!mainWstValues.hasPosition(MAIN_VALUE_MHQ)) + if (!values.hasPosition(MAIN_VALUE_MHQ)) problems.addProblem("uinfo_salix_calc.warning.missing_mhq"); - if (!mainWstValues.hasPosition(MAIN_VALUE_MNQ)) + if (!values.hasPosition(MAIN_VALUE_MNQ)) problems.addProblem("uinfo_salix_calc.warning.missing_mnq"); } - return mainWstValues; + return values; } /** * Create a result row for a station and its gauge, and add w-q-values as selected */ - private ResultRow createRow(final MainWstValuesCalculator mainWstValues, final double station, final NavigableMap<Double, List<Double>> rangeScenarios) { + private ResultRow createRow(final MainWstValues mainWstValues, final double station, final NavigableMap<Double, List<Double>> rangeScenarios) { + + final River river = this.riverInfoProvider.getRiver(); final ResultRow row = ResultRow.create(); row.putValue(GeneralResultType.station, station); - // Find station's gauge (obsolete version which calculates gauge-wise) - // final Gauge gauge = this.riverInfoProvider.getGauge(station, true); - // Interpolate mnw, mw, and mhw - // final double mnw = interpolateW(station, this.gaugeMnwPos.get(gauge)); - // final double mw = interpolateW(station, this.gaugeMwPos.get(gauge)); - // final double mhw = interpolateW(station, this.gaugeMhwPos.get(gauge)); - final double mnw = mainWstValues.interpolateW(station, MAIN_VALUE_MNQ); - final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ); - final double mhw = mainWstValues.interpolateW(station, MAIN_VALUE_MHQ); - final double hw5 = mainWstValues.interpolateW(station, MAIN_VALUE_HQ5); + + final double mnw = mainWstValues.getW(river, MAIN_VALUE_MNQ, station); + final double mw = mainWstValues.getW(river, MAIN_VALUE_MQ, station); + final double mhw = mainWstValues.getW(river, MAIN_VALUE_MHQ, station); + final double hw5 = mainWstValues.getW(river, MAIN_VALUE_HQ5, station); row.putValue(UInfoResultType.waterlevelMNW, mnw); row.putValue(UInfoResultType.waterlevelMW, mw); row.putValue(UInfoResultType.waterlevelMHW, mhw);