Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.java @ 9145:e6b63b2b41b9
sinfo.flood_duration pdf, csv, ui
author | gernotbelger |
---|---|
date | Tue, 12 Jun 2018 10:23:23 +0200 |
parents | 2ed3824a3d53 |
children | 23945061daec |
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; | |
17 import org.dive4elements.river.artifacts.model.CalculationResult; | |
9145 | 18 import org.dive4elements.river.artifacts.model.DataFacet; |
9050 | 19 import org.dive4elements.river.artifacts.model.EmptyFacet; |
9145 | 20 import org.dive4elements.river.artifacts.model.FacetTypes; |
9050 | 21 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
22 import org.dive4elements.river.artifacts.states.DefaultState; | |
23 | |
24 /** State in which a waterlevel has been calculated. */ | |
9054
95643dffd006
rename grounding->collision; inundation_duration->flood_duration
gernotbelger
parents:
9050
diff
changeset
|
25 public class FloodDurationState extends DefaultState { |
9050 | 26 |
27 /// ** The log that is used in this state. */ | |
28 // private static Logger log = Logger.getLogger(FlowDepthState.class); | |
29 | |
30 private static final long serialVersionUID = 1L; | |
31 | |
32 /** | |
33 * From this state can only be continued trivially. | |
34 */ | |
35 @Override | |
36 protected String getUIProvider() { | |
37 return "continue"; | |
38 } | |
39 | |
40 @Override | |
41 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
42 if (artifact instanceof ChartArtifact) { | |
43 facets.add(new EmptyFacet()); | |
44 return null; | |
45 } | |
46 | |
47 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
48 } | |
49 | |
50 @Override | |
51 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
52 if (artifact instanceof ChartArtifact) { | |
53 facets.add(new EmptyFacet()); | |
54 return null; | |
55 } | |
56 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
57 } | |
58 | |
59 /** | |
60 * Compute result or returned object from cache, create facets. | |
61 * | |
62 * @param old | |
63 * Object that was cached. | |
64 */ | |
65 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
66 | |
67 final CalculationResult res = doCompute(sinfo, context, old); | |
68 | |
69 if (facets == null) | |
70 return res; | |
71 | |
9145 | 72 final FloodDurationCalculationResults results = (FloodDurationCalculationResults) res.getData(); |
73 | |
74 /* add themes for chart, for each result */ | |
75 final List<FloodDurationCalculationResult> resultList = results.getResults(); | |
76 for (int index = 0; index < resultList.size(); index++) { | |
77 | |
78 final FloodDurationCalculationResult result = resultList.get(index); | |
79 | |
80 /* filtered (zoom dependent mean) flow depth TODO: */ | |
81 // facets.add(FloodDurationProcessor.createFlowDepthFilteredFacet(context, hash, this.id, result, index)); | |
82 // facets.add(FloodDurationProcessor.createFlowDepthRawFacet(context, hash, this.id, result, index)); | |
83 | |
84 } | |
85 | |
86 if (!resultList.isEmpty()) { | |
87 final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); | |
88 final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); | |
89 | |
90 facets.add(csv); | |
91 facets.add(pdf); | |
92 } | |
93 | |
9050 | 94 // final Calculation report = res.getReport(); |
95 // | |
96 // if (report.hasProblems()) { | |
97 // facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); | |
98 // } | |
99 | |
100 return res; | |
101 } | |
102 | |
103 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { | |
104 if (old instanceof CalculationResult) | |
105 return (CalculationResult) old; | |
106 | |
9067 | 107 return new FloodDurationCalculation(context).calculate(sinfo); |
9050 | 108 } |
109 } |