changeset 2230:59af81364eb1

Improved the 'historical discharge' calculation: implemented findValueForW(). flys-artifacts/trunk@3872 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Feb 2012 15:41:11 +0000
parents 9dc81827b187
children 5648b5b34ae2
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java
diffstat 3 files changed, 60 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Feb 01 15:00:13 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Feb 01 15:41:11 2012 +0000
@@ -1,3 +1,12 @@
+2012-02-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
+	  Moved code to load values of a discharge table into an own static
+	  function to be able to reuse it in Calculation6.
+
+	* src/main/java/de/intevation/flys/artifacts/model/Calculation6.java:
+	  Implemented the findValueForW().
+
 2012-02-01  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Fake some reference curve input values to have working prototype
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java	Wed Feb 01 15:00:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java	Wed Feb 01 15:41:11 2012 +0000
@@ -26,6 +26,8 @@
     public static final int MODE_W = 0;
     public static final int MODE_Q = 1;
 
+    public static final double SCALE = 100d;
+
 
     public Calculation6(int mode, long[] timerange, double[] values) {
         this.mode      = mode;
@@ -115,6 +117,8 @@
     protected WQTimerange[] prepareCalculationData(List<DischargeTable> dts) {
         List<WQTimerange> wqts = new ArrayList<WQTimerange>(values.length);
 
+        boolean debug = logger.isDebugEnabled();
+
         for (double value: values) {
             logger.debug("Prepare data for value: " + value);
 
@@ -137,6 +141,10 @@
                     w = findValueForQ(dt, q);
                 }
 
+                if (debug) {
+                    logger.debug("Q=" + q + " | W=" + w);
+                }
+
                 wqt.add(w, q, t);
             }
 
@@ -148,13 +156,15 @@
 
 
     protected double findValueForW(DischargeTable dt, double w) {
-        logger.warn("TODO: IMPLEMENT ME!");
-        return 5;
+        double[][] vs = DischargeTables.loadDischargeTableValues(dt,SCALE,true);
+        return DischargeTables.getQForW(vs, w);
     }
 
 
     protected double findValueForQ(DischargeTable dt, double q) {
+        double[][] vs = DischargeTables.loadDischargeTableValues(dt,SCALE,true);
         logger.warn("TODO: IMPLEMENT ME!");
+
         return 10;
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Wed Feb 01 15:00:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Wed Feb 01 15:41:11 2012 +0000
@@ -124,27 +124,10 @@
             // TODO: Filter by time interval
             DischargeTable table = tables.get(0);
 
-            List<DischargeTableValue> dtvs =
-                table.getDischargeTableValues();
-
-            final double [][] vs = new double[2][dtvs.size()];
-
             boolean qSorted = true;
 
-            double lastQ = -Double.MAX_VALUE;
-
-            int idx = 0;
-            for (DischargeTableValue dtv: dtvs) {
-                double q = dtv.getQ().doubleValue();
-                vs[0][idx] = q * scale;
-                vs[1][idx] = dtv.getW().doubleValue() * scale;
-                ++idx;
-
-                if (qSorted && lastQ > q) {
-                    qSorted = false;
-                }
-                lastQ = q;
-            }
+            final double[][] vs =
+                loadDischargeTableValues(table, scale, qSorted);
 
             if (!qSorted) {
                 log.debug("need to sort by q values");
@@ -182,6 +165,43 @@
         return values;
     }
 
+
+    /**
+     * @param table The discharge table
+     * @param scale The scale factor to adjust W and Q values.
+     * @param qSorted Boolean flag that is used to evaluate if the values should
+     * be sorted.
+     *
+     * @return the values of a discharge table.
+     */
+    public static double[][] loadDischargeTableValues(
+        DischargeTable table,
+        double         scale,
+        boolean        qSorted
+    ) {
+        List<DischargeTableValue> dtvs = table.getDischargeTableValues();
+
+        final double [][] vs = new double[2][dtvs.size()];
+
+        double lastQ = -Double.MAX_VALUE;
+
+        int idx = 0;
+        for (DischargeTableValue dtv: dtvs) {
+            double q = dtv.getQ().doubleValue();
+            vs[0][idx] = q * scale;
+            vs[1][idx] = dtv.getW().doubleValue() * scale;
+            ++idx;
+
+            if (qSorted && lastQ > q) {
+                qSorted = false;
+            }
+            lastQ = q;
+        }
+
+        return vs;
+    }
+
+
     public static double getQForW(double [][] values, double w) {
 
         boolean debug = log.isDebugEnabled();

http://dive4elements.wald.intevation.org