Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9175:34dc0163ad2d | 9176:1614cb14308f |
---|---|
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | 10 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
11 | 11 |
12 import java.util.ArrayList; | 12 import java.util.ArrayList; |
13 import java.util.Collection; | 13 import java.util.Collection; |
14 import java.util.List; | 14 import java.util.HashMap; |
15 import java.util.Map; | |
15 | 16 |
16 import org.apache.commons.lang.math.DoubleRange; | 17 import org.apache.commons.lang.math.DoubleRange; |
17 import org.dive4elements.artifacts.CallContext; | 18 import org.dive4elements.artifacts.CallContext; |
18 import org.dive4elements.river.artifacts.common.GeneralResultType; | 19 import org.dive4elements.river.artifacts.common.GeneralResultType; |
19 import org.dive4elements.river.artifacts.common.ResultRow; | 20 import org.dive4elements.river.artifacts.common.ResultRow; |
20 import org.dive4elements.river.artifacts.model.Calculation; | 21 import org.dive4elements.river.artifacts.model.Calculation; |
22 import org.dive4elements.river.artifacts.sinfo.common.GaugeDurationValuesFinder; | |
21 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; | 23 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; |
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 24 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
25 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder; | |
26 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; | |
23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 27 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
24 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; | 28 import org.dive4elements.river.model.Attribute.AttributeKey; |
29 import org.dive4elements.river.model.Gauge; | |
30 import org.dive4elements.river.model.sinfo.InfrastructureValue; | |
25 | 31 |
26 /** | 32 /** |
27 * @author Gernot Belger | 33 * Calculation of the result rows of the flood duration of the infrastructures in a river km range |
34 * and selected main value durations | |
35 * | |
36 * @author Matthias Schäfer | |
28 */ | 37 */ |
29 final class FloodDurationCalculator { | 38 final class FloodDurationCalculator { |
30 | 39 |
31 private final Collection<ResultRow> rows = new ArrayList<>(); | 40 private final Collection<ResultRow> rows = new ArrayList<>(); |
32 | 41 |
33 private final RiverInfoProvider riverInfoProvider; | 42 private final RiverInfoProvider riverInfoProvider; |
34 | 43 |
35 private final CallContext context; | 44 private final CallContext context; |
36 | 45 |
46 | |
37 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { | 47 public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { |
38 this.context = context; | 48 this.context = context; |
39 this.riverInfoProvider = riverInfoProvider; | 49 this.riverInfoProvider = riverInfoProvider; |
40 } | 50 } |
41 | 51 |
42 public FloodDurationCalculationResults execute(final Calculation problems, final String label, final WstInfo wstInfo, final String calcModeLabel, | 52 /** |
43 final DoubleRange calcRange, final String riverside, final String user) { | 53 * Calculate the result rows |
54 * | |
55 * @return a result collection with one result | |
56 */ | |
57 public FloodDurationCalculationResults execute(final Calculation problems, final String label, final String calcModeLabel, | |
58 final DoubleRange calcRange, final RiversideChoiceKey riverside, final String user) { | |
44 | 59 |
45 calculateResultRow(8888.888); | 60 final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), |
46 calculateResultRow(99); | 61 calcRange.getMaximumDouble(), problems); |
47 calculateResultRow(77); | 62 final Map<Gauge, GaugeDurationValuesFinder> durFinders = new HashMap<>(); |
48 final boolean hasTkh = false; // TODO tkh richtig machen, oder anderen result-Type wählen als super-klasse für FloodDurationCalculationResult | 63 for (final Gauge gauge : this.riverInfoProvider.getRiver().determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) { |
64 durFinders.put(gauge, GaugeDurationValuesFinder.loadValues(gauge, problems)); | |
65 } | |
66 final AttributeKey bankKey = riverside.getAttributeKey(); | |
67 for (final InfrastructureValue infrastructure : InfrastructureValue.getValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), | |
68 calcRange.getMaximumDouble(), bankKey)) { | |
69 calculateResultRow(infrastructure, wqFinder, durFinders); | |
70 } | |
49 | 71 |
50 final FloodDurationCalculationResult result = new FloodDurationCalculationResult(label, wstInfo, this.rows, false, 4); | 72 final FloodDurationCalculationResult result = new FloodDurationCalculationResult(label, this.rows); |
51 | 73 |
52 final RiverInfo riverInfo = new RiverInfo(this.riverInfoProvider.getRiver()); | 74 final RiverInfo riverInfo = new RiverInfo(this.riverInfoProvider.getRiver()); |
53 | 75 |
54 final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange, riverside); | 76 final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange); |
55 results.addResult(result, problems); | 77 results.addResult(result, problems); |
56 return results; | 78 return results; |
57 } | 79 } |
58 | 80 |
59 private void calculateResultRow(final double station) { | 81 /** |
82 * Calculate the result row for one infrastructure | |
83 */ | |
84 private void calculateResultRow(final InfrastructureValue infrastructure, final WQBaseTableFinder wqFinder, | |
85 final Map<Gauge, GaugeDurationValuesFinder> durFinders) { | |
60 | 86 |
61 final ResultRow row = ResultRow.create(); | 87 final ResultRow row = ResultRow.create(); |
62 | 88 |
89 final Gauge gauge = this.riverInfoProvider.getGauge(infrastructure.getStation(), true); | |
90 final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight()); | |
91 final double qOut = Double.isInfinite(q) ? Double.NaN : q; | |
63 // REMARK: access the location once only during calculation | 92 // REMARK: access the location once only during calculation |
64 final String location = this.riverInfoProvider.getLocation(station); | 93 final String location = this.riverInfoProvider.getLocation(infrastructure.getStation()); |
65 row.putValue(GeneralResultType.station, station); | 94 row.putValue(GeneralResultType.station, infrastructure.getStation()); |
66 row.putValue(SInfoResultType.riverside, "todo:getRiverside"); | 95 row.putValue(SInfoResultType.riverside, infrastructure.getAttributeKey().getName()); // TODO i18n |
67 row.putValue(SInfoResultType.inundationduration, 44); | 96 row.putValue(SInfoResultType.floodDuration, 365 - durFinders.get(gauge).getDuration(q)); |
68 row.putValue(SInfoResultType.inundationdurationq, 444); | 97 row.putValue(SInfoResultType.floodDischarge, qOut); |
69 row.putValue(SInfoResultType.infrastructureHeight, 55); | 98 row.putValue(SInfoResultType.infrastructureHeight, infrastructure.getHeight()); |
70 row.putValue(SInfoResultType.infrastructuretype, "todo_get_infrastructureType"); | 99 row.putValue(SInfoResultType.infrastructuretype, infrastructure.getInfrastructure().getType().getName()); |
71 | 100 |
72 // custom type; each entry produces 4 Columns | 101 // TODO Berechne W, Überflutungsdauer, Q und Bezeichnung von bis zu drei WSPL |
73 final List<DurationWaterlevel> rowWsps = new ArrayList<>(); | 102 // row.putValue(SInfoResultType.customMultiRowColWaterlevel, rowWsps); |
74 | 103 |
75 rowWsps.add(new DurationWaterlevel(222, 30, 666, "1. Test")); | 104 row.putValue(SInfoResultType.gaugeLabel, gauge.getName()); |
76 rowWsps.add(new DurationWaterlevel(111, 40, 555, "2. Test")); | 105 row.putValue(SInfoResultType.location, location); |
77 rowWsps.add(new DurationWaterlevel(123, 333, 33, "3. Test")); | |
78 rowWsps.add(new DurationWaterlevel(444, 452, 55, "4. Test")); | |
79 row.putValue(SInfoResultType.customMultiRowColWaterlevel, rowWsps); | |
80 | |
81 row.putValue(SInfoResultType.gaugeLabel, "todo:getReferencedGauge"); | |
82 row.putValue(SInfoResultType.location, "location"); | |
83 | 106 |
84 this.rows.add(row); | 107 this.rows.add(row); |
85 } | 108 } |
86 } | 109 } |