Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9176:1614cb14308f
Work on calculations for S-Info flood duration workflow
author | mschaefer |
---|---|
date | Mon, 25 Jun 2018 19:21:11 +0200 |
parents | 9b2e46090099 |
children | b4402594213b |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java Mon Jun 25 17:58:11 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java Mon Jun 25 19:21:11 2018 +0200 @@ -11,20 +11,29 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.List; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.lang.math.DoubleRange; import org.dive4elements.artifacts.CallContext; 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.sinfo.common.GaugeDurationValuesFinder; import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; +import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder; +import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; -import org.dive4elements.river.artifacts.sinfo.util.WstInfo; +import org.dive4elements.river.model.Attribute.AttributeKey; +import org.dive4elements.river.model.Gauge; +import org.dive4elements.river.model.sinfo.InfrastructureValue; /** - * @author Gernot Belger + * Calculation of the result rows of the flood duration of the infrastructures in a river km range + * and selected main value durations + * + * @author Matthias Schäfer */ final class FloodDurationCalculator { @@ -34,52 +43,66 @@ private final CallContext context; + public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { this.context = context; this.riverInfoProvider = riverInfoProvider; } - public FloodDurationCalculationResults execute(final Calculation problems, final String label, final WstInfo wstInfo, final String calcModeLabel, - final DoubleRange calcRange, final String riverside, final String user) { + /** + * Calculate the result rows + * + * @return a result collection with one result + */ + public FloodDurationCalculationResults execute(final Calculation problems, final String label, final String calcModeLabel, + final DoubleRange calcRange, final RiversideChoiceKey riverside, final String user) { - calculateResultRow(8888.888); - calculateResultRow(99); - calculateResultRow(77); - final boolean hasTkh = false; // TODO tkh richtig machen, oder anderen result-Type wählen als super-klasse für FloodDurationCalculationResult + final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), + calcRange.getMaximumDouble(), problems); + final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>(); + for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) { + durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems)); + } + final AttributeKey bankKey = riverside.getAttributeKey(); + for (final InfrastructureValue infrastructure : InfrastructureValue.getValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), + calcRange.getMaximumDouble(), bankKey)) { + calculateResultRow(infrastructure, wqFinder, durFinders); + } - final FloodDurationCalculationResult result = new FloodDurationCalculationResult(label, wstInfo, this.rows, false, 4); + final FloodDurationCalculationResult result = new FloodDurationCalculationResult(label, this.rows); final RiverInfo riverInfo = new RiverInfo(this.riverInfoProvider.getRiver()); - final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange, riverside); + final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange); results.addResult(result, problems); return results; } - private void calculateResultRow(final double station) { + /** + * Calculate the result row for one infrastructure + */ + private void calculateResultRow(final InfrastructureValue infrastructure, final WQBaseTableFinder wqFinder, + final Map<Gauge, GaugeDurationValuesFinder> durFinders) { final ResultRow row = ResultRow.create(); + final Gauge gauge = this.riverInfoProvider.getGauge(infrastructure.getStation(), true); + final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight()); + final double qOut = Double.isInfinite(q) ? Double.NaN : q; // REMARK: access the location once only during calculation - final String location = this.riverInfoProvider.getLocation(station); - row.putValue(GeneralResultType.station, station); - row.putValue(SInfoResultType.riverside, "todo:getRiverside"); - row.putValue(SInfoResultType.inundationduration, 44); - row.putValue(SInfoResultType.inundationdurationq, 444); - row.putValue(SInfoResultType.infrastructureHeight, 55); - row.putValue(SInfoResultType.infrastructuretype, "todo_get_infrastructureType"); + final String location = this.riverInfoProvider.getLocation(infrastructure.getStation()); + row.putValue(GeneralResultType.station, infrastructure.getStation()); + row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey().getName()); // TODO i18n + row.putValue(SInfoResultType.floodDuration, 365 - durFinders.get(gauge).getDuration(q)); + row.putValue(SInfoResultType.floodDischarge, qOut); + row.putValue(SInfoResultType.infrastructureHeight, infrastructure.getHeight()); + row.putValue(SInfoResultType.infrastructuretype, infrastructure.getInfrastructure().getType().getName()); - // custom type; each entry produces 4 Columns - final List<DurationWaterlevel> rowWsps = new ArrayList<>(); + // TODO Berechne W, Überflutungsdauer, Q und Bezeichnung von bis zu drei WSPL + // row.putValue(SInfoResultType.customMultiRowColWaterlevel, rowWsps); - rowWsps.add(new DurationWaterlevel(222, 30, 666, "1. Test")); - rowWsps.add(new DurationWaterlevel(111, 40, 555, "2. Test")); - rowWsps.add(new DurationWaterlevel(123, 333, 33, "3. Test")); - rowWsps.add(new DurationWaterlevel(444, 452, 55, "4. Test")); - row.putValue(SInfoResultType.customMultiRowColWaterlevel, rowWsps); - - row.putValue(SInfoResultType.gaugeLabel, "todo:getReferencedGauge"); - row.putValue(SInfoResultType.location, "location"); + row.putValue(SInfoResultType.gaugeLabel, gauge.getName()); + row.putValue(SInfoResultType.location, location); this.rows.add(row); }