Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java @ 9195:a4121ec450d6
'ca.'-issue
ExportContextCSV+PDF separated
uinfo.inundationduration url export
author | gernotbelger |
---|---|
date | Fri, 29 Jun 2018 14:52:54 +0200 |
parents | 1614cb14308f |
children | b4402594213b |
rev | line source |
---|---|
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
9067 | 2 * Software engineering by |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | |
11 | |
12 import org.apache.commons.lang.math.DoubleRange; | |
13 import org.dive4elements.artifacts.CallContext; | |
14 import org.dive4elements.river.artifacts.model.Calculation; | |
15 import org.dive4elements.river.artifacts.model.CalculationResult; | |
16 import org.dive4elements.river.artifacts.resources.Resources; | |
17 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | |
18 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
19 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; |
9067 | 20 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
21 import org.dive4elements.river.model.River; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
22 import org.dive4elements.river.model.sinfo.Infrastructure; |
9067 | 23 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
24 /** |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
25 * Calculation of the flood durations of the infrastructures of the km range of a river |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
26 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
27 * @author Matthias Schäfer |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
28 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
29 final class FloodDurationCalculation { |
9067 | 30 |
31 private final CallContext context; | |
32 | |
33 public FloodDurationCalculation(final CallContext context) { | |
34 this.context = context; | |
35 } | |
36 | |
37 public CalculationResult calculate(final SINFOArtifact sinfo) { | |
38 | |
39 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); | |
40 | |
41 /* access input data */ | |
42 final FloodDurationAccess access = new FloodDurationAccess(sinfo); | |
43 final River river = access.getRiver(); | |
44 final DoubleRange calcRange = access.getRange(); | |
45 | |
46 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); | |
47 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
48 final String riverside = Resources.getMsg(this.context.getMeta(), access.getRiverside()); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
49 final Infrastructure infrasSeries = Infrastructure.getSeries(river); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
50 final String infrasType = (infrasSeries != null) ? infrasSeries.getType().getName() : "?"; |
9067 | 51 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
52 final Calculation problems = new Calculation(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
53 |
9195 | 54 final FloodDurationCalculationResults results = calculateResult(calcModeLabel, infrasType, riverside, calcRange, infoProvider, |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
55 RiversideChoiceKey.fromKey(access.getRiverside()), user, problems); |
9067 | 56 |
9145 | 57 return new CalculationResult(results, problems); |
58 } | |
59 | |
60 /** | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
61 * Calculates the flood durations of the infrastructures of a km range of a river |
9145 | 62 */ |
9195 | 63 private FloodDurationCalculationResults calculateResult(final String calcModeLabel, final String infrastructureType, final String riverside, |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
64 final DoubleRange calcRange, final RiverInfoProvider riverInfoProvider, final RiversideChoiceKey riversideKey, final String user, |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
65 final Calculation problems) { |
9145 | 66 |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9145
diff
changeset
|
67 final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, riverInfoProvider); |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
68 final String label = infrastructureType + ", " + riverside; |
9195 | 69 return calculator.execute(problems, label, calcModeLabel, calcRange, riversideKey, user); |
9067 | 70 } |
71 } |