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
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
2 * Software engineering by Intevation GmbH
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
3 *
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
7 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
8
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
9 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
10
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
11 import java.util.List;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
12
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
13 import org.dive4elements.artifactdatabase.state.Facet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
14 import org.dive4elements.artifacts.CallContext;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
15 import org.dive4elements.river.artifacts.ChartArtifact;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
16 import org.dive4elements.river.artifacts.D4EArtifact;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
17 import org.dive4elements.river.artifacts.model.Calculation;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.CalculationResult;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
19 import org.dive4elements.river.artifacts.model.DataFacet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.artifacts.model.EmptyFacet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.artifacts.model.FacetTypes;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.model.ReportFacet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
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
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
25 import org.dive4elements.river.artifacts.states.DefaultState;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
26
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
27 /** State in which a waterlevel has been calculated. */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
28 public class FlowDepthMinMaxState extends DefaultState {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
29
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
30 /// ** The log that is used in this state. */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
31 // private static Logger log = Logger.getLogger(FlowDepthState.class);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
32
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
33 private static final long serialVersionUID = 1L;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
34
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
35 /**
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
36 * From this state can only be continued trivially.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
37 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
38 @Override
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
39 protected String getUIProvider() {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
40 return "continue";
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
41 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
42
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
43 @Override
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
44 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
45 // FIXME: why is this necessary?
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
46 if (artifact instanceof ChartArtifact) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
47 facets.add(new EmptyFacet());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
48 return null;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
49 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
50
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
51 return compute((SINFOArtifact) artifact, context, hash, facets, old);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
52 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
53
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
54 @Override
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
55 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
56 if (artifact instanceof ChartArtifact) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
57 facets.add(new EmptyFacet());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
58 return null;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
59 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
60 return compute((SINFOArtifact) artifact, context, hash, facets, old);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
61 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
62
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
63 /**
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
64 * Compute result or returned object from cache, create facets.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
65 *
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
66 * @param old
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
67 * Object that was cached.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
68 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
69 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
70
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
71 final CalculationResult res = doCompute(sinfo, context, old);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
72
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
73 if (facets == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
74 return res;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
75
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
76 final FlowDepthMinMaxCalculationResults results = (FlowDepthMinMaxCalculationResults) res.getData();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
77
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
78 /* add themes for chart, for each result */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
79 final List<FlowDepthMinMaxCalculationResult> resultList = results.getResults();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
80 for (int index = 0; index < resultList.size(); index++) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
81
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
82 final FlowDepthMinMaxCalculationResult result = resultList.get(index);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
83
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
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
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
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
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
90 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
91
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
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
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
95 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
96
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
97 final Calculation report = res.getReport();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
98 if (report.hasProblems())
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
99 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id));
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
100
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
101 return res;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
102 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
103
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
104 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
105 if (old instanceof CalculationResult)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
106 return (CalculationResult) old;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
107
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
108 return new FlowDepthMinMaxCalculation(context).calculate(sinfo);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
109 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
110 }

http://dive4elements.wald.intevation.org