changeset 2219:4b6e9b377a84

Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters. flys-artifacts/trunk@3858 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Feb 2012 13:33:58 +0000
parents 39933df6d0fe
children f31d92060f21
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java
diffstat 3 files changed, 82 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Feb 01 13:32:10 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Feb 01 13:33:58 2012 +0000
@@ -1,3 +1,13 @@
+2012-02-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Fetch
+	  necessary parameters for 'historical discharge curve' calculation and call
+	  Calculation6 with those parameters.
+
+	* src/main/java/de/intevation/flys/artifacts/model/Calculation6.java:
+	  Modified default constructor and calculate() signatures and added a
+	  parameter check which is evaluated before the calculation starts.
+
 2012-02-01  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Feb 01 13:32:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Feb 01 13:33:58 2012 +0000
@@ -738,7 +738,15 @@
 
 
     public CalculationResult getHistoricalDischargeData() {
-        return new Calculation6().calculate();
+        Gauge  gauge        = FLYSUtils.getReferenceGauge(this);
+        String rawTimerange = getDataAsString("year_range");
+        String rawValues    = getDataAsString("historical_values");
+        int    mode         = getDataAsInteger("historical_mode");
+
+        int[]    timerange = FLYSUtils.intArrayFromString(rawTimerange);
+        double[] values    = FLYSUtils.doubleArrayFromString(rawValues);
+
+        return new Calculation6(mode, timerange, values).calculate(gauge);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java	Wed Feb 01 13:32:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java	Wed Feb 01 13:33:58 2012 +0000
@@ -2,6 +2,8 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.flys.model.Gauge;
+
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
@@ -10,14 +12,73 @@
 
     private static final Logger logger = Logger.getLogger(Calculation6.class);
 
+    private int      mode;
+    private int[]    timerange;
+    private double[] values;
 
-    public Calculation6() {
+
+    public static final int MODE_W = 0;
+    public static final int MODE_Q = 1;
+
+
+    public Calculation6(int mode, int[] timerange, double[] values) {
+        this.mode      = mode;
+        this.timerange = timerange;
+        this.values    = values;
     }
 
 
-    public CalculationResult calculate() {
+    public CalculationResult calculate(Gauge gauge) {
+        if (!checkParameters() || gauge == null) {
+            logger.warn("Parameters not valid for calculation.");
+
+            return null;
+        }
+
+        if (logger.isDebugEnabled()) {
+            debug();
+        }
+
         logger.warn("TODO: IMPLEMENT ME");
+
         return null;
     }
+
+
+    protected boolean checkParameters() {
+        if (!(mode == MODE_W || mode == MODE_Q)) {
+            logger.warn("Invalid mode '" + mode + "' for calculation.");
+            return false;
+        }
+
+        if (timerange == null || timerange.length < 2) {
+            logger.warn("Invalid timerange for calculation.");
+            return false;
+        }
+
+        if (values == null || values.length == 0) {
+            logger.warn("No values for W or Q specified.");
+            return false;
+        }
+
+        return true;
+    }
+
+
+    /**
+     * Writes the parameters used for this calculation to logger.
+     */
+    public void debug() {
+        StringBuilder sb = new StringBuilder();
+        for (double value: values) {
+            sb.append(String.valueOf(value) + " ");
+        }
+
+        logger.debug("========== Calculation6 ==========");
+        logger.debug("   Mode:         " + mode);
+        logger.debug("   Timerange:    " + timerange[0] + " - " + timerange[1]);
+        logger.debug("   Input values: " + sb.toString());
+        logger.debug("==================================");
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org