changeset 735:db68806e6563

Fixed "W am Pegel" calculations. flys-artifacts/trunk@2230 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 25 Jun 2011 17:35:50 +0000
parents 56d70e546800
children d9d9f67af984
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java
diffstat 4 files changed, 83 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jun 24 12:05:13 2011 +0000
+++ b/flys-artifacts/ChangeLog	Sat Jun 25 17:35:50 2011 +0000
@@ -1,3 +1,15 @@
+2011-06-25  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
+	  Conversion w->q was broken. This should fix a number of issues
+	  around "W am Pegel" calculations.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Issue an error report if a w->q conversion fails.
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
+	  The gauge to convert w->q with its discharge table was determined wrong.
+
 2011-06-24  Ingo Weinzierl <ingo@intevation.de>
 
 	  flys/issue174 (Diagramm: Q-Linie wird bei initialem Laden des Diagramms
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Jun 24 12:05:13 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Sat Jun 25 17:35:50 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts;
 
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -493,17 +494,30 @@
      * @return the selected distance or points.
      */
     public double[] getDistance() {
+        StateData dMode      = getData("ld_mode");
         StateData dFrom      = getData("ld_from");
         StateData dTo        = getData("ld_to");
         StateData dLocations = getData("ld_locations");
 
+        if (dMode != null) {
+            String mode = (String)dMode.getValue();
+            if ("location".equals(mode)) {
+                double[] locations = getLocations();
+                return new double[] { locations[0], locations[locations.length-1] };
+            }
+            if (dFrom != null && dTo != null) {
+                return getDistanceByRange(dFrom, dTo);
+            }
+        }
+
+        if (dLocations != null) {
+            double[] locations = getLocations();
+            return new double[] { locations[0], locations[locations.length-1] };
+        }
+
         if (dFrom != null && dTo != null) {
             return getDistanceByRange(dFrom, dTo);
         }
-        else if (dLocations != null) {
-            double[] locations = getLocations();
-            return new double[] { locations[0], locations[locations.length-1] };
-        }
 
         logger.warn("No data found for distance determination!");
 
@@ -664,8 +678,19 @@
      */
     public Gauge getGauge() {
         River    river = getRiver();
+
+        if (river == null) {
+            logger.debug("no river found");
+            return null;
+        }
+
         double[] dist  = getDistance();
 
+        if (dist == null) {
+            logger.debug("no range found");
+            return null;
+        }
+
         if (logger.isDebugEnabled()) {
             logger.debug("Determine gauge for:");
             logger.debug("... river: " + river.getName());
@@ -848,10 +873,39 @@
      * @return an array of Q values.
      */
     public double[] getQsForWs(double[] ws) {
-        logger.debug("FLYSArtifact.getQsForWs");
+
+        boolean debug = logger.isDebugEnabled();
+
+        if (debug) {
+            logger.debug("FLYSArtifact.getQsForWs");
+        }
 
         River r = getRiver();
-        Gauge g = getGauge();
+        if (r == null) {
+            logger.warn("no river found");
+            return null;
+
+        }
+
+        double [] range = getDistance();
+        if (range == null) {
+            logger.warn("no ranges found");
+            return null;
+        }
+
+        if (debug) {
+            logger.debug("range: " + Arrays.toString(range));
+        }
+
+        Gauge g = r.determineGaugeByPosition(range[0]);
+        if (g == null) {
+            logger.warn("no gauge found for km: " + range[0]);
+            return null;
+        }
+
+        if (debug) {
+            logger.debug("convert w->q with gauge '" + g.getName() + "'");
+        }
 
         DischargeTables dt = new DischargeTables(r.getName(), g.getName());
         Map<String, double [][]>  tmp = dt.getValues();
@@ -861,6 +915,9 @@
 
         for (int i = 0; i < ws.length; i++) {
             qs[i] = dt.getQForW(values, ws[i]);
+            if (debug) {
+                logger.debug("w: " + ws[i] + " -> q: " + qs[i]);
+            }
         }
 
         return qs;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Jun 24 12:05:13 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Sat Jun 25 17:35:50 2011 +0000
@@ -334,6 +334,9 @@
             qSel = false;
             ws   = getWs();
             qs   = getQsForWs(ws);
+            if (qs == null) {
+                return error(new WQKms[0], "conversion ws to qs failed.");
+            }
         }
 
         WstValueTable wst = WstValueTableFactory.getTable(river);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Fri Jun 24 12:05:13 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Sat Jun 25 17:35:50 2011 +0000
@@ -187,7 +187,7 @@
             log.debug("calculating getQForW(" + w + ")");
         }
 
-        int index = Arrays.binarySearch(values[0], w);
+        int index = Arrays.binarySearch(values[1], w);
         if (index >= 0) {
             return values[0][index];
         }
@@ -202,10 +202,10 @@
             return Double.NaN;
         }
 
-        double w1 = values[0][index-1];
-        double w2 = values[0][index  ];
-        double q1 = values[1][index-1];
-        double q2 = values[1][index  ];
+        double w1 = values[1][index-1];
+        double w2 = values[1][index  ];
+        double q1 = values[0][index-1];
+        double q2 = values[0][index  ];
 
         // q1 = m*w1 + b
         // q2 = m*w2 + b

http://dive4elements.wald.intevation.org