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

http://dive4elements.wald.intevation.org