comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxState.java @ 8946:5d5d482da3e9

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

http://dive4elements.wald.intevation.org