changeset 2733:ac9a03ed32c1

More debugging of discharge-curve issue. flys-artifacts/trunk@4466 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 22 May 2012 19:51:05 +0000
parents 7311d0336600
children 89731cb8c385
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeFacet.java
diffstat 4 files changed, 98 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue May 22 19:42:54 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue May 22 19:51:05 2012 +0000
@@ -1,3 +1,12 @@
+2012-05-22  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java
+	  (getDischargeCurveData): Moved to more specific class.
+
+	* src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeFacet.java:
+	  Cosmetics, be louder in miscondition.
+
 2012-05-22  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Allow loading of fixations and thmatic
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java	Tue May 22 19:42:54 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java	Tue May 22 19:51:05 2012 +0000
@@ -1,12 +1,15 @@
 package de.intevation.flys.artifacts;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
 
+import de.intevation.artifactdatabase.data.DefaultStateData;
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.artifacts.Artifact;
@@ -17,9 +20,20 @@
 import de.intevation.artifacts.common.utils.XMLUtils;
 
 import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WQKms;
 
 import de.intevation.flys.artifacts.states.DefaultState;
 
+import de.intevation.flys.artifacts.model.Calculation;
+import de.intevation.flys.artifacts.model.CalculationResult;
+
+import de.intevation.flys.artifacts.model.DischargeTables;
+
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.River;
+
+import de.intevation.flys.utils.FLYSUtils;
+
 
 
 /**
@@ -33,7 +47,7 @@
     private static Logger logger = Logger.getLogger(GaugeDischargeArtifact.class);
 
     /** The name of the artifact. */
-    public static final String ARTIFACT_NAME = "historicalq";
+    public static final String ARTIFACT_NAME = "gaugedischarge";
 
     // TODO make this one globally available
     public static final String XPATH_DATA =
@@ -66,6 +80,7 @@
         String ids = XMLUtils.xpathString(
             data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE);
         logger.debug("id for gaugedischarge: " + ids);
+
     }
 
 
@@ -91,15 +106,20 @@
         FLYSArtifact artifact = (FLYSArtifact) art;
 
         // Get the location(s)
-        importData(artifact, "ld_mode");
-        importData(artifact, "ld_from");
-        importData(artifact, "ld_to");
-        importData(artifact, "ld_locations");
+        //importData(artifact, "ld_mode");
+        //importData(artifact, "ld_from");
+        //importData(artifact, "ld_to");
+        //importData(artifact, "ld_locations");
+        addStringData("ld_from", "0");
+        addStringData("ld_to", "1000");
+        addStringData("ld_mode", "distance");
+
 
         DefaultState state = (DefaultState) getCurrentState(context);
         state.computeInit(this, hash(), context, meta, fs);
         if (!fs.isEmpty()) { 
-            logger.debug("Facets to add in GaugeDischargeArtifact.initialize ."); 
+            logger.debug("Facets to add in GaugeDischargeArtifact.initialize. ("
+                + state.getID() + ")."); 
             facets.put(getCurrentStateId(), fs); 
         } 
         else { 
@@ -109,7 +129,6 @@
     }
 
 
-
     /**
      * Determines Facets initial disposition regarding activity (think of
      * selection in Client ThemeList GUI). This will be checked one time
@@ -127,5 +146,62 @@
     {
         return 1;
     }
+
+
+    /**
+     * Returns the data that is used to create discharge curves.
+     *
+     */
+    public CalculationResult getDischargeCurveData() {
+
+        River river = FLYSUtils.getRiver(this);
+        if (river == null) {
+            return error(new WQKms[0], "no.river.selected");
+        }
+
+        double [] distance = FLYSUtils.getKmRange(this);
+        logger.debug("getDischargeCurveData: get range");
+
+        if (distance == null) {
+            return error(new WQKms[0], "no.range.found");
+        }
+
+        List<Gauge> gauges = river.determineGauges(distance[0], distance[1]);
+        logger.debug("getDischargeCurveData: get gauges");
+
+        if (gauges.isEmpty()) {
+            return error(new WQKms[0], "no.gauge.selected");
+        }
+
+        String [] names = new String[gauges.size()];
+
+        for (int i = 0; i < names.length; ++i) {
+            names[i] = gauges.get(i).getName();
+            logger.debug("getDischargeCurveData: name " + names[i]);
+        }
+
+        DischargeTables dt = new DischargeTables(river.getName(), names);
+
+        Map<String, double [][]> map = dt.getValues(100d);
+
+        ArrayList<WQKms> res = new ArrayList<WQKms>();
+
+        for (Gauge gauge: gauges) {
+            String name = gauge.getName();
+            double [][] values = map.get(name);
+            if (values == null) {
+                continue;
+            }
+            double [] kms = new double[values[0].length];
+            Arrays.fill(kms, gauge.getStation().doubleValue());
+            res.add(new WQKms(kms, values[0], values[1], name));
+            logger.debug("getDischargeCurveData: add one res gauge");
+        }
+
+        return new CalculationResult(
+            res.toArray(new WQKms[res.size()]),
+            new Calculation());
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Tue May 22 19:42:54 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Tue May 22 19:51:05 2012 +0000
@@ -71,6 +71,7 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+
 /**
  * The default WINFO artifact.
  *
@@ -475,58 +476,6 @@
 
 
     /**
-     * Returns the data that is used to create discharge curves.
-     *
-     */
-    public CalculationResult getDischargeCurveData() {
-
-        River river = FLYSUtils.getRiver(this);
-        if (river == null) {
-            return error(new WQKms[0], "no.river.selected");
-        }
-
-        double [] distance = FLYSUtils.getKmRange(this);
-
-        if (distance == null) {
-            return error(new WQKms[0], "no.range.found");
-        }
-
-        List<Gauge> gauges = river.determineGauges(distance[0], distance[1]);
-
-        if (gauges.isEmpty()) {
-            return error(new WQKms[0], "no.gauge.selected");
-        }
-
-        String [] names = new String[gauges.size()];
-
-        for (int i = 0; i < names.length; ++i) {
-            names[i] = gauges.get(i).getName();
-        }
-
-        DischargeTables dt = new DischargeTables(river.getName(), names);
-
-        Map<String, double [][]> map = dt.getValues(100d);
-
-        ArrayList<WQKms> res = new ArrayList<WQKms>();
-
-        for (Gauge gauge: gauges) {
-            String name = gauge.getName();
-            double [][] values = map.get(name);
-            if (values == null) {
-                continue;
-            }
-            double [] kms = new double[values[0].length];
-            Arrays.fill(kms, gauge.getStation().doubleValue());
-            res.add(new WQKms(kms, values[0], values[1], name));
-        }
-
-        return new CalculationResult(
-            res.toArray(new WQKms[res.size()]),
-            new Calculation());
-    }
-
-
-    /**
      * Returns the data that is computed by a discharge curve computation.
      *
      * @return the data computed by a discharge curve computation.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeFacet.java	Tue May 22 19:42:54 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeFacet.java	Tue May 22 19:51:05 2012 +0000
@@ -12,6 +12,7 @@
 
 
 /**
+ * Access Discharge Curve of a gauge.
  */
 public class GaugeDischargeFacet extends DataFacet {
 
@@ -43,7 +44,6 @@
 
     @Override
     public Facet deepCopy() {
-        // TODO why waterlevel?
         GaugeDischargeFacet copy = new GaugeDischargeFacet();
         copy.set(this);
         copy.type    = type;
@@ -60,10 +60,13 @@
                 index + " / stateId: " + stateId);
         }
 
+        if (stateId == null) {
+            logger.error("GaugeDischargeFacet.getData: stateId is null.");
+        }
         FLYSArtifact flys = (FLYSArtifact) artifact;
 
         CalculationResult res = (CalculationResult)
-            flys.compute(context, hash, stateId, type,  false);
+            flys.compute(context, hash, stateId, type, false);
 
         WQKms[] discharge = (WQKms[]) res.getData();
 

http://dive4elements.wald.intevation.org