Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java @ 9266:465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
author | mschaefer |
---|---|
date | Wed, 18 Jul 2018 12:20:01 +0200 |
parents | c2a0028bfa9f |
children | 83ebeb620b5a |
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 | |
9266
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
12 import java.util.List; |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
13 |
9067 | 14 import org.apache.commons.lang.math.DoubleRange; |
15 import org.dive4elements.artifacts.CallContext; | |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
16 import org.dive4elements.river.artifacts.WINFOArtifact; |
9067 | 17 import org.dive4elements.river.artifacts.model.Calculation; |
18 import org.dive4elements.river.artifacts.model.CalculationResult; | |
9266
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
19 import org.dive4elements.river.artifacts.model.WQDay; |
9067 | 20 import org.dive4elements.river.artifacts.resources.Resources; |
21 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | |
22 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
23 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper; |
9067 | 25 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
26 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
9266
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
27 import org.dive4elements.river.jfree.StickyAxisAnnotation; |
9067 | 28 import org.dive4elements.river.model.River; |
29 | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
30 /** |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
31 * 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
|
32 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
33 * @author Matthias Schäfer |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
34 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
35 final class FloodDurationCalculation { |
9067 | 36 |
37 private final CallContext context; | |
38 | |
39 public FloodDurationCalculation(final CallContext context) { | |
40 this.context = context; | |
41 } | |
42 | |
43 public CalculationResult calculate(final SINFOArtifact sinfo) { | |
44 | |
45 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); | |
46 | |
47 /* access input data */ | |
48 final FloodDurationAccess access = new FloodDurationAccess(sinfo); | |
49 final River river = access.getRiver(); | |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
50 final RiverInfo riverInfo = new RiverInfo(river); |
9067 | 51 final DoubleRange calcRange = access.getRange(); |
52 | |
53 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); | |
54 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); | |
9236
b515ed950d39
S-Info flood durations with automatic km step width
mschaefer
parents:
9229
diff
changeset
|
55 final String label = Resources.getMsg(this.context.getMeta(), access.getRiverside().getKey()); |
9067 | 56 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
57 final Calculation problems = new Calculation(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
58 |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
59 // Calculate the selected main values, if any |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
60 /* misuse winfo-artifact to calculate waterlevels in the same way */ |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
61 final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo); |
9236
b515ed950d39
S-Info flood durations with automatic km step width
mschaefer
parents:
9229
diff
changeset
|
62 winfo.addStringData("ld_mode", "distance"); |
b515ed950d39
S-Info flood durations with automatic km step width
mschaefer
parents:
9229
diff
changeset
|
63 winfo.addStringData("ld_step", "100"); |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
64 |
9215 | 65 final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange); |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
66 |
9252 | 67 calculateResult(label, calcRange, infoProvider, access.getRiverside(), problems, winfo, results); |
9067 | 68 |
9145 | 69 return new CalculationResult(results, problems); |
70 } | |
71 | |
72 /** | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
73 * Calculates the flood durations of the infrastructures of a km range of a river |
9145 | 74 */ |
9252 | 75 private void calculateResult(final String label, final DoubleRange calcRange, final RiverInfoProvider riverInfoProvider, |
76 final RiversideChoiceKey riverside, final Calculation problems, final WINFOArtifact winfo, final FloodDurationCalculationResults results) { | |
9145 | 77 |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9145
diff
changeset
|
78 final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, riverInfoProvider); |
9252 | 79 calculator.execute(problems, label, calcRange, riverside, winfo, results); |
9067 | 80 } |
9266
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
81 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
82 /** |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
83 * Calculates the flood duration curve of a station |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
84 */ |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
85 public WQDay calcStationCurve(final double station, final SINFOArtifact sinfo) { |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
86 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
87 /* access input data */ |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
88 final FloodDurationAccess access = new FloodDurationAccess(sinfo); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
89 final River river = access.getRiver(); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
90 final DoubleRange calcRange = access.getRange(); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
91 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
92 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
93 final Calculation problems = new Calculation(); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
94 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
95 // Calculate the selected main values, if any |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
96 /* misuse winfo-artifact to calculate waterlevels in the same way */ |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
97 final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
98 winfo.addStringData("ld_locations", Double.toString(station)); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
99 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
100 final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, infoProvider); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
101 if (!Double.isNaN(station)) |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
102 return calculator.calcWQDays(problems, station, winfo); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
103 else |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
104 return calculator.calcWQDays(problems, calcRange.getMinimumFloat(), winfo); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
105 } |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
106 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
107 /** |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
108 * Calculates the annotations of the infrastructure(s) of a station for a flood duration calculation |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
109 */ |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
110 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final double station, final FloodDurationCalculationResult result) { |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
111 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
112 final Calculation problems = new Calculation(); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
113 |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
114 final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, null); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
115 return calculator.calcInfrastructureAnnotations(problems, station, result); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9252
diff
changeset
|
116 } |
9067 | 117 } |