Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 362:d79a51fc4f1d
Added necessary methods to start the computation of waterlevel data.
flys-artifacts/trunk@1770 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 29 Apr 2011 07:46:27 +0000 |
parents | d97982627596 |
children | 3e66a5705c39 |
comparison
equal
deleted
inserted
replaced
361:3e3ec9613883 | 362:d79a51fc4f1d |
---|---|
58 /** The constant string that shows that an operation was successful.*/ | 58 /** The constant string that shows that an operation was successful.*/ |
59 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; | 59 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; |
60 | 60 |
61 /** The constant string that shows that an operation failed.*/ | 61 /** The constant string that shows that an operation failed.*/ |
62 public static final String OPERATION_FAILED = "FAILURE"; | 62 public static final String OPERATION_FAILED = "FAILURE"; |
63 | |
64 /** The default number of steps between the start end end of a selected Q | |
65 * range.*/ | |
66 public static final int DEFAULT_Q_STEPS = 30; | |
63 | 67 |
64 | 68 |
65 /** The identifier of the current state. */ | 69 /** The identifier of the current state. */ |
66 protected String currentStateId; | 70 protected String currentStateId; |
67 | 71 |
474 return new double[] { from, to }; | 478 return new double[] { from, to }; |
475 } | 479 } |
476 | 480 |
477 | 481 |
478 /** | 482 /** |
483 * Returns the selected Kms. | |
484 * | |
485 * @return the selected Kms. | |
486 */ | |
487 public double[] getKms() { | |
488 StateData dStep = getData("ld_step"); | |
489 | |
490 if (dStep == null) { | |
491 logger.warn("No step width given. Cannot compute Kms."); | |
492 return null; | |
493 } | |
494 | |
495 double step = Double.parseDouble((String) dStep.getValue()); | |
496 double[] distance = getDistance(); | |
497 double lower = distance[0]; | |
498 | |
499 // transform step from 'm' into 'km' | |
500 step = step / 1000; | |
501 | |
502 return getExplodedValues(distance[0], distance[1], step); | |
503 } | |
504 | |
505 | |
506 /** | |
479 * Returns the gauge based on the current distance and river. | 507 * Returns the gauge based on the current distance and river. |
480 * | 508 * |
481 * @return the gauge. | 509 * @return the gauge. |
482 */ | 510 */ |
483 public Gauge getGauge() { | 511 public Gauge getGauge() { |
495 String name = gauge != null ? gauge.getName() : "'n/a"; | 523 String name = gauge != null ? gauge.getName() : "'n/a"; |
496 logger.debug("Found gauge: " + name); | 524 logger.debug("Found gauge: " + name); |
497 | 525 |
498 return gauge; | 526 return gauge; |
499 } | 527 } |
528 | |
529 | |
530 /** | |
531 * This method returns the Q values. | |
532 * | |
533 * @return the selected Q values or null, if no Q values are selected. | |
534 */ | |
535 public double[] getQs() { | |
536 StateData dFrom = getData("wq_from"); | |
537 StateData dTo = getData("wq_to"); | |
538 | |
539 if (dFrom == null || dTo == null) { | |
540 logger.warn("Missing start or end value for Q range."); | |
541 return null; | |
542 } | |
543 | |
544 double from = Double.parseDouble((String) dFrom.getValue()); | |
545 double to = Double.parseDouble((String) dTo.getValue()); | |
546 | |
547 StateData dStep = getData("wq_step"); | |
548 | |
549 if (dStep == null) { | |
550 logger.warn("No step width given. Cannot compute Qs."); | |
551 return null; | |
552 } | |
553 | |
554 double step = Double.parseDouble((String) dStep.getValue()); | |
555 | |
556 // if no width is given, the DEFAULT_Q_STEPS is used to compute the step | |
557 // width. Maybe, we should round the value to a number of digits. | |
558 if (step == 0d) { | |
559 double diff = to - from; | |
560 step = diff / DEFAULT_Q_STEPS; | |
561 } | |
562 | |
563 return getExplodedValues(from, to, step); | |
564 } | |
565 | |
566 | |
567 /** | |
568 * Returns an array of double values. The values contained in this array | |
569 * begin with the value <i>from</i> and end with the value <i>to</i>. The | |
570 * number of values in the result array depends on the <i>step</i> width. | |
571 * | |
572 * @param from The lower value. | |
573 * @param to The upper value. | |
574 * @param step The step width between two values in the result array. | |
575 * | |
576 * @return an array of double values. | |
577 */ | |
578 public double[] getExplodedValues(double from, double to, double step) { | |
579 double lower = from; | |
580 | |
581 double diff = to - from; | |
582 double tmp = (diff * 100 / step); | |
583 int tmpN = (int) (tmp / 100); | |
584 int num = tmpN + 2; | |
585 | |
586 double[] values = new double[num]; | |
587 int idx = 0; | |
588 | |
589 do { | |
590 values[idx++] = lower; | |
591 lower += step; | |
592 } | |
593 while (lower < to); | |
594 | |
595 values[idx] = to; | |
596 | |
597 return values; | |
598 } | |
500 } | 599 } |
501 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 600 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |