Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java @ 9361:2aec052d4088
Refactoring on SalixLineCalculationResult etc., calculation using MQ etc., scenario (regional+supra) csv columns and meta data added
author | mschaefer |
---|---|
date | Wed, 01 Aug 2018 18:01:11 +0200 |
parents | b3d3c958a594 |
children | 6f7e92c16050 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Wed Aug 01 17:13:52 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Wed Aug 01 18:01:11 2018 +0200 @@ -24,7 +24,6 @@ import org.dive4elements.river.artifacts.model.WstValueTable; import org.dive4elements.river.artifacts.model.WstValueTable.QPosition; import org.dive4elements.river.artifacts.model.WstValueTableFactory; -import org.dive4elements.river.artifacts.sinfo.common.GaugeDischargeValuesFinder; import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper; @@ -34,6 +33,7 @@ import org.dive4elements.river.model.Gauge; import org.dive4elements.river.model.MainValue; import org.dive4elements.river.model.MainValueType.MainValueTypeKey; +import org.dive4elements.river.utils.Formatter; /** * Calculation of the result rows of the u-info salix line calc mode @@ -65,7 +65,8 @@ * Calculate the salix line result rows */ public void execute(final Calculation problems, final UINFOArtifact uinfo, final NavigableMap<Double, List<Double>> rangeScenarios, - final ScenarioType scenarioType, final String[] scenarioLabels, final SalixLineCalculationResults results) { + final ScenarioType scenarioType, final String[] scenarioLabels, final String rangeString, final String additionalString, + final SalixLineCalculationResults results) { this.problems = problems; this.wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); @@ -79,17 +80,17 @@ this.rows.add(createRow(station, rangeScenarios)); } if (scenarioType == ScenarioType.REGIONAL) - results.addResult(new SalixLineCalculationRegionalResult("Salix", scenarioLabels, this.rows), problems); + results.addResult(new SalixLineCalculationRegionalResult("Salix-regional", scenarioLabels, rangeString, additionalString, this.rows), problems); else if (scenarioType == ScenarioType.SUPRAREGIONAL) - results.addResult(new SalixLineCalculationSupraRegionalResult("Salix", this.rows), problems); + results.addResult(new SalixLineCalculationSupraRegionalResult("Salix-supra", scenarioLabels, rangeString, additionalString, this.rows), problems); else if (scenarioType == ScenarioType.HISTORICAL) - results.addResult(new SalixLineCalculationHistoricalResult("Salix", this.rows), problems); + results.addResult(new SalixLineCalculationHistoricalResult("Salix-hist", scenarioLabels, rangeString, additionalString, this.rows), problems); else - results.addResult(new SalixLineCalculationNoScenarioResult("Salix", this.rows), problems); + results.addResult(new SalixLineCalculationResult("Salix-simple", this.rows), problems); } /** - * Fetch MW, MNW and MHW of all gauges and determine the wst QPosition for each one + * Fetch MQ, MNQ and MHQ of all gauges and determine the wst QPosition for each one */ private void fetchGaugeMainValuePositions() { this.gaugeMwPos.clear(); @@ -99,17 +100,14 @@ this.gaugeMwPos.put(gauge, null); this.gaugeMnwPos.put(gauge, null); this.gaugeMhwPos.put(gauge, null); - final GaugeDischargeValuesFinder finder = GaugeDischargeValuesFinder.loadValues(gauge, this.problems); - if (finder == null) - continue; final double gaugeKm = gauge.getStation().doubleValue(); - for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.W)) { - if (mv.getMainValue().getName().equalsIgnoreCase("mw")) - this.gaugeMwPos.put(gauge, this.wst.getQPosition(gaugeKm, finder.getDischarge(mv.getValue().doubleValue()))); - else if (mv.getMainValue().getName().equalsIgnoreCase("mnw")) - this.gaugeMnwPos.put(gauge, this.wst.getQPosition(gaugeKm, finder.getDischarge(mv.getValue().doubleValue()))); - else if (mv.getMainValue().getName().equalsIgnoreCase("mhw")) - this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, finder.getDischarge(mv.getValue().doubleValue()))); + for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q)) { + if (mv.getMainValue().getName().equalsIgnoreCase("mq")) + this.gaugeMwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue())); + else if (mv.getMainValue().getName().equalsIgnoreCase("mnq")) + this.gaugeMnwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue())); + else if (mv.getMainValue().getName().equalsIgnoreCase("mhq")) + this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue())); } } } @@ -134,24 +132,20 @@ row.putValue(SInfoResultType.waterlevel2, mhw); // Calc salix-line and mw-mnw row.putValue(UInfoResultType.salixline, calcSalix(mhw, mw)); - row.putValue(UInfoResultType.salix_delta_mw, calcMwmnw(mw, mnw)); + row.putValue(UInfoResultType.salix_mw_mnw, calcMwmnw(mw, mnw)); // Calc scenario values (always all scenario types set, Result variant extracts the fields needed) final List<SalixScenario> scenarios = new ArrayList<>(); final double[] deltaws = getDeltaWs(station, rangeScenarios); for (int i = 0; i <= deltaws.length - 1; i++) { - if (Math.abs(deltaws[i]) < 0.0001) { - row.putValue(UInfoResultType.salix_line_scenario, Double.NaN); - row.putValue(UInfoResultType.salix_line_scenario_dwspl, 0); // TODO NaN when changed from int to double - /* always need to add a member, so the exporter will produce empty columns */ - scenarios.add(null); - } else { + if (Math.abs(deltaws[i]) > 0.0001) { final double salix = calcSalix(mhw, mw + deltaws[i]); - row.putValue(UInfoResultType.salix_line_scenario, salix); - row.putValue(UInfoResultType.salix_line_scenario_dwspl, (int) (deltaws[i] * 100)); scenarios.add(new SalixScenario((int) (deltaws[i] * 100), salix)); } + else { + scenarios.add(null); + } } - row.putValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl, scenarios); + row.putValue(UInfoResultType.customMultiRowColSalixScenarios, scenarios); return row; } @@ -169,14 +163,14 @@ * Calculates the salix value */ private double calcSalix(final double mhw, final double mw) { - return mhw - 2.31 - mw; + return Formatter.roundW(mhw) - 2.31 - Formatter.roundW(mw); } /** * Calculates the inverse MW-MNW difference */ private double calcMwmnw(final double mw, final double mnw) { - return mnw - mw; + return Formatter.roundW(mnw) - Formatter.roundW(mw); } /**