Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxState.java @ 8950:b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
author | gernotbelger |
---|---|
date | Thu, 15 Mar 2018 17:22:28 +0100 |
parents | 5d5d482da3e9 |
children | b194fa64506a |
rev | line source |
---|---|
8946 | 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 | |
9 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax; | |
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.Calculation; | |
18 import org.dive4elements.river.artifacts.model.CalculationResult; | |
19 import org.dive4elements.river.artifacts.model.DataFacet; | |
20 import org.dive4elements.river.artifacts.model.EmptyFacet; | |
21 import org.dive4elements.river.artifacts.model.FacetTypes; | |
22 import org.dive4elements.river.artifacts.model.ReportFacet; | |
23 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.common.FlowDepthProcessor; |
8946 | 25 import org.dive4elements.river.artifacts.states.DefaultState; |
26 | |
27 /** State in which a waterlevel has been calculated. */ | |
28 public class FlowDepthMinMaxState extends DefaultState { | |
29 | |
30 /// ** The log that is used in this state. */ | |
31 // private static Logger log = Logger.getLogger(FlowDepthState.class); | |
32 | |
33 private static final long serialVersionUID = 1L; | |
34 | |
35 /** | |
36 * From this state can only be continued trivially. | |
37 */ | |
38 @Override | |
39 protected String getUIProvider() { | |
40 return "continue"; | |
41 } | |
42 | |
43 @Override | |
44 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
45 // FIXME: why is this necessary? | |
46 if (artifact instanceof ChartArtifact) { | |
47 facets.add(new EmptyFacet()); | |
48 return null; | |
49 } | |
50 | |
51 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
52 } | |
53 | |
54 @Override | |
55 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
56 if (artifact instanceof ChartArtifact) { | |
57 facets.add(new EmptyFacet()); | |
58 return null; | |
59 } | |
60 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
61 } | |
62 | |
63 /** | |
64 * Compute result or returned object from cache, create facets. | |
65 * | |
66 * @param old | |
67 * Object that was cached. | |
68 */ | |
69 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
70 | |
71 final CalculationResult res = doCompute(sinfo, context, old); | |
72 | |
73 if (facets == null) | |
74 return res; | |
75 | |
76 final FlowDepthMinMaxCalculationResults results = (FlowDepthMinMaxCalculationResults) res.getData(); | |
77 | |
78 /* add themes for chart, for each result */ | |
79 final List<FlowDepthMinMaxCalculationResult> resultList = results.getResults(); | |
80 for (int index = 0; index < resultList.size(); index++) { | |
81 | |
82 final FlowDepthMinMaxCalculationResult result = resultList.get(index); | |
83 | |
84 /* filtered (zoom dependent mean) flow depth */ | |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
85 if (result.hasMin()) |
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
86 facets.add(FlowDepthProcessor.createFlowDepthMinFacet(context, hash, this.id, result, index)); |
8946 | 87 |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
88 if (result.hasMax()) |
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
89 facets.add(FlowDepthProcessor.createFlowDepthMaxFacet(context, hash, this.id, result, index)); |
8946 | 90 } |
91 | |
92 if (!resultList.isEmpty()) { | |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
93 facets.add(new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id)); |
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
94 facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
8946 | 95 } |
96 | |
97 final Calculation report = res.getReport(); | |
98 if (report.hasProblems()) | |
99 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); | |
100 | |
101 return res; | |
102 } | |
103 | |
104 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { | |
105 if (old instanceof CalculationResult) | |
106 return (CalculationResult) old; | |
107 | |
108 return new FlowDepthMinMaxCalculation(context).calculate(sinfo); | |
109 } | |
110 } |