changeset 721:7298d58a1f5a

Generate facets for "Abflusskurven am Pegel". Not working by now. :-/ flys-artifacts/trunk@2198 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 22 Jun 2011 09:19:16 +0000
parents d60cc6453d45
children 4800230fba8a
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java
diffstat 6 files changed, 103 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 22 06:51:36 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 22 09:19:16 2011 +0000
@@ -1,3 +1,20 @@
+2011-06-21  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* doc/conf/artifacts/winfo.xml: Generate facets for "Abflusskurven am Pegel"
+	  Not working by now. :-/
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: New facet type
+	  for "Abflusskurven am Pegel"
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Do calculation
+	  in the artifact not in the output generator.
+
+	* src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java:
+	  Generate the new facets.
+
+	* src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java:
+	  Fetch data from facet.
+
 2011-06-22  Ingo Weinzierl <ingo@intevation.de>
 
 	  flys/issue161 (Diagramm: Q-Achse in W-Längsschnitten immer bei Q=0)
@@ -9,7 +26,7 @@
 
 2011-06-21  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
-    Draw correction curve again.
+	Draw correction curve again.
 
 	* src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java:
 	  Use correction curve to map plot to axes. Not doing so prevented
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Wed Jun 22 06:51:36 2011 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Wed Jun 22 09:19:16 2011 +0000
@@ -63,8 +63,6 @@
                 <outputmode name="discharge_curve" description="output.discharge_curve" mime-type="image/png">
                     <facets>
                         <facet name="discharge_curve.curve" description="facet.discharge_curve.curve"/>
-                        <facet name="discharge_curve.w" description="facet.discharge_curve.w"/>
-                        <facet name="discharge_curve.q" description="facet.discharge_curve.q"/>
                     </facets>
                 </outputmode>
             </outputmodes>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 22 06:51:36 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 22 09:19:16 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts;
 
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -447,31 +448,52 @@
     /**
      * Returns the data that is used to create discharge curves.
      *
-     * @return a map where the key is the name of the gauge and a double[][]
-     * which are the values.
      */
