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