Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.java @ 9376:f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
author | mschaefer |
---|---|
date | Fri, 03 Aug 2018 17:02:38 +0200 |
parents | e5367900dd6d |
children | f8308db94634 |
rev | line source |
---|---|
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
2 * Software engineering by |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
9050 | 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 | |
9054
95643dffd006
rename grounding->collision; inundation_duration->flood_duration
gernotbelger
parents:
9050
diff
changeset
|
11 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
9050 | 12 |
13 import java.util.List; | |
14 | |
9265 | 15 import org.apache.commons.lang.StringUtils; |
9050 | 16 import org.dive4elements.artifactdatabase.state.Facet; |
17 import org.dive4elements.artifacts.CallContext; | |
18 import org.dive4elements.river.artifacts.ChartArtifact; | |
19 import org.dive4elements.river.artifacts.D4EArtifact; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
20 import org.dive4elements.river.artifacts.model.Calculation; |
9050 | 21 import org.dive4elements.river.artifacts.model.CalculationResult; |
9145 | 22 import org.dive4elements.river.artifacts.model.DataFacet; |
9050 | 23 import org.dive4elements.river.artifacts.model.EmptyFacet; |
9145 | 24 import org.dive4elements.river.artifacts.model.FacetTypes; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
25 import org.dive4elements.river.artifacts.model.ReportFacet; |
9252 | 26 import org.dive4elements.river.artifacts.resources.Resources; |
9050 | 27 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
9229
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
28 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; |
9050 | 29 import org.dive4elements.river.artifacts.states.DefaultState; |
9376
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
30 import org.dive4elements.river.model.Attribute.AttributeKey; |
9050 | 31 |
9176
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 * Last state of the S-Info flood duration workflow that calculates and outputs the result |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
34 */ |
9054
95643dffd006
rename grounding->collision; inundation_duration->flood_duration
gernotbelger
parents:
9050
diff
changeset
|
35 public class FloodDurationState extends DefaultState { |
9050 | 36 |
37 private static final long serialVersionUID = 1L; | |
38 | |
39 /** | |
40 * From this state can only be continued trivially. | |
41 */ | |
42 @Override | |
43 protected String getUIProvider() { | |
44 return "continue"; | |
45 } | |
46 | |
47 @Override | |
48 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
49 if (artifact instanceof ChartArtifact) { | |
50 facets.add(new EmptyFacet()); | |
51 return null; | |
52 } | |
53 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
54 } | |
55 | |
56 @Override | |
57 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
58 if (artifact instanceof ChartArtifact) { | |
59 facets.add(new EmptyFacet()); | |
60 return null; | |
61 } | |
62 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
63 } | |
64 | |
65 /** | |
66 * Compute result or returned object from cache, create facets. | |
67 * | |
68 * @param old | |
69 * Object that was cached. | |
70 */ | |
71 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
72 | |
73 final CalculationResult res = doCompute(sinfo, context, old); | |
74 | |
75 if (facets == null) | |
76 return res; | |
77 | |
9145 | 78 final FloodDurationCalculationResults results = (FloodDurationCalculationResults) res.getData(); |
9195 | 79 final List<FloodDurationCalculationResult> resultList = results.getResults(); |
9265 | 80 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
81 int resultIndex = 0; |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
82 int themeCount = 0; |
9195 | 83 for (final FloodDurationCalculationResult result : resultList) { |
9145 | 84 |
9265 | 85 if (resultIndex == 0) { |
86 /* we only have one result, but safety first... */ | |
87 | |
88 /* Setting the valid stations as data to the state, so the NaviChartOutputTab knows what are the valid stations */ | |
89 final List<Double> validDurationChartKilometers = result.getValidDurationChartKilometers(); | |
90 final String validKilometerString = StringUtils.join(validDurationChartKilometers, ','); | |
91 sinfo.addStringData("validStations", validKilometerString); | |
92 } | |
93 | |
9229
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
94 final FloodDurationAccess access = new FloodDurationAccess(sinfo); |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
95 if ((access.getRiverside() == RiversideChoiceKey.LEFT) || (access.getRiverside() == RiversideChoiceKey.BOTH)) |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
96 facets.add(FloodDurationProcessor.createFloodDurationFacet(context, hash, this.id, result, 0, resultIndex)); |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
97 if ((access.getRiverside() == RiversideChoiceKey.RIGHT) || (access.getRiverside() == RiversideChoiceKey.BOTH)) |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
98 facets.add(FloodDurationProcessor.createFloodDurationFacet(context, hash, this.id, result, 1, resultIndex)); |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
99 |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
100 final int waterlevelCount = result.getWaterlevelCount(); |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
101 |
9229
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
102 if ((access.getRiverside() == RiversideChoiceKey.LEFT) || (access.getRiverside() == RiversideChoiceKey.BOTH)) |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
103 facets.add(FloodHeightProcessor.createFloodHeightFacet(context, hash, this.id, result, 0, resultIndex)); |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
104 if ((access.getRiverside() == RiversideChoiceKey.RIGHT) || (access.getRiverside() == RiversideChoiceKey.BOTH)) |
0dcd1cd41915
Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents:
9215
diff
changeset
|
105 facets.add(FloodHeightProcessor.createFloodHeightFacet(context, hash, this.id, result, 1, resultIndex)); |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
106 |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
107 for (int j = 0; j < waterlevelCount; j++) { |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
108 |
9252 | 109 // final String waterlevelLabel = result.getMainValueLabel(j); |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
110 // FIXME: use label as label for theme |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
111 |
9215 | 112 // final int facetIndex, final int resultIndex, final int dataIndex |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
113 facets.add(FloodDurationProcessor.createMainValueDurationFacet(context, hash, this.id, result, themeCount, resultIndex, j)); |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
114 facets.add(FloodHeightProcessor.createMainValueHeightFacet(context, hash, this.id, result, themeCount, resultIndex, j)); |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
115 |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
116 themeCount++; |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
117 } |
9145 | 118 |
9252 | 119 final String nameW = Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.w"); |
120 final String nameQ = Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.q"); | |
121 facets.add(FloodDurationCurveProcessor.createFloodDurationWCurveFacet(context, hash, this.id, result, 0, resultIndex, nameW)); | |
122 facets.add(FloodDurationCurveProcessor.createFloodDurationQCurveFacet(context, hash, this.id, result, 1, resultIndex, nameQ)); | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
123 if (waterlevelCount >= 1) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
124 facets.add(FloodDurationCurveProcessor.createMainValuesWFacet(context, hash, this.id, result, 0, resultIndex, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
125 Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.mainw"))); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
126 facets.add(FloodDurationCurveProcessor.createMainValuesQFacet(context, hash, this.id, result, 1, resultIndex, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
127 Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.mainq"))); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
128 } |
9376
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
129 if ((access.getRiverside() == RiversideChoiceKey.LEFT) || (access.getRiverside() == RiversideChoiceKey.BOTH)) { |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
130 facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, 0, resultIndex, |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
131 Resources.getMsg(context.getMeta(), "sinfo_facet_flood_duration_curve.infra.w.left.description"), AttributeKey.LEFT, true)); |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
132 facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, 0, resultIndex, |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
133 Resources.getMsg(context.getMeta(), "sinfo_facet_flood_duration_curve.infra.q.left.description"), AttributeKey.LEFT, false)); |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
134 } |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
135 if ((access.getRiverside() == RiversideChoiceKey.RIGHT) || (access.getRiverside() == RiversideChoiceKey.BOTH)) { |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
136 facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, 0, resultIndex, |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
137 Resources.getMsg(context.getMeta(), "sinfo_facet_flood_duration_curve.infra.w.right.description"), AttributeKey.RIGHT, true)); |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
138 facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, 0, resultIndex, |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
139 Resources.getMsg(context.getMeta(), "sinfo_facet_flood_duration_curve.infra.q.right.description"), AttributeKey.RIGHT, false)); |
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
140 } |
9252 | 141 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
142 facets.add(new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id)); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
143 facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
9195 | 144 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
145 resultIndex++; |
9145 | 146 } |
147 | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
148 final Calculation report = res.getReport(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
149 if (report.hasProblems()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
150 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
9050 | 151 |
152 return res; | |
153 } | |
154 | |
155 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { | |
156 if (old instanceof CalculationResult) | |
157 return (CalculationResult) old; | |
158 | |
9067 | 159 return new FloodDurationCalculation(context).calculate(sinfo); |
9050 | 160 } |
161 } |