changeset 708:757ff56b43b3

Added calculation "am Pegel" version to the "Wasserspiegellage" calculation. flys-artifacts/trunk@2161 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 18 Jun 2011 20:20:34 +0000
parents b6f57d927905
children 3b7e9ddf6bb1
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/Calculation1.java
diffstat 4 files changed, 48 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Jun 18 18:38:04 2011 +0000
+++ b/flys-artifacts/ChangeLog	Sat Jun 18 20:20:34 2011 +0000
@@ -1,3 +1,18 @@
+2011-06-18  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/Calculation1.java:
+	  Allow an explicit reference km to enable calculation "am Pegel".
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  If a calculation "am Pegel" is done, take start km of the
+	  calculation range and find the gauge in which range it is located.
+	  Take the station of the gauge as the reference km. If no gauge
+	  is found the calcualtion falls back to calculation "auf freier Strecke".
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
+	  Replaced another inefficient attribute extraction via XPath
+	  with direct DOM access.
+
 2011-06-18  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Sat Jun 18 18:38:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Sat Jun 18 20:20:34 2011 +0000
@@ -19,7 +19,6 @@
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import de.intevation.artifacts.ArtifactFactory;
@@ -400,15 +399,15 @@
         int count = nodes.getLength();
         logger.debug("Try to save " + count + " data items.");
 
-        for (int i = 0; i < count; i++) {
-            Node node = nodes.item(i);
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
-            String name = XMLUtils.xpathString(
-                node, "@art:name", ArtifactNamespaceContext.INSTANCE);
-            String value = XMLUtils.xpathString(
-                node, "@art:value", ArtifactNamespaceContext.INSTANCE);
+        for (int i = 0; i < count; i++) {
+            Element node = (Element)nodes.item(i);
 
-            if (name != null && value != null) {
+            String name  = node.getAttributeNS(uri, "name");
+            String value = node.getAttributeNS(uri, "value");
+
+            if (name.length() > 0 && value.length() > 0) {
                 logger.debug("Save data item for '" + name + "' : " + value);
 
                 addData(name, new DefaultStateData(name, null, null, value));
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Sat Jun 18 18:38:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Sat Jun 18 20:20:34 2011 +0000
@@ -328,8 +328,21 @@
             throw new NullPointerException("No Wst found for selected river.");
         }
 
+        double refKm = Double.NaN;
+
+        if (!isFreeQ()) {
+            double pos = kms[river.getKmUp() ? 0 : kms.length-1];
+            Gauge gauge = river.determineGaugeByPosition(pos);
+            if (gauge == null) {
+                logger.warn("no gauge found at km " + pos);
+            }
+            else {
+                refKm = gauge.getStation().doubleValue();
+            }
+        }
+
         WQKms[] results = computeWaterlevelData(
-            kms, qs, ws, wst, river.getKmUp());
+            kms, qs, ws, wst, refKm, river.getKmUp());
 
         return results;
     }
@@ -349,11 +362,12 @@
         double []     qs,
         double []     ws,
         WstValueTable wst,
+        double        refKm,
         boolean       up
     ) {
         logger.info("WINFOArtifact.computeWaterlevelData");
 
-        Calculation1 calculation = new Calculation1(kms, qs, ws, up);
+        Calculation1 calculation = new Calculation1(kms, qs, ws, refKm, up);
 
         WQKms[] wqkms = calculation.calculate(wst);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation1.java	Sat Jun 18 18:38:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation1.java	Sat Jun 18 20:20:34 2011 +0000
@@ -13,6 +13,7 @@
     protected double [] qs;
     protected double [] ws;
     protected boolean   up;
+    protected double    refKm;
 
     public Calculation1() {
     }
@@ -21,19 +22,23 @@
         double [] kms, 
         double [] qs, 
         double [] ws,
+        double    refKm,
         boolean   up
     ) {
-        this.kms = kms;
-        this.qs  = qs;
-        this.ws  = ws;
-        this.up  = up;
+        this.kms   = kms;
+        this.qs    = qs;
+        this.ws    = ws;
+        this.refKm = refKm;
+        this.up    = up;
     }
 
     public WQKms [] calculate(WstValueTable wst) {
 
         ArrayList<WQKms> results = new ArrayList<WQKms>();
 
-        double ref = kms[up ? 0 : kms.length-1];
+        double ref = Double.isNaN(refKm)
+            ? kms[up ? 0 : kms.length-1]
+            : refKm;
 
         String    prefix;
         double [] origData;

http://dive4elements.wald.intevation.org