Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java @ 9202:b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
author | mschaefer |
---|---|
date | Mon, 02 Jul 2018 07:33:53 +0200 |
parents | a4121ec450d6 |
children | 3dae6b78e1da |
comparison
equal
deleted
inserted
replaced
9201:491e1a434457 | 9202:b4402594213b |
---|---|
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | 10 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
11 | 11 |
12 import org.apache.commons.lang.math.DoubleRange; | 12 import org.apache.commons.lang.math.DoubleRange; |
13 import org.dive4elements.artifacts.CallContext; | 13 import org.dive4elements.artifacts.CallContext; |
14 import org.dive4elements.river.artifacts.WINFOArtifact; | |
14 import org.dive4elements.river.artifacts.model.Calculation; | 15 import org.dive4elements.river.artifacts.model.Calculation; |
15 import org.dive4elements.river.artifacts.model.CalculationResult; | 16 import org.dive4elements.river.artifacts.model.CalculationResult; |
16 import org.dive4elements.river.artifacts.resources.Resources; | 17 import org.dive4elements.river.artifacts.resources.Resources; |
17 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | 18 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
18 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; | 19 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; |
19 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; | 20 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; |
21 import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper; | |
20 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; | 22 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | |
21 import org.dive4elements.river.model.River; | 24 import org.dive4elements.river.model.River; |
22 import org.dive4elements.river.model.sinfo.Infrastructure; | 25 import org.dive4elements.river.model.sinfo.Infrastructure; |
23 | 26 |
24 /** | 27 /** |
25 * Calculation of the flood durations of the infrastructures of the km range of a river | 28 * Calculation of the flood durations of the infrastructures of the km range of a river |
39 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); | 42 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); |
40 | 43 |
41 /* access input data */ | 44 /* access input data */ |
42 final FloodDurationAccess access = new FloodDurationAccess(sinfo); | 45 final FloodDurationAccess access = new FloodDurationAccess(sinfo); |
43 final River river = access.getRiver(); | 46 final River river = access.getRiver(); |
47 final RiverInfo riverInfo = new RiverInfo(river); | |
44 final DoubleRange calcRange = access.getRange(); | 48 final DoubleRange calcRange = access.getRange(); |
45 | 49 |
46 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); | 50 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); |
47 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); | 51 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); |
48 final String riverside = Resources.getMsg(this.context.getMeta(), access.getRiverside()); | 52 final String riverside = Resources.getMsg(this.context.getMeta(), access.getRiverside()); |
49 final Infrastructure infrasSeries = Infrastructure.getSeries(river); | 53 final Infrastructure infrasSeries = Infrastructure.getSeries(river); |
50 final String infrasType = (infrasSeries != null) ? infrasSeries.getType().getName() : "?"; | 54 final String infrasType = (infrasSeries != null) ? infrasSeries.getType().getName() : "?"; |
51 | 55 |
52 final Calculation problems = new Calculation(); | 56 final Calculation problems = new Calculation(); |
53 | 57 |
54 final FloodDurationCalculationResults results = calculateResult(calcModeLabel, infrasType, riverside, calcRange, infoProvider, | 58 // Calculate the selected main values, if any |
55 RiversideChoiceKey.fromKey(access.getRiverside()), user, problems); | 59 /* misuse winfo-artifact to calculate waterlevels in the same way */ |
60 final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo); | |
61 int mainValueCount = 0; | |
62 if (winfo.isW()) | |
63 mainValueCount = winfo.getWs().length; | |
64 else if (winfo.isQ()) | |
65 mainValueCount = winfo.getQs().length; | |
66 | |
67 final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange, mainValueCount); | |
68 | |
69 final FloodDurationCalculationResult result = calculateResult(infrasType, riverside, calcRange, infoProvider, | |
70 RiversideChoiceKey.fromKey(access.getRiverside()), problems, winfo); | |
71 results.addResult(result, problems); | |
56 | 72 |
57 return new CalculationResult(results, problems); | 73 return new CalculationResult(results, problems); |
58 } | 74 } |
59 | 75 |
60 /** | 76 /** |
61 * Calculates the flood durations of the infrastructures of a km range of a river | 77 * Calculates the flood durations of the infrastructures of a km range of a river |
62 */ | 78 */ |
63 private FloodDurationCalculationResults calculateResult(final String calcModeLabel, final String infrastructureType, final String riverside, | 79 private FloodDurationCalculationResult calculateResult(final String infrastructureType, final String riverside, final DoubleRange calcRange, |
64 final DoubleRange calcRange, final RiverInfoProvider riverInfoProvider, final RiversideChoiceKey riversideKey, final String user, | 80 final RiverInfoProvider riverInfoProvider, final RiversideChoiceKey riversideKey, final Calculation problems, final WINFOArtifact winfo) { |
65 final Calculation problems) { | |
66 | 81 |
67 final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, riverInfoProvider); | 82 final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, riverInfoProvider); |
68 final String label = infrastructureType + ", " + riverside; | 83 final String label = infrastructureType + ", " + riverside; |
69 return calculator.execute(problems, label, calcModeLabel, calcRange, riversideKey, user); | 84 return calculator.execute(problems, label, calcRange, riversideKey, winfo); |
70 } | 85 } |
71 } | 86 } |