annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxState.java @ 9150:23945061daec

gigantic refactoring: exporter, result, results to support multiple jaspers -> collisions
author gernotbelger
date Thu, 14 Jun 2018 16:56:31 +0200
parents 0adc6d04de95
children a4121ec450d6
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;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8993
diff changeset
17 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.Calculation;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
19 import org.dive4elements.river.artifacts.model.CalculationResult;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.artifacts.model.DataFacet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.artifacts.model.EmptyFacet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.model.FacetTypes;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.artifacts.model.ReportFacet;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
8950
b0aeed4c97c1 Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents: 8946
diff changeset
25 import org.dive4elements.river.artifacts.sinfo.common.FlowDepthProcessor;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
26 import org.dive4elements.river.artifacts.states.DefaultState;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
27
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
28 /** State in which a waterlevel has been calculated. */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
29 public class FlowDepthMinMaxState extends DefaultState {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
30
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
31 /// ** The log that is used in this state. */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
32 // private static Logger log = Logger.getLogger(FlowDepthState.class);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
33
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
34 private static final long serialVersionUID = 1L;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
35
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
36 /**
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
37 * From this state can only be continued trivially.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
38 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
39 @Override
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
40 protected String getUIProvider() {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
41 return "continue";
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
42 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
43
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
44 @Override
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
45 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
46 // FIXME: why is this necessary?
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
47 if (artifact instanceof ChartArtifact) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
48 facets.add(new EmptyFacet());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
49 return null;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
50 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
51
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
52 return compute((SINFOArtifact) artifact, context, hash, facets, old);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
53 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
54
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
55 @Override
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
56 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
57 if (artifact instanceof ChartArtifact) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
58 facets.add(new EmptyFacet());
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
59 return null;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
60 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
61 return compute((SINFOArtifact) artifact, context, hash, facets, old);
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 /**
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
65 * Compute result or returned object from cache, create facets.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
66 *
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
67 * @param old
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
68 * Object that was cached.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
69 */
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
70 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
71
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
72 final CalculationResult res = doCompute(sinfo, context, old);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
73
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
74 if (facets == null)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
75 return res;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
76
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
77 final FlowDepthMinMaxCalculationResults results = (FlowDepthMinMaxCalculationResults) res.getData();
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
78
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
79 /* add themes for chart, for each result */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8993
diff changeset
80 final List<AbstractCalculationExportableResult<FlowDepthMinMaxCalculationResults>> resultList = results.getResults();
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
81 for (int index = 0; index < resultList.size(); index++) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
82
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8993
diff changeset
83 final FlowDepthMinMaxCalculationResult result = (FlowDepthMinMaxCalculationResult) resultList.get(index);
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
84
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
diff changeset
85 /* filtered (zoom dependent mean) flow depth */
8993
0adc6d04de95 SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents: 8980
diff changeset
86 facets.add(FlowDepthProcessor.createFlowDepthMinFilteredFacet(context, hash, this.id, result, index));
0adc6d04de95 SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents: 8980
diff changeset
87 facets.add(FlowDepthProcessor.createFlowDepthMinRawFacet(context, hash, this.id, result, index));
0adc6d04de95 SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents: 8980
diff changeset
88 facets.add(FlowDepthProcessor.createFlowDepthMaxFilteredFacet(context, hash, this.id, result, index));
0adc6d04de95 SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents: 8980
diff changeset
89 facets.add(FlowDepthProcessor.createFlowDepthMaxRawFacet(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