diff artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java@bd047b71ab37
children 4897a58c8746
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,269 @@
+package org.dive4elements.river.exports;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.river.artifacts.FLYSArtifact;
+import org.dive4elements.river.artifacts.StaticWKmsArtifact;
+import org.dive4elements.river.artifacts.WINFOArtifact;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.WKms;
+import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.jfree.FLYSAnnotation;
+import org.dive4elements.river.jfree.StickyAxisAnnotation;
+import org.dive4elements.river.jfree.StyledXYSeries;
+
+import org.dive4elements.river.utils.FLYSUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.w3c.dom.Document;
+
+
+/**
+ * An OutGenerator that generates discharge curves.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ComputedDischargeCurveGenerator
+extends      DischargeCurveGenerator
+implements   FacetTypes
+{
+    /** The logger used in this generator. */
+    private static Logger logger =
+        Logger.getLogger(ComputedDischargeCurveGenerator.class);
+
+    public static final String I18N_CHART_TITLE =
+        "chart.computed.discharge.curve.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+        "chart.computed.discharge.curve.subtitle";
+
+    public static final String I18N_YAXIS_LABEL =
+        "chart.computed.discharge.curve.yaxis.label";
+
+    public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
+    public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
+    public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)";
+    public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)";
+
+
+    /** Trivial Constructor. */
+    public ComputedDischargeCurveGenerator () {
+        super();
+    }
+
+
+    @Override
+    protected String getDefaultChartTitle() {
+        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
+    }
+
+
+    @Override
+    protected String getDefaultChartSubtitle() {
+        double[] dist = getRange();
+
+        Object[] args = new Object[] {
+            getRiverName(),
+            dist[0]
+        };
+
+        return msg(I18N_CHART_SUBTITLE, "", args);
+    }
+
+
+    @Override
+    protected String getDefaultYAxisLabel(int pos) {
+        FLYSArtifact flys = (FLYSArtifact) master;
+
+        String unit = FLYSUtils.getRiver(flys).getWstUnit().getName();
+
+        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit });
+    }
+
+
+    /**
+     * Process data, build up plot.
+     */
+    @Override
+    public void doOut(
+        ArtifactAndFacet artifactFacet,
+        Document         attr,
+        boolean          visible
+    ) {
+        String name = artifactFacet.getFacetName();
+
+        logger.debug("ComputedDischargeCurveGenerator.doOut: " + name);
+
+        if (name == null) {
+            logger.warn("Broken facet in computed discharge out generation.");
+            return;
+        }
+
+        //XXX DEAD CODE // Facet facet = artifactFacet.getFacet();
+
+        if (name.equals(COMPUTED_DISCHARGE_Q)) {
+            doQOut((WQKms) artifactFacet.getData(context), artifactFacet, attr, visible);
+        }
+        else if (name.equals(STATIC_WQ)) {
+            doWQOut(artifactFacet.getData(context), artifactFacet, attr, visible);
+        }
+        else if (name.equals(STATIC_WQ_ANNOTATIONS)) {
+            doWQAnnotations(
+                artifactFacet.getData(context),
+                artifactFacet,
+                attr,
+                visible);
+        }
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
+                || name.equals(MAINVALUES_Q)
+                || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
+                || name.equals(MAINVALUES_W)
+        ) {
+            doAnnotations((FLYSAnnotation)
+                artifactFacet.getData(context), artifactFacet, attr, visible);
+        }
+        else if (name.equals(STATIC_WKMS_INTERPOL) || name.equals(HEIGHTMARKS_POINTS)) {
+            doWAnnotations(
+                artifactFacet.getData(context),
+                artifactFacet,
+                attr,
+                visible);
+        }
+        else if (name.equals(STATIC_WKMS)) {
+            doWAnnotations(
+                artifactFacet.getData(context),
+                artifactFacet,
+                attr,
+                visible);
+        }
+        else if (FacetTypes.IS.MANUALPOINTS(name)) {
+            doPoints(artifactFacet.getData(context),
+                artifactFacet,
+                attr, visible, YAXIS.W.idx);
+        }
+        else if (name.equals(DISCHARGE_CURVE)) {
+            doDischargeOut(
+                (WINFOArtifact) artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                attr,
+                visible);
+        }
+        else {
+            logger.warn("Unknown facet type for computed discharge: " + name);
+            return;
+        }
+    }
+
+
+    /**
+     * Add WQ Data to plot.
+     * @param wqkms data as double[][]
+     */
+    protected void doWQOut(
+        Object           wqkms,
+        ArtifactAndFacet aaf,
+        Document         theme,
+        boolean          visible
+    ) {
+        logger.debug("ComputedDischargeCurveGenerator: doWQOut");
+        double [][] data = (double [][]) wqkms;
+
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
+        StyledSeriesBuilder.addPoints(series, data, true);
+
+        addAxisSeries(series, YAXIS.W.idx, visible);
+    }
+
+
+    /**
+     * Add Q-Series to plot.
+     * @param wqkms actual data
+     * @param theme theme to use.
+     */
+    protected void doQOut(
+        WQKms            wqkms,
+        ArtifactAndFacet aaf,
+        Document         theme,
+        boolean          visible
+    ) {
+        logger.debug("ComputedDischargeCurveGenerator: doWQOut");
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
+        StyledSeriesBuilder.addPointsQW(series, wqkms);
+
+        addAxisSeries(series, YAXIS.W.idx, visible);
+    }
+
+
+    /**
+     * Add WQ-Annotations to plot.
+     * @param wqkms actual data
+     * @param theme theme to use.
+     */
+    protected void doWQAnnotations(
+        Object   wqkms,
+        ArtifactAndFacet aandf,
+        Document theme,
+        boolean  visible
+    ) {
+        List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
+        double [][] data = (double [][]) wqkms;
+        for (int i = 0; i< data[0].length; i++) {
+            // TODO we need linear interpolation?
+            xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
+                (float) data[0][i], StickyAxisAnnotation.SimpleAxis.X_AXIS));
+            xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
+                (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS));
+        }
+
+        doAnnotations(new FLYSAnnotation(aandf.getFacetDescription(), xy),
+            aandf, theme, visible);
+    }
+
+
+    /**
+     * Add W-Annotations to plot.
+     * @param wqkms actual data (double[][]).
+     * @param theme theme to use.
+     */
+    protected void doWAnnotations(
+        Object   wqkms,
+        ArtifactAndFacet aandf,
+        Document theme,
+        boolean  visible
+    ) {
+        Facet facet = aandf.getFacet();
+
+        List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
+        // Try to find them as WKms as well...
+        if (wqkms instanceof double[][]) {
+            logger.debug("its double[][] time, baby");
+            double [][] data = (double [][]) wqkms;
+            // TODO Do we need interpolation?
+            for (int i = 0; i< data[0].length; i++) {
+                xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
+                    (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS));
+            }
+
+            doAnnotations(new FLYSAnnotation(facet.getDescription(), xy),
+                aandf, theme, visible);
+        }
+        else {
+            logger.debug("its wkms time, baby");
+            WKms data = (WKms) wqkms;
+            // Assume its WKms.
+            // XXX DEAD CODE // double location = getRange()[0];
+            double w = StaticWKmsArtifact.getWAtKmLin(data, getRange()[0]);
+            xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
+              (float) w, StickyAxisAnnotation.SimpleAxis.Y_AXIS));
+
+            doAnnotations(new FLYSAnnotation(facet.getDescription(), xy),
+                aandf, theme, visible);
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org