-    public Map<String, double[][]> getDischargeCurveData() {
-        River       river  = getRiver();
-        List<Gauge> gauges = getGauges();
+    public CalculationResult getDischargeCurveData() {
 
-        if (gauges == null) {
-            logger.warn("No gauges found for the current kilometer range.");
-            return null;
+        River river = getRiver();
+        if (river == null) {
+            return error(new WQKms[0], "no river found");
         }
 
-        int num = gauges.size();
-
-        logger.debug("Found " + num + " gauges.");
+        double [] distance = getDistance();
 
-        String[] gaugeNames = new String[num];
-
-        for (int i = 0; i < num; i++) {
-            gaugeNames[i] = gauges.get(i).getName();
+        if (distance == null) {
+            return error(new WQKms[0], "no range found");
         }
 
-        DischargeTables dt = new DischargeTables(river.getName(), gaugeNames);
+        List<Gauge> gauges = river.determineGauges(distance[0], distance[1]);
 
-        return dt.getValues(100d);
+        if (gauges.isEmpty()) {
+            return error(new WQKms[0], "no gauges found");
+        }
+
+        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(values[1], values[0], kms, name));
+        }
+
+        return new CalculationResult(
+            res.toArray(new WQKms[res.size()]),
+            new Calculation());
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 22 06:51:36 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 22 09:19:16 2011 +0000
@@ -11,6 +11,8 @@
 
     String COMPUTED_DISCHARGE_Q = "computed_discharge_curve.q";
 
+    String DISCHARGE_CURVE = "computed_discharge_curve.curve";
+
     String DURATION_W = "duration_curve.w";
     String DURATION_Q = "duration_curve.q";
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Wed Jun 22 06:51:36 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Wed Jun 22 09:19:16 2011 +0000
@@ -1,7 +1,6 @@
 package de.intevation.flys.artifacts.states;
 
 import java.util.List;
-import java.util.Map;
 
 import org.apache.log4j.Logger;
 
@@ -24,13 +23,20 @@
 import de.intevation.flys.artifacts.WINFOArtifact;
 
 import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.artifacts.model.WQKms;
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.WaterlevelFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
 
 import de.intevation.flys.artifacts.resources.Resources;
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class LocationDistanceSelect extends RangeState {
+public class LocationDistanceSelect 
+extends      RangeState
+implements   FacetTypes
+{
 
     /** The logger used in this class.*/
     private static Logger logger = Logger.getLogger(LocationDistanceSelect.class);
@@ -309,17 +315,19 @@
     ) {
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        Map<String, double [][]> res;
+        CalculationResult res = old instanceof CalculationResult
+            ? (CalculationResult)old
+            : winfo.getDischargeCurveData();
 
-        if (old instanceof Map<?, ?>) {
-            res = (Map<String, double [][]>)old;
-        }
-        else {
-            res = winfo.getDischargeCurveData();
+        if (facets == null) {
+            return res;
         }
 
-        if (facets != null) {
-            // TODO: Generate facets!
+        WQKms [] wqkms = (WQKms [])res.getData();
+
+        for (int i = 0; i < wqkms.length; ++i) {
+            String name = wqkms[i].getName();
+            facets.add(new WaterlevelFacet(i, DISCHARGE_CURVE, name));
         }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Wed Jun 22 06:51:36 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Wed Jun 22 09:19:16 2011 +0000
@@ -23,9 +23,8 @@
 import de.intevation.flys.model.TimeInterval;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
-import de.intevation.flys.artifacts.model.DischargeTables;
-import de.intevation.flys.artifacts.model.GaugesFactory;
 
+import de.intevation.flys.artifacts.model.WQKms;
 
 /**
  * An OutGenerator that generates discharge curves.
@@ -98,49 +97,43 @@
         logger.debug("DischargeCurveGenerator.doOut: " + facet.getName());
 
         if (!(artifact instanceof FLYSArtifact)) {
-            logger.error("Artifact is no instance of FLYSArtifact.");
+            logger.debug("Artifact is no instance of FLYSArtifact.");
             return;
         }
 
         FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
 
-        River    river    = flysArtifact.getRiver();
-        double[] distance = flysArtifact.getDistance();
-
-        List<double[]> ranges = new ArrayList<double[]>();
-        ranges.add(distance);
-
-        List<Gauge> gauges   = GaugesFactory.getGauges(river);
-        List<Gauge> filtered = GaugesFactory.filterRanges(gauges, ranges);
+        facet = flysArtifact.getNativeFacet(facet);
 
-        if (logger.isDebugEnabled()) {
-            int numGauges   = gauges != null ? gauges.size() : 0;
-            int numFiltered = filtered != null ? filtered.size() : 0;
-
-            logger.debug("++++++++++++++++++++");
-            logger.debug("Search gauges for river: " + river.getName());
-            logger.debug("-> ... from range: " + distance[0]);
-            logger.debug("-> ... to range: " + distance[1]);
-            logger.debug("-> Found " + numGauges + " gauges in total.");
-            logger.debug("-> Found " + numFiltered + " gauges after filtering.");
-            logger.debug("++++++++++++++++++++");
+        if (facet == null) {
+            logger.debug("no facet found");
+            return;
         }
 
-        String[] gaugeNames = new String[filtered.size()];
-        int idx = 0;
-        for (Gauge gauge: filtered) {
-            gaugeNames[idx++] = gauge.getName();
+        WQKms wqkms = (WQKms)facet.getData(flysArtifact, context);
+
+        String gaugeName = wqkms.getName();
+
+        River river = flysArtifact.getRiver();
+
+        if (river == null) {
+            logger.debug("no river found");
+            return;
         }
 
-        DischargeTables dt = new DischargeTables(river.getName(), gaugeNames);
-        Map<String, double[][]> gaugeValues = dt.getValues(100d);
+        Gauge gauge = river.determineGaugeByName(gaugeName);
 
-        for (Gauge gauge: filtered) {
-            String gaugeName = gauge.getName();
+        if (gauge == null) {
+            logger.debug("no gauge found");
+            return;
+        }
 
-            double[][] values = gaugeValues.get(gaugeName);
-            dataset.addSeries(getSeriesName(gauge), values);
-        }
+        String seriesName = getSeriesName(gauge);
+
+        double [][] values = new double [][] {
+            wqkms.getQs(), wqkms.getWs() };
+
+        dataset.addSeries(seriesName, values);
     }
 
 

http://dive4elements.wald.intevation.org