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