Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/minfo/SedimentLoadCalculate.java @ 4372:19772b414d46
New facet and result set for sediment load.
* Added new facet and updated sediment load config and facet types.
* Added new result set for sediment load.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 14:53:51 +0100 |
parents | a30647abf009 |
children | 3e1810e72199 |
comparison
equal
deleted
inserted
replaced
4371:26afee1b8959 | 4372:19772b414d46 |
---|---|
1 package de.intevation.flys.artifacts.states.minfo; | 1 package de.intevation.flys.artifacts.states.minfo; |
2 | 2 |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import de.intevation.artifactdatabase.state.Facet; | |
9 import de.intevation.artifacts.CallContext; | |
10 import de.intevation.artifacts.CallMeta; | |
11 import de.intevation.flys.artifacts.FLYSArtifact; | |
12 import de.intevation.flys.artifacts.access.SedimentLoadAccess; | |
13 import de.intevation.flys.artifacts.model.CalculationResult; | |
14 import de.intevation.flys.artifacts.model.DataFacet; | |
3 import de.intevation.flys.artifacts.model.FacetTypes; | 15 import de.intevation.flys.artifacts.model.FacetTypes; |
16 import de.intevation.flys.artifacts.model.minfo.SedimentLoadCalculation; | |
17 import de.intevation.flys.artifacts.model.minfo.SedimentLoadFacet; | |
18 import de.intevation.flys.artifacts.model.minfo.SedimentLoadResult; | |
19 import de.intevation.flys.artifacts.resources.Resources; | |
4 import de.intevation.flys.artifacts.states.DefaultState; | 20 import de.intevation.flys.artifacts.states.DefaultState; |
5 | 21 |
6 | 22 |
7 public class SedimentLoadCalculate | 23 public class SedimentLoadCalculate |
8 extends DefaultState | 24 extends DefaultState |
9 implements FacetTypes | 25 implements FacetTypes |
10 { | 26 { |
11 | 27 |
28 private static final long serialVersionUID = 1L; | |
29 | |
30 private static final Logger logger = Logger | |
31 .getLogger(SedimentLoadCalculate.class); | |
32 | |
33 public static final String I18N_FACET_SEDIMENTLOAD_COARSE = "facet.sedimentload.coarse"; | |
34 public static final String I18N_FACET_SEDIMENTLOAD_SAND = "facet.sedimentload.sand"; | |
35 public static final String I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE = "facet.sedimentload.fine_middle"; | |
36 public static final String I18N_FACET_SEDIMENTLOAD_SUSPSAND = "facet.sedimentload.susp_sand"; | |
37 public static final String I18N_FACET_SEDIMENTLOAD_SUSPSANDBED = "facet.sediemntload.susp_sand_bed"; | |
38 public static final String I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT = "facet.sedimentload.susp_sediment"; | |
39 public static final String I18N_FACET_SEDIMENTLOAD_TOTAL = "facet.sedimentload.total"; | |
40 | |
41 @Override | |
42 public Object computeAdvance(FLYSArtifact artifact, String hash, | |
43 CallContext context, List<Facet> facets, Object old) { | |
44 logger.debug("SedimentLoadCalculate.computeAdvance"); | |
45 | |
46 List<Facet> newFacets = new ArrayList<Facet>(); | |
47 | |
48 SedimentLoadAccess access = new SedimentLoadAccess(artifact); | |
49 | |
50 CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old | |
51 : new SedimentLoadCalculation().calculate(access); | |
52 | |
53 if (facets == null || res == null) { | |
54 return res; | |
55 } | |
56 | |
57 SedimentLoadResult[] results = (SedimentLoadResult[]) res.getData(); | |
58 | |
59 if (results == null || results.length == 0) { | |
60 logger.warn("Calculation computed no results!"); | |
61 return res; | |
62 } | |
63 | |
64 String type = access.getYearEpoch(); | |
65 if (type.equals("year")) { | |
66 generateYearFacets(context, newFacets, results, getID(), hash); | |
67 } | |
68 else if (type.equals("epoch")) { | |
69 generateEpochFacets(context, newFacets, results, getID(), hash); | |
70 } | |
71 else if (type.equals("off_epoch")) { | |
72 generateOffEpochFacets(context, newFacets, results, getID(), hash); | |
73 } | |
74 logger.debug("Created " + newFacets.size() + " new Facets."); | |
75 | |
76 facets.addAll(newFacets); | |
77 | |
78 return res; | |
79 } | |
80 | |
81 protected void generateYearFacets(CallContext context, List<Facet> newFacets, | |
82 SedimentLoadResult[] results, String stateId, String hash) { | |
83 logger.debug("SedimentLoadCalculate.generateFacets"); | |
84 | |
85 CallMeta meta = context.getMeta(); | |
86 | |
87 // newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
88 for (int idx = 0; idx < results.length; idx++) { | |
89 SedimentLoadResult res = results[idx]; | |
90 if (res.hasCoarseData()) { | |
91 newFacets.add(new SedimentLoadFacet( | |
92 idx, | |
93 SEDIMENT_LOAD_COARSE, | |
94 Resources.getMsg( | |
95 meta, | |
96 I18N_FACET_SEDIMENTLOAD_COARSE, | |
97 I18N_FACET_SEDIMENTLOAD_COARSE) + | |
98 " - " + res.getStartYear(), | |
99 ComputeType.ADVANCE, | |
100 stateId, | |
101 hash)); | |
102 } | |
103 if (res.hasSandData()) { | |
104 newFacets.add(new SedimentLoadFacet( | |
105 idx, | |
106 SEDIMENT_LOAD_SAND, | |
107 Resources.getMsg( | |
108 meta, | |
109 I18N_FACET_SEDIMENTLOAD_SAND, | |
110 I18N_FACET_SEDIMENTLOAD_SAND) + | |
111 " - " + res.getStartYear(), | |
112 ComputeType.ADVANCE, | |
113 stateId, | |
114 hash)); | |
115 } | |
116 if (res.hasFineMiddleData()) { | |
117 newFacets.add(new SedimentLoadFacet( | |
118 idx, | |
119 SEDIMENT_LOAD_FINEMIDDLE, | |
120 Resources.getMsg( | |
121 meta, | |
122 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, | |
123 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + | |
124 " - " + res.getStartYear(), | |
125 ComputeType.ADVANCE, | |
126 stateId, | |
127 hash)); | |
128 } | |
129 if (res.hasSuspSandData()) { | |
130 newFacets.add(new SedimentLoadFacet( | |
131 idx, | |
132 SEDIMENT_LOAD_SUSP_SAND, | |
133 Resources.getMsg( | |
134 meta, | |
135 I18N_FACET_SEDIMENTLOAD_SUSPSAND, | |
136 I18N_FACET_SEDIMENTLOAD_SUSPSAND) | |
137 + " - " + res.getStartYear(), | |
138 ComputeType.ADVANCE, | |
139 stateId, | |
140 hash)); | |
141 } | |
142 if (res.hasSuspSandBedData()) { | |
143 newFacets.add(new SedimentLoadFacet( | |
144 idx, | |
145 SEDIMENT_LOAD_SUSP_SAND_BED, | |
146 Resources.getMsg( | |
147 meta, | |
148 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, | |
149 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + | |
150 " - " + res.getStartYear(), | |
151 ComputeType.ADVANCE, | |
152 stateId, | |
153 hash)); | |
154 } | |
155 if (res.hasSuspSedimentData()) { | |
156 newFacets.add(new SedimentLoadFacet( | |
157 idx, | |
158 SEDIMENT_LOAD_SUSP_SEDIMENT, | |
159 Resources.getMsg( | |
160 meta, | |
161 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, | |
162 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + | |
163 " - " + res.getStartYear(), | |
164 ComputeType.ADVANCE, | |
165 stateId, | |
166 hash)); | |
167 | |
168 } | |
169 if (res.hasTotalData()) { | |
170 newFacets.add(new SedimentLoadFacet( | |
171 idx, | |
172 SEDIMENT_LOAD_TOTAL, | |
173 Resources.getMsg( | |
174 meta, | |
175 I18N_FACET_SEDIMENTLOAD_TOTAL, | |
176 I18N_FACET_SEDIMENTLOAD_TOTAL) + | |
177 " - " + res.getStartYear(), | |
178 ComputeType.ADVANCE, | |
179 stateId, | |
180 hash)); | |
181 } | |
182 } | |
183 } | |
184 | |
185 protected void generateEpochFacets( | |
186 CallContext context, | |
187 List<Facet> newFacets, | |
188 SedimentLoadResult[] results, | |
189 String stateId, | |
190 String hash | |
191 ) { | |
192 logger.debug("SedimentLoadCalculate.generateEpochFacets"); | |
193 | |
194 CallMeta meta = context.getMeta(); | |
195 | |
196 // newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
197 for (int idx = 0; idx < results.length; idx++) { | |
198 SedimentLoadResult res = results[idx]; | |
199 if (res.hasCoarseData()) { | |
200 newFacets.add(new SedimentLoadFacet( | |
201 idx, | |
202 SEDIMENT_LOAD_COARSE, | |
203 Resources.getMsg( | |
204 meta, | |
205 I18N_FACET_SEDIMENTLOAD_COARSE, | |
206 I18N_FACET_SEDIMENTLOAD_COARSE) + | |
207 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
208 ComputeType.ADVANCE, | |
209 stateId, | |
210 hash)); | |
211 } | |
212 if (res.hasSandData()) { | |
213 newFacets.add(new SedimentLoadFacet( | |
214 idx, | |
215 SEDIMENT_LOAD_SAND, | |
216 Resources.getMsg( | |
217 meta, | |
218 I18N_FACET_SEDIMENTLOAD_SAND, | |
219 I18N_FACET_SEDIMENTLOAD_SAND) + | |
220 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
221 ComputeType.ADVANCE, | |
222 stateId, | |
223 hash)); | |
224 } | |
225 if (res.hasFineMiddleData()) { | |
226 newFacets.add(new SedimentLoadFacet( | |
227 idx, | |
228 SEDIMENT_LOAD_FINEMIDDLE, | |
229 Resources.getMsg( | |
230 meta, | |
231 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, | |
232 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + | |
233 " - " + res.getStartYear(), | |
234 ComputeType.ADVANCE, | |
235 stateId, | |
236 hash)); | |
237 } | |
238 if (res.hasSuspSandData()) { | |
239 newFacets.add(new SedimentLoadFacet( | |
240 idx, | |
241 SEDIMENT_LOAD_SUSP_SAND, | |
242 Resources.getMsg( | |
243 meta, | |
244 I18N_FACET_SEDIMENTLOAD_SUSPSAND, | |
245 I18N_FACET_SEDIMENTLOAD_SUSPSAND) | |
246 + " - " + res.getStartYear() + "-" + res.getEndYear(), | |
247 ComputeType.ADVANCE, | |
248 stateId, | |
249 hash)); | |
250 } | |
251 if (res.hasSuspSandBedData()) { | |
252 newFacets.add(new SedimentLoadFacet( | |
253 idx, | |
254 SEDIMENT_LOAD_SUSP_SAND_BED, | |
255 Resources.getMsg( | |
256 meta, | |
257 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, | |
258 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + | |
259 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
260 ComputeType.ADVANCE, | |
261 stateId, | |
262 hash)); | |
263 } | |
264 if (res.hasSuspSedimentData()) { | |
265 newFacets.add(new SedimentLoadFacet( | |
266 idx, | |
267 SEDIMENT_LOAD_SUSP_SEDIMENT, | |
268 Resources.getMsg( | |
269 meta, | |
270 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, | |
271 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + | |
272 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
273 ComputeType.ADVANCE, | |
274 stateId, | |
275 hash)); | |
276 | |
277 } | |
278 if (res.hasTotalData()) { | |
279 newFacets.add(new SedimentLoadFacet( | |
280 idx, | |
281 SEDIMENT_LOAD_TOTAL, | |
282 Resources.getMsg( | |
283 meta, | |
284 I18N_FACET_SEDIMENTLOAD_TOTAL, | |
285 I18N_FACET_SEDIMENTLOAD_TOTAL) + | |
286 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
287 ComputeType.ADVANCE, | |
288 stateId, | |
289 hash)); | |
290 } | |
291 } | |
292 } | |
293 | |
294 protected void generateOffEpochFacets( | |
295 CallContext context, | |
296 List<Facet> newFacets, | |
297 SedimentLoadResult[] results, | |
298 String stateId, | |
299 String hash | |
300 ) { | |
301 logger.debug("SedimentLoadCalculate.generateOffEpochFacets"); | |
302 | |
303 CallMeta meta = context.getMeta(); | |
304 | |
305 // newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
306 for (int idx = 0; idx < results.length; idx++) { | |
307 SedimentLoadResult res = results[idx]; | |
308 if (res.hasCoarseData()) { | |
309 newFacets.add(new SedimentLoadFacet( | |
310 idx, | |
311 SEDIMENT_LOAD_COARSE, | |
312 Resources.getMsg( | |
313 meta, | |
314 I18N_FACET_SEDIMENTLOAD_COARSE, | |
315 I18N_FACET_SEDIMENTLOAD_COARSE) + | |
316 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
317 ComputeType.ADVANCE, | |
318 stateId, | |
319 hash)); | |
320 } | |
321 if (res.hasSandData()) { | |
322 newFacets.add(new SedimentLoadFacet( | |
323 idx, | |
324 SEDIMENT_LOAD_SAND, | |
325 Resources.getMsg( | |
326 meta, | |
327 I18N_FACET_SEDIMENTLOAD_SAND, | |
328 I18N_FACET_SEDIMENTLOAD_SAND) + | |
329 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
330 ComputeType.ADVANCE, | |
331 stateId, | |
332 hash)); | |
333 } | |
334 if (res.hasFineMiddleData()) { | |
335 newFacets.add(new SedimentLoadFacet( | |
336 idx, | |
337 SEDIMENT_LOAD_FINEMIDDLE, | |
338 Resources.getMsg( | |
339 meta, | |
340 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, | |
341 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + | |
342 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
343 ComputeType.ADVANCE, | |
344 stateId, | |
345 hash)); | |
346 } | |
347 if (res.hasSuspSandData()) { | |
348 newFacets.add(new SedimentLoadFacet( | |
349 idx, | |
350 SEDIMENT_LOAD_SUSP_SAND, | |
351 Resources.getMsg( | |
352 meta, | |
353 I18N_FACET_SEDIMENTLOAD_SUSPSAND, | |
354 I18N_FACET_SEDIMENTLOAD_SUSPSAND) + | |
355 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
356 ComputeType.ADVANCE, | |
357 stateId, | |
358 hash)); | |
359 } | |
360 if (res.hasSuspSandBedData()) { | |
361 newFacets.add(new SedimentLoadFacet( | |
362 idx, | |
363 SEDIMENT_LOAD_SUSP_SAND_BED, | |
364 Resources.getMsg( | |
365 meta, | |
366 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, | |
367 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + | |
368 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
369 ComputeType.ADVANCE, | |
370 stateId, | |
371 hash)); | |
372 } | |
373 if (res.hasSuspSedimentData()) { | |
374 newFacets.add(new SedimentLoadFacet( | |
375 idx, | |
376 SEDIMENT_LOAD_SUSP_SEDIMENT, | |
377 Resources.getMsg( | |
378 meta, | |
379 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, | |
380 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + | |
381 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
382 ComputeType.ADVANCE, | |
383 stateId, | |
384 hash)); | |
385 | |
386 } | |
387 if (res.hasTotalData()) { | |
388 newFacets.add(new SedimentLoadFacet( | |
389 idx, | |
390 SEDIMENT_LOAD_TOTAL, | |
391 Resources.getMsg( | |
392 meta, | |
393 I18N_FACET_SEDIMENTLOAD_TOTAL, | |
394 I18N_FACET_SEDIMENTLOAD_TOTAL) + | |
395 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
396 ComputeType.ADVANCE, | |
397 stateId, | |
398 hash)); | |
399 } | |
400 } | |
401 } | |
12 } | 402 } |