changeset 153:c97f9bc9b642

The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user. flys-artifacts/trunk@1590 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 28 Mar 2011 14:33:36 +0000
parents 956445dd601d
children 03362976fa0f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java
diffstat 3 files changed, 96 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Mar 28 10:48:27 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Mar 28 14:33:36 2011 +0000
@@ -1,3 +1,12 @@
+2011-03-28  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
+	  Introduced a 'scale' parameter in the getValues() method.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Filled
+	  the out() operation with code that draws a discharge table of one or
+	  more gauges specified by the given range in entered in a previous state.
+
 2011-03-28  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartExportHelper.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon Mar 28 10:48:27 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon Mar 28 14:33:36 2011 +0000
@@ -1,6 +1,10 @@
 package de.intevation.flys.artifacts;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Vector;
 
 import org.w3c.dom.Document;
@@ -9,6 +13,12 @@
 
 import org.apache.log4j.Logger;
 
+import org.jfree.data.xy.DefaultXYDataset;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.CallContext;
 
@@ -20,8 +30,13 @@
 
 import de.intevation.artifacts.common.utils.XMLUtils;
 
+import de.intevation.flys.model.Gauge;
+
+import de.intevation.flys.artifacts.model.DischargeTables;
+import de.intevation.flys.artifacts.model.GaugesFactory;
 import de.intevation.flys.artifacts.states.DefaultState;
 import de.intevation.flys.artifacts.context.FLYSContext;
+import de.intevation.flys.exports.ChartExportHelper;
 
 
 /**
@@ -123,6 +138,73 @@
     }
 
 
+    @Override
+    public void out(
+        Document     format,
+        OutputStream out,
+        CallContext  context)
+    throws IOException
+    {
+        logger.info("WINFOArtifact.out");
+        String river = (String) getData("river").getValue();
+        String from  = (String) getData("ld_from").getValue();
+        String to    = (String) getData("ld_to").getValue();
+
+        double f = Double.parseDouble(from);
+        double t = Double.parseDouble(to);
+
+        List<double[]> ranges = new ArrayList<double[]>();
+        ranges.add(new double [] { f, t });
+
+        List<Gauge> gauges   = GaugesFactory.getGauges(river);
+        List<Gauge> filtered = GaugesFactory.filterRanges(gauges, ranges);
+
+        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);
+            logger.debug("-> ... from range: " + from);
+            logger.debug("-> ... to range: " + to);
+            logger.debug("-> Found " + numGauges + " gauges in total.");
+            logger.debug("-> Found " + numFiltered + " gauges after filtering.");
+            logger.debug("++++++++++++++++++++");
+        }
+
+        String[] gaugeNames = new String[filtered.size()];
+        int idx = 0;
+        for (Gauge gauge: filtered) {
+            gaugeNames[idx++] = gauge.getName();
+        }
+
+        DischargeTables dt = new DischargeTables(river, gaugeNames);
+        Map<String, double[][]> gaugeValues = dt.getValues(100d);
+
+        DefaultXYDataset dataset = new DefaultXYDataset();
+
+        for (String gauge: gaugeNames) {
+            double[][] values = gaugeValues.get(gauge);
+            dataset.addSeries(gauge, values);
+        }
+
+        JFreeChart chart = ChartFactory.createXYLineChart(
+            "Abflusskurven (" + river + ")",
+            "Q", "W",
+            dataset,
+            PlotOrientation.VERTICAL,
+            true,
+            false,
+            false);
+
+        ChartExportHelper.exportImage(
+            out,
+            chart,
+            "png",
+            600, 400);
+    }
+
+
     /**
      * Returns the name of the concrete artifact.
      *
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Mon Mar 28 10:48:27 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Mon Mar 28 14:33:36 2011 +0000
@@ -42,14 +42,14 @@
         this.gaugeNames = gaugeNames;
     }
 
-    public Map<String, double [][]> getValues() {
+    public Map<String, double [][]> getValues(double scale) {
         if (values == null) {
-            values = loadValues();
+            values = loadValues(scale);
         }
         return values;
     }
 
-    protected Map<String, double [][]> loadValues() {
+    protected Map<String, double [][]> loadValues(double scale) {
         Map<String, double [][]> values = new HashMap<String, double [][]>();
 
         SessionFactory sf = SessionFactoryProvider.getSessionFactory();
@@ -88,8 +88,8 @@
 
                 int idx = 0;
                 for (DischargeTableValue dtv: dtvs) {
-                    vs[0][idx] = dtv.getW().doubleValue();
-                    vs[1][idx] = dtv.getQ().doubleValue();
+                    vs[0][idx] = dtv.getQ().doubleValue() * scale;
+                    vs[1][idx] = dtv.getW().doubleValue() * scale;
                     ++idx;
                 }
 

http://dive4elements.wald.intevation.org