Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.java @ 9612:f8308db94634
#20 UI, Diagramme
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 09 Oct 2019 16:17:16 +0200 |
parents | f318359b81a2 |
children | d889ffe2fb05 |
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 |
9612 | 13 import java.util.HashSet; |
9050 | 14 import java.util.List; |
9612 | 15 import java.util.Set; |
9050 | 16 |
9265 | 17 import org.apache.commons.lang.StringUtils; |
9050 | 18 import org.dive4elements.artifactdatabase.state.Facet; |
19 import org.dive4elements.artifacts.CallContext; | |
20 import org.dive4elements.river.artifacts.ChartArtifact; | |
21 import org.dive4elements.river.artifacts.D4EArtifact; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
22 import org.dive4elements.river.artifacts.model.Calculation; |
9050 | 23 import org.dive4elements.river.artifacts.model.CalculationResult; |
9145 | 24 import org.dive4elements.river.artifacts.model.DataFacet; |
9050 | 25 import org.dive4elements.river.artifacts.model.EmptyFacet; |
9145 | 26 import org.dive4elements.river.artifacts.model.FacetTypes; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
27 import org.dive4elements.river.artifacts.model.ReportFacet; |
9252 | 28 import org.dive4elements.river.artifacts.resources.Resources; |
9050 | 29 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
9612 | 30 import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.Infrastructure; |
9050 | 31 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
|
32 import org.dive4elements.river.model.Attribute.AttributeKey; |
9050 | 33 |
9176
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 * 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
|
36 */ |
9054
95643dffd006
rename grounding->collision; inundation_duration->flood_duration
gernotbelger
parents:
9050
diff
changeset
|
37 public class FloodDurationState extends DefaultState { |
9050 | 38 |
39 private static final long serialVersionUID = 1L; | |
40 | |
41 /** | |
42 * From this state can only be continued trivially. | |
43 */ | |
44 @Override | |
45 protected String getUIProvider() { | |
46 return "continue"; | |
47 } | |
48 | |
49 @Override | |
50 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
51 if (artifact instanceof ChartArtifact) { | |
52 facets.add(new EmptyFacet()); | |
53 return null; | |
54 } | |
55 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
56 } | |
57 | |
58 @Override | |
59 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
60 if (artifact instanceof ChartArtifact) { | |
61 facets.add(new EmptyFacet()); | |
62 return null; | |
63 } | |
64 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
65 } | |
66 | |
67 /** | |
68 * Compute result or returned object from cache, create facets. | |
69 * | |
70 * @param old | |
71 * Object that was cached. | |
72 */ | |
73 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
74 | |
75 final CalculationResult res = doCompute(sinfo, context, old); | |
76 | |
77 if (facets == null) | |
78 return res; | |
79 | |
9145 | 80 final FloodDurationCalculationResults results = (FloodDurationCalculationResults) res.getData(); |
9195 | 81 final List<FloodDurationCalculationResult> resultList = results.getResults(); |
9265 | 82 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
83 int resultIndex = 0; |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
84 int themeCount = 0; |
9612 | 85 |
9195 | 86 for (final FloodDurationCalculationResult result : resultList) { |
9145 | 87 |
9265 | 88 if (resultIndex == 0) { |
89 /* we only have one result, but safety first... */ | |
90 | |
91 /* Setting the valid stations as data to the state, so the NaviChartOutputTab knows what are the valid stations */ | |
92 final List<Double> validDurationChartKilometers = result.getValidDurationChartKilometers(); | |
93 final String validKilometerString = StringUtils.join(validDurationChartKilometers, ','); | |
94 sinfo.addStringData("validStations", validKilometerString); | |
95 } | |
96 | |
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
|
97 final FloodDurationAccess access = new FloodDurationAccess(sinfo); |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
98 |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
99 final int waterlevelCount = result.getWaterlevelCount(); |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
100 |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
101 for (int j = 0; j < waterlevelCount; j++) { |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
102 |
9252 | 103 // final String waterlevelLabel = result.getMainValueLabel(j); |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
104 // FIXME: use label as label for theme |
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
105 |
9215 | 106 // final int facetIndex, final int resultIndex, final int dataIndex |
9612 | 107 facets.add(FloodDurationProcessor.createMainValueDurationFacet(context, hash, this.id, result, themeCount++, resultIndex, j)); |
108 facets.add(FloodHeightProcessor.createMainValueHeightFacet(context, hash, this.id, result, themeCount++, resultIndex, j)); | |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
109 |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
110 } |
9145 | 111 |
9252 | 112 final String nameW = Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.w"); |
113 final String nameQ = Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.q"); | |
9612 | 114 facets.add(FloodDurationCurveProcessor.createFloodDurationWCurveFacet(context, hash, this.id, result, themeCount++, resultIndex, nameW)); |
115 facets.add(FloodDurationCurveProcessor.createFloodDurationQCurveFacet(context, hash, this.id, result, themeCount++, resultIndex, nameQ)); | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
116 if (waterlevelCount >= 1) { |
9612 | 117 facets.add(FloodDurationCurveProcessor.createMainValuesWFacet(context, hash, this.id, result, themeCount++, resultIndex, |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
118 Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.mainw"))); |
9612 | 119 facets.add(FloodDurationCurveProcessor.createMainValuesQFacet(context, hash, this.id, result, themeCount++, resultIndex, |
120 Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.mainq"), null)); | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
121 } |
9612 | 122 |
123 final AttributeKey choice = access.getRiverside().getAttributeKey(); | |
124 | |
125 for (final AttributeKey riversideC : getRiversides(choice)) { | |
126 facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, themeCount++, resultIndex, true, riversideC)); | |
127 | |
128 facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, themeCount++, resultIndex, false, riversideC)); | |
9376
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
129 } |
9612 | 130 |
131 final Set<Infrastructure> infrastructures = result.getInfastructureMap(); | |
132 for (final Infrastructure entry : infrastructures) { | |
133 | |
134 facets.add(FloodDurationProcessor.createFloodDurationFacet(context, hash, this.id, result, themeCount++, resultIndex, entry)); | |
135 | |
136 facets.add(FloodHeightProcessor.createFloodHeightFacet(context, hash, this.id, result, themeCount++, resultIndex, entry)); | |
9376
f318359b81a2
S-Info flood duration theme rename, and more infrastructure themes in the duration curve
mschaefer
parents:
9265
diff
changeset
|
137 } |
9252 | 138 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
139 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
|
140 facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
9195 | 141 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9202
diff
changeset
|
142 resultIndex++; |
9145 | 143 } |
144 | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
145 final Calculation report = res.getReport(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
146 if (report.hasProblems()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
147 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
9050 | 148 |
149 return res; | |
150 } | |
151 | |
9612 | 152 private Set<AttributeKey> getRiversides(final AttributeKey choice) { |
153 final Set<AttributeKey> usedRiversides = new HashSet<>(); | |
154 if (choice.equals(AttributeKey.LEFT)) | |
155 usedRiversides.add(AttributeKey.LEFT); | |
156 else if (choice.equals(AttributeKey.RIGHT)) | |
157 usedRiversides.add(AttributeKey.RIGHT); | |
158 | |
159 else { | |
160 usedRiversides.add(AttributeKey.RIGHT); | |
161 usedRiversides.add(AttributeKey.LEFT); | |
162 } | |
163 return usedRiversides; | |
164 } | |
165 | |
9050 | 166 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { |
167 if (old instanceof CalculationResult) | |
168 return (CalculationResult) old; | |
169 | |
9067 | 170 return new FloodDurationCalculation(context).calculate(sinfo); |
9050 | 171 } |
172 } |