comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 687:06689035024c facets-slt

Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states. flys-artifacts/branches/facets-slt@2127 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 07:50:56 +0000
parents 3dc61e00385e
children f8ac04b2dbd0
comparison
equal deleted inserted replaced
686:3dc61e00385e 687:06689035024c
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import java.util.List; 3 import java.util.List;
4 import java.util.Map;
4 5
5 import org.w3c.dom.Document; 6 import org.w3c.dom.Document;
6 import org.w3c.dom.Element; 7 import org.w3c.dom.Element;
7 import org.w3c.dom.Node; 8 import org.w3c.dom.Node;
8 9
25 import de.intevation.flys.artifacts.states.CalculationSelect; 26 import de.intevation.flys.artifacts.states.CalculationSelect;
26 import de.intevation.flys.artifacts.states.DefaultState; 27 import de.intevation.flys.artifacts.states.DefaultState;
27 import de.intevation.flys.artifacts.context.FLYSContext; 28 import de.intevation.flys.artifacts.context.FLYSContext;
28 29
29 import de.intevation.flys.artifacts.model.ComputeCallback; 30 import de.intevation.flys.artifacts.model.ComputeCallback;
31 import de.intevation.flys.artifacts.model.DischargeTables;
30 import de.intevation.flys.artifacts.model.MainValuesFactory; 32 import de.intevation.flys.artifacts.model.MainValuesFactory;
31 import de.intevation.flys.artifacts.model.WQDay; 33 import de.intevation.flys.artifacts.model.WQDay;
32 import de.intevation.flys.artifacts.model.WQKms; 34 import de.intevation.flys.artifacts.model.WQKms;
33 import de.intevation.flys.artifacts.model.WstValueTable; 35 import de.intevation.flys.artifacts.model.WstValueTable;
34 import de.intevation.flys.artifacts.model.WstValueTableFactory; 36 import de.intevation.flys.artifacts.model.WstValueTableFactory;
241 // 243 //
242 // METHODS FOR RETRIEVING COMPUTED DATA FOR DIFFERENT CHART TYPES 244 // METHODS FOR RETRIEVING COMPUTED DATA FOR DIFFERENT CHART TYPES
243 // 245 //
244 246
245 247
246 public Object compute() { 248 /**
247 return compute(hash()); 249 * Dispatches the computation request to compute(CallContext context, String
248 } 250 * hash) with the current hash value of the artifact which is provided by
249 251 * hash().
250 252 *
251 public Object compute(String hash) { 253 * @param context The CallContext.
254 */
255 public Object compute(CallContext context) {
256 return compute(context, hash());
257 }
258
259
260 /**
261 * Dispatches computation requests to the current state which needs to
262 * implement a createComputeCallback(String hash, FLYSArtifact artifact)
263 * method.
264 *
265 * @param context The CallContext.
266 * @param hash The hash value which is used to fetch computed data from
267 * cache.
268 *
269 * @return the computed data.
270 */
271 public Object compute(CallContext context, String hash) {
252 String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue(); 272 String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue();
253 273
254 ComputeCallback callback = null; 274 DefaultState current = (DefaultState) getCurrentState(context);
255 275
256 if (calc.equals(CalculationSelect.CALCULATION_SURFACE_CURVE)) { 276 ComputeCallback callback = current.createComputeCallback(hash(), this);
257 callback = createSurfaceCurveCallback(); 277
258 } 278 if (callback == null) {
259 else if (calc.equals(CalculationSelect.CALCULATION_DURATION_CURVE)) { 279 logger.info("There is no data which needs to be computed.");
260 callback = createDurationCurveCallback();
261 }
262 else if (
263 calc.equals(
264 CalculationSelect.CALCULATION_DISCHARGE_LONGITUDINAL_CURVE))
265 {
266 callback = createDischargeLongitudinalCurveCallback();
267 }
268 else if (calc.equals(CalculationSelect.CALCULATION_DISCHARGE_CURVE)) {
269 callback = createDischargeCurveCallback();
270 }
271 else {
272 return null; 280 return null;
273 } 281 }
274 282
275 return compute(hash, callback); 283 return compute(hash, callback);
276 }
277
278
279 protected ComputeCallback createSurfaceCurveCallback() {
280 return new ComputeCallback() {
281 public Object compute() {
282 return getWaterlevelData();
283 }
284 };
285 }
286
287
288 protected ComputeCallback createDurationCurveCallback() {
289 return new ComputeCallback() {
290 public Object compute() {
291 return getDurationCurveData();
292 }
293 };
294 }
295
296
297 protected ComputeCallback createDischargeLongitudinalCurveCallback() {
298 return new ComputeCallback() {
299 public Object compute() {
300 return getDischargeLongitudinalSectionData();
301 }
302 };
303 }
304
305
306 protected ComputeCallback createDischargeCurveCallback() {
307 return new ComputeCallback() {
308 public Object compute() {
309 return getComputedDischargeCurveData();
310 }
311 };
312 } 284 }
313 285
314 286
315 /** 287 /**
316 * Returns the data that is computed by a waterlevel computation. 288 * Returns the data that is computed by a waterlevel computation.
440 412
441 Calculation3 calculation = new Calculation3(location, days, qs); 413 Calculation3 calculation = new Calculation3(location, days, qs);
442 414
443 // TODO: report the errors to the user. 415 // TODO: report the errors to the user.
444 return calculation.calculate(wst); 416 return calculation.calculate(wst);
417 }
418
419
420 /**
421 * Returns the data that is used to create discharge curves.
422 *
423 * @return a map where the key is the name of the gauge and a double[][]
424 * which are the values.
425 */
426 public Map<String, double[][]> getDischargeCurveData() {
427 River river = getRiver();
428 List<Gauge> gauges = getGauges();
429
430 if (gauges == null) {
431 logger.warn("No gauges found for the current kilometer range.");
432 return null;
433 }
434
435 int num = gauges.size();
436
437 logger.debug("Found " + num + " gauges.");
438
439 String[] gaugeNames = new String[num];
440
441 for (int i = 0; i < num; i++) {
442 gaugeNames[i] = gauges.get(i).getName();
443 }
444
445 DischargeTables dt = new DischargeTables(river.getName(), gaugeNames);
446
447 return dt.getValues(100d);
445 } 448 }
446 449
447 450
448 /** 451 /**
449 * Returns the data that is computed by a discharge curve computation. 452 * Returns the data that is computed by a discharge curve computation.

http://dive4elements.wald.intevation.org