Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.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 |
rev | line source |
---|---|
9050 | 1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9054
95643dffd006
rename grounding->collision; inundation_duration->flood_duration
gernotbelger
parents:
9050
diff
changeset
|
9 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
9050 | 10 |
11 import java.util.List; | |
12 | |
13 import org.dive4elements.artifactdatabase.state.Facet; | |
14 import org.dive4elements.artifacts.CallContext; | |
15 import org.dive4elements.river.artifacts.ChartArtifact; | |
16 import org.dive4elements.river.artifacts.D4EArtifact; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
17 import org.dive4elements.river.artifacts.model.Calculation; |
9050 | 18 import org.dive4elements.river.artifacts.model.CalculationResult; |
9145 | 19 import org.dive4elements.river.artifacts.model.DataFacet; |
9050 | 20 import org.dive4elements.river.artifacts.model.EmptyFacet; |
9145 | 21 import org.dive4elements.river.artifacts.model.FacetTypes; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
22 import org.dive4elements.river.artifacts.model.ReportFacet; |
9050 | 23 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.common.FloodDurationProcessor; |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
25 import org.dive4elements.river.artifacts.sinfo.common.FloodHeightProcessor; |
9050 | 26 import org.dive4elements.river.artifacts.states.DefaultState; |
27 | |
9176
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 * 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
|
30 */ |
9054
95643dffd006
rename grounding->collision; inundation_duration->flood_duration
gernotbelger
parents:
9050
diff
changeset
|
31 public class FloodDurationState extends DefaultState { |
9050 | 32 |
33 /// ** The log that is used in this state. */ | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
34 // private static Logger log = Logger.getLogger(FloodDurationState.class); |
9050 | 35 |
36 private static final long serialVersionUID = 1L; | |
37 | |
38 /** | |
39 * From this state can only be continued trivially. | |
40 */ | |
41 @Override | |
42 protected String getUIProvider() { | |
43 return "continue"; | |
44 } | |
45 | |
46 @Override | |
47 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
48 if (artifact instanceof ChartArtifact) { | |
49 facets.add(new EmptyFacet()); | |
50 return null; | |
51 } | |
52 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
53 } | |
54 | |
55 @Override | |
56 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
57 if (artifact instanceof ChartArtifact) { | |
58 facets.add(new EmptyFacet()); | |
59 return null; | |
60 } | |
61 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
62 } | |
63 | |
64 /** | |
65 * Compute result or returned object from cache, create facets. | |
66 * | |
67 * @param old | |
68 * Object that was cached. | |
69 */ | |
70 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
71 | |
72 final CalculationResult res = doCompute(sinfo, context, old); | |
73 | |
74 if (facets == null) | |
75 return res; | |
76 | |
9145 | 77 final FloodDurationCalculationResults results = (FloodDurationCalculationResults) res.getData(); |
9195 | 78 final List<FloodDurationCalculationResult> resultList = results.getResults(); |
79 int index = 0; | |
80 for (final FloodDurationCalculationResult result : resultList) { | |
9145 | 81 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
82 facets.add(FloodDurationProcessor.createFloodDurationFacet(context, hash, this.id, result, index)); |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
83 for (int j = 0; j <= 2; j++) { |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
84 if (result.getMainValueLabel(j) != null) |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
85 facets.add(FloodDurationProcessor.createMainValueDurationFacet(context, hash, this.id, result, j)); |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
86 } |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
87 facets.add(FloodHeightProcessor.createFloodHeightFacet(context, hash, this.id, result, index)); |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
88 for (int j = 0; j <= 2; j++) { |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
89 if (result.getMainValueLabel(j) != null) |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
90 facets.add(FloodHeightProcessor.createMainValueHeightFacet(context, hash, this.id, result, j)); |
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
91 } |
9145 | 92 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
93 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
|
94 facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
9195 | 95 |
96 index++; | |
9145 | 97 } |
98 | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
99 final Calculation report = res.getReport(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
100 if (report.hasProblems()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9150
diff
changeset
|
101 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
9050 | 102 |
103 return res; | |
104 } | |
105 | |
106 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { | |
107 if (old instanceof CalculationResult) | |
108 return (CalculationResult) old; | |
109 | |
9067 | 110 return new FloodDurationCalculation(context).calculate(sinfo); |
9050 | 111 } |
112 } |