diff flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java @ 385:478940d06876

Enabled the WINFO artifact to create duration curves - new OutGenerator, added methods for data computation. flys-artifacts/trunk@1802 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 03 May 2011 12:05:32 +0000
parents
children fc3ac59c3c8b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java	Tue May 03 12:05:32 2011 +0000
@@ -0,0 +1,166 @@
+package de.intevation.flys.exports;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+
+import de.intevation.artifacts.Artifact;
+
+import de.intevation.flys.artifacts.WINFOArtifact;
+import de.intevation.flys.artifacts.model.WQDay;
+
+
+/**
+ * An OutGenerator that generates duration curves.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DurationCurveGenerator extends XYChartGenerator {
+
+    private static Logger logger =
+        Logger.getLogger(DurationCurveGenerator.class);
+
+    /** The storage for the W series to be drawn in this chart.*/
+    protected XYSeriesCollection w;
+
+    /** The storage for the Q series to be drawn in this chart.*/
+    protected XYSeriesCollection q;
+
+
+    public static final String DURATION_CURVE_W =
+        "duration_curve.w";
+
+    public static final String DURATION_CURVE_Q =
+        "duration_curve.q";
+
+
+    public DurationCurveGenerator() {
+        super();
+
+        this.w = new XYSeriesCollection();
+        this.q = new XYSeriesCollection();
+    }
+
+
+    protected String getChartTitle() {
+        // TODO i18n
+        return "Wasserstand für Gewässer";
+    }
+
+
+    protected String getXAxisLabel() {
+        // TODO i18n
+        return "Unterschreitungsdauer [Tagen]";
+    }
+
+
+    protected String getYAxisLabel() {
+        return "W [NN + m]";
+    }
+
+
+    public void addDatasets(JFreeChart chart) {
+        XYPlot plot = (XYPlot) chart.getPlot();
+
+        plot.setDataset(0, w);
+        plot.setDataset(1, q);
+    }
+
+
+    protected void adjustAxes(XYPlot plot) {
+        super.adjustAxes(plot);
+
+        NumberAxis qAxis = new NumberAxis("Q [m³/s]");
+
+        plot.setRangeAxis(2, qAxis);
+        plot.mapDatasetToRangeAxis(1, 2);
+    }
+
+
+    public void doOut(Artifact artifact, String facet, Document attr) {
+        logger.debug("DurationCurveGenerator.doOut: " + facet);
+
+        if (facet == null || facet.length() == 0) {
+            logger.error("No facet given. Cannot create dataset.");
+            return;
+        }
+
+        if (facet.equals(DURATION_CURVE_W)) {
+            doWOut(getDurationCurveData(artifact));
+        }
+        else if (facet.equals(DURATION_CURVE_Q)) {
+            doQOut(getDurationCurveData(artifact));
+        }
+        else {
+            logger.warn("Unknown facet name: " + facet);
+            return;
+        }
+    }
+
+
+    /**
+     * Creates the series for a duration curve's W facet.
+     *
+     * @param wqdays The WQDay store that contains the Ws.
+     */
+    protected void doWOut(WQDay wqdays) {
+        logger.debug("DurationCurveGenerator.doWOut");
+
+        // TODO find the correct series name
+        XYSeries series = new XYSeries("W-1");
+
+        int size = wqdays.size();
+        for (int i = 0; i < size; i++) {
+            int  day = wqdays.getDay(i);
+            double w = wqdays.getW(i);
+
+            series.add((double) day, w);
+        }
+
+        this.w.addSeries(series);
+    }
+
+
+    /**
+     * Creates the series for a duration curve's Q facet.
+     *
+     * @param wqdays The WQDay store that contains the Qs.
+     */
+    protected void doQOut(WQDay wqdays) {
+        logger.debug("DurationCurveGenerator.doQOut");
+
+        // TODO find the correct series name
+        XYSeries series = new XYSeries("Q-1");
+
+        int size = wqdays.size();
+        for (int i = 0; i < size; i++) {
+            int  day = wqdays.getDay(i);
+            double q = wqdays.getQ(i);
+
+            series.add((double) day, q);
+        }
+
+        this.q.addSeries(series);
+    }
+
+
+    /**
+     * Returns the computed data for a duration curve based on the artifact's
+     * computation method.
+     *
+     * @param artifact The WINFO artifact.
+     *
+     * @return the computed data for a duration curve's W and Q facet.
+     */
+    protected WQDay getDurationCurveData(Artifact artifact) {
+        WINFOArtifact winfoArtifact = (WINFOArtifact) artifact;
+        return winfoArtifact.getDurationCurveData();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org