comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthState.java @ 8854:7bbfb24e6eec

SINFO - first prototype of BArt Fließtiefen
author gernotbelger
date Thu, 18 Jan 2018 18:34:41 +0100
parents
children 9f7a285b0ee3
comparison
equal deleted inserted replaced
8853:8c64617a7991 8854:7bbfb24e6eec
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. */
28 public class FlowDepthState
29 extends DefaultState
30 {
31 /// ** The log that is used in this state. */
32 // private static Logger log = Logger.getLogger(FlowDepthState.class);
33
34 private static final String I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.filtered.description";
35
36 /**
37 * From this state can only be continued trivially.
38 */
39 @Override
40 protected String getUIProvider() {
41 return "continue";
42 }
43
44 @Override
45 public Object computeFeed(
46 final D4EArtifact artifact,
47 final String hash,
48 final CallContext context,
49 final List<Facet> facets,
50 final Object old
51 ) {
52 // FIXME: why is this necessary?
53 if (artifact instanceof ChartArtifact) {
54 facets.add(new EmptyFacet());
55 return null;
56 }
57 return compute((SINFOArtifact) artifact, context, hash, facets, old);
58 }
59
60 @Override
61 public Object computeAdvance(
62 final D4EArtifact artifact,
63 final String hash,
64 final CallContext context,
65 final List<Facet> facets,
66 final Object old
67 ) {
68 if (artifact instanceof ChartArtifact) {
69 facets.add(new EmptyFacet());
70 return null;
71 }
72 return compute((SINFOArtifact) artifact, context, hash, facets, old);
73 }
74
75 /**
76 * Compute result or returned object from cache, create facets.
77 * @param old Object that was cached.
78 */
79 private Object compute(
80 final SINFOArtifact sinfo,
81 final CallContext context,
82 final String hash,
83 final List<Facet> facets,
84 final Object old
85 ) {
86 final CalculationResult res;
87 if (old instanceof CalculationResult)
88 res = (CalculationResult) old;
89 else
90 res = new FlowDepthCalculation(context).calculate(sinfo);
91
92 if (facets == null) {
93 return res;
94 }
95
96 final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData();
97
98 /* add themes for chart, for each result */
99 final List<FlowDepthCalculationResult> resultList = results.getResults();
100 for (int index = 0; index < resultList.size(); index++) {
101
102 final FlowDepthCalculationResult result = resultList.get(index);
103 /* compute theme label */
104 final String wspLabel = result.getWstLabel();
105 final String soundingLabel = result.getSoundingLabel();
106 final String inputLabel = String.format("%s - %s", wspLabel, soundingLabel);
107
108 /* filtered (zoom dependent mean) flow depth */
109 final String facetFlowDepthFilteredDescription = Resources.getMsg( context.getMeta(), I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, inputLabel );
110 facets.add(new FlowDepthFilterFacet(
111 index,
112 FlowDepthProcessor.FACET_FLOW_DEPTH_FILTERED,
113 facetFlowDepthFilteredDescription,
114 ComputeType.ADVANCE,
115 id,
116 hash
117 ));
118
119 // FIXME: add other themes
120 }
121
122 if (!resultList.isEmpty() ) {
123 Facet csv = new DataFacet(
124 FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, id);
125 Facet pdf = new DataFacet(
126 FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, id);
127
128 facets.add(csv);
129 facets.add(pdf);
130 }
131
132 final Calculation report = res.getReport();
133
134 if (report.hasProblems()) {
135 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
136 }
137
138 return res;
139 }
140 }

http://dive4elements.wald.intevation.org