Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthState.java @ 8946:5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
author | gernotbelger |
---|---|
date | Tue, 13 Mar 2018 18:49:33 +0100 |
parents | 82998242ba84 |
children | b194fa64506a |
rev | line source |
---|---|
8854 | 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.flowdepth; | |
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; | |
8940
82998242ba84
Preparing for additional outputs of SINFO-Tkh
gernotbelger
parents:
8916
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.common.FlowDepthProcessor; |
8916 | 25 import org.dive4elements.river.artifacts.sinfo.common.TkhProcessor; |
8854 | 26 import org.dive4elements.river.artifacts.states.DefaultState; |
27 | |
28 /** State in which a waterlevel has been calculated. */ | |
8884 | 29 public class FlowDepthState extends DefaultState { |
30 | |
8854 | 31 /// ** The log that is used in this state. */ |
32 // private static Logger log = Logger.getLogger(FlowDepthState.class); | |
33 | |
8877 | 34 private static final long serialVersionUID = 1L; |
35 | |
8854 | 36 /** |
37 * From this state can only be continued trivially. | |
38 */ | |
39 @Override | |
40 protected String getUIProvider() { | |
41 return "continue"; | |
42 } | |
43 | |
44 @Override | |
8884 | 45 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
8879 | 46 // FIXME: why is this necessary? |
47 if (artifact instanceof ChartArtifact) { | |
48 facets.add(new EmptyFacet()); | |
49 return null; | |
50 } | |
51 | |
52 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
53 } | |
54 | |
55 @Override | |
8884 | 56 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
8854 | 57 if (artifact instanceof ChartArtifact) { |
58 facets.add(new EmptyFacet()); | |
59 return null; | |
60 } | |
61 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
62 } | |
63 | |
64 /** | |
65 * Compute result or returned object from cache, create facets. | |
8884 | 66 * |
67 * @param old | |
68 * Object that was cached. | |
8854 | 69 */ |
8884 | 70 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { |
8879 | 71 |
8914
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
72 final CalculationResult res = doCompute(sinfo, context, old); |
8854 | 73 |
8914
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
74 if (facets == null) |
8854 | 75 return res; |
76 | |
8884 | 77 final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); |
8854 | 78 |
79 /* add themes for chart, for each result */ | |
80 final List<FlowDepthCalculationResult> resultList = results.getResults(); | |
81 for (int index = 0; index < resultList.size(); index++) { | |
82 | |
8879 | 83 final FlowDepthCalculationResult result = resultList.get(index); |
84 | |
85 /* filtered (zoom dependent mean) flow depth */ | |
8940
82998242ba84
Preparing for additional outputs of SINFO-Tkh
gernotbelger
parents:
8916
diff
changeset
|
86 facets.add(FlowDepthProcessor.createFlowDepthFacet(context, hash, this.id, result, index)); |
8879 | 87 |
8884 | 88 if (results.isUseTkh()) { |
89 /* filtered (zoom dependent mean) flow depth including tkh */ | |
8940
82998242ba84
Preparing for additional outputs of SINFO-Tkh
gernotbelger
parents:
8916
diff
changeset
|
90 facets.add(FlowDepthProcessor.createFlowDepthTkhFacet(context, hash, this.id, result, index)); |
8884 | 91 |
8916 | 92 facets.add(TkhProcessor.createTkhFacet(context, hash, this.id, result, index)); |
8884 | 93 } |
8879 | 94 } |
8854 | 95 |
8884 | 96 if (!resultList.isEmpty()) { |
97 final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); | |
98 final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); | |
8854 | 99 |
100 facets.add(csv); | |
101 facets.add(pdf); | |
102 } | |
103 | |
104 final Calculation report = res.getReport(); | |
105 | |
106 if (report.hasProblems()) { | |
8879 | 107 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
8854 | 108 } |
109 | |
110 return res; | |
111 } | |
8914
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
112 |
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
113 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { |
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
114 if (old instanceof CalculationResult) |
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
115 return (CalculationResult) old; |
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
116 |
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
117 return new FlowDepthCalculation(context).calculate(sinfo); |
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8884
diff
changeset
|
118 } |
8854 | 119 } |