Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxState.java @ 9195:a4121ec450d6
'ca.'-issue
ExportContextCSV+PDF separated
uinfo.inundationduration url export
author | gernotbelger |
---|---|
date | Fri, 29 Jun 2018 14:52:54 +0200 |
parents | 23945061daec |
children | 1d4262a68f1f |
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 */ | |
9195 | 79 final List<FlowDepthMinMaxCalculationResult> resultList = results.getResults(); |
8946 | 80 for (int index = 0; index < resultList.size(); index++) { |
81 | |
9195 | 82 final FlowDepthMinMaxCalculationResult result = resultList.get(index); |
8946 | 83 |
84 /* 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
|
85 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
|
86 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
|
87 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
|
88 facets.add(FlowDepthProcessor.createFlowDepthMaxRawFacet(context, hash, this.id, result, index)); |
8946 | 89 } |
90 | |
91 if (!resultList.isEmpty()) { | |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
92 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
|
93 facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
8946 | 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 } |