changeset 1151:08048bd090e6

Added very stubby WDifferences State/OutGenerator for WINFOArtifact. flys-artifacts/trunk@2682 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 09 Sep 2011 10:07:14 +0000 (2011-09-09)
parents 5f53b443d67c
children fc572b30f1b8
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java
diffstat 4 files changed, 262 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Sep 09 10:01:09 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Sep 09 10:07:14 2011 +0000
@@ -1,4 +1,19 @@
-2011-09-08  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+2011-09-09  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java:
+	  Added w_differences facet type.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java:
+	  New file, implements naive approach to calculate w-differences (of
+	  calculations identified by hardcoded uuids!) and register respective facet.
+
+	* src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java:
+	  src/main/java/de/intevation/flys/exports/WDifferencesCurveInfoGenerator.java:
+	  New files, implementing naive approach to display w-differences.
+
+2011-09-09  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Implement getArtifact(uuid,context) in FLYSUtils.
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Fri Sep 09 10:01:09 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Fri Sep 09 10:07:14 2011 +0000
@@ -15,6 +15,8 @@
     String LONGITUDINAL_Q = "longitudinal_section.q";
     String LONGITUDINAL_ANNOTATION = "longitudinal_section.annotations";
 
+    String W_DIFFERENCES = "w_differences";
+
     String COMPUTED_DISCHARGE_Q = "computed_discharge_curve.q";
     String COMPUTED_DISCHARGE_MAINVALUES_Q = "computed_discharge_curve.mainvalues.q";
     String COMPUTED_DISCHARGE_MAINVALUES_W = "computed_discharge_curve.mainvalues.w";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java	Fri Sep 09 10:07:14 2011 +0000
@@ -0,0 +1,97 @@
+package de.intevation.flys.artifacts.states;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.WINFOArtifact;
+
+import de.intevation.flys.artifacts.math.WKmsOperation;
+
+import de.intevation.flys.artifacts.model.DurationCurveFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WKms;
+import de.intevation.flys.artifacts.model.WQKms;
+import de.intevation.flys.artifacts.model.WQDay;
+
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.ReportFacet;
+import de.intevation.flys.artifacts.model.CalculationResult;
+
+import de.intevation.flys.artifacts.resources.Resources;
+
+import de.intevation.flys.utils.FLYSUtils;
+
+public class WDifferencesState
+extends      DefaultState
+implements   FacetTypes
+{
+    /** The logger that is used in this state. */
+    private static Logger logger = Logger.getLogger(WDifferencesState.class);
+
+    public WDifferencesState() {
+    }
+
+
+    /** Specify to display a datacage_twin_panel. */
+    @Override
+    protected String getUIProvider() {
+        return "datacage_twin_panel";
+    }
+
+
+    @Override
+    public Object computeAdvance(
+        FLYSArtifact artifact,
+        String       hash,
+        CallContext  context,
+        List<Facet>  facets,
+        Object       old
+    ) {
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
+
+        // Get a data item (uuids) or parameterization of the respective
+        // artifacts.
+        // TODO Fix, choose artifacts/parameterization dynamically.
+        WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact(
+            //"a110a16d-d155-4115-ab0d-c4c61101c9cb", //Collection
+            "a0ec533f-b05b-4dcd-9db3-7850686f90a2",
+            context);
+        WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact(
+            //"8ebb696d-771a-4540-bd18-15e19744a6e2", //Collection
+            "ce5a2c4e-3f9c-4c4d-a35c-109dd8670992",
+            context);
+
+        if (flys1 == null) {
+            logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
+        }
+        if (flys2 == null) {
+            logger.warn("One of the artifacts (2) for diff calculation could not be loaded");
+        }
+        WKms wkms = null;
+
+        if (flys1 != null && flys2 != null) {
+            WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData();
+            WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData();
+            wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]);
+            logger.warn("Did a WKMSSubtraction");
+        }
+
+        if (facets != null) {
+            // TODO: pass computetype and state id.
+            //, ComputeType.ADVANCE, getID(), hash));
+            facets.add(new DataFacet(W_DIFFERENCES, "wdiff data"));
+        }
+        else {
+            logger.debug("Not adding facets in WDifferencesState.");
+        }
+
+        return wkms;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java	Fri Sep 09 10:07:14 2011 +0000
@@ -0,0 +1,147 @@
+package de.intevation.flys.exports;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.title.TextTitle;
+import org.jfree.data.Range;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.ui.TextAnchor;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifacts.Artifact;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WKms;
+import de.intevation.flys.artifacts.model.WQKms;
+
+import de.intevation.flys.model.Annotation;
+import de.intevation.flys.jfree.StickyAxisAnnotation;
+
+
+/**
+ * An OutGenerator that generates w differences curves.
+ */
+public class WDifferencesCurveGenerator
+extends      LongitudinalSectionGenerator
+implements   FacetTypes
+{
+    /** The logger that is used in this generator. */
+    private static Logger logger =
+        Logger.getLogger(WDifferencesCurveGenerator.class);
+
+    public static final String I18N_CHART_TITLE =
+        "chart.w_differences.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+        "chart.w_differences.subtitle";
+
+    public static final String I18N_2YAXIS_LABEL =
+        "chart.w_differences.yaxis.second.label";
+
+    // TODO proper i18n.
+    public static final String I18N_CHART_TITLE_DEFAULT  = "W-Differenzen";
+    public static final String I18N_XAXIS_LABEL_DEFAULT  = "km";
+    public static final String I18N_YAXIS_LABEL_DEFAULT  = "W [NN + m]";
+
+
+    /**
+     * Add a subtitle to Chart.
+     * @param chart Chart to add subtitle to.
+     */
+    @Override
+    protected void addSubtitles(JFreeChart chart) {
+        String subtitle = msg(I18N_CHART_SUBTITLE, "");
+        chart.addSubtitle(new TextTitle(subtitle));
+    }
+
+
+    /**
+     * Add (themed) data for chart generation.
+     */
+    public void doOut(Artifact artifact, Facet facet, Document attr) {
+        String name = facet.getName();
+
+        logger.debug("WDifferencesCurveGenerator.doOut: " + name);
+
+        if (name == null) {
+            logger.error("No facet name for doOut(). No output generated!");
+            return;
+        }
+
+        FLYSArtifact flys = (FLYSArtifact) artifact;
+        Facet        f    = flys.getNativeFacet(facet);
+
+        if (f == null) {
+            return;
+        }
+
+        if (name.equals(W_DIFFERENCES)) {
+            doWDifferencesOut((WKms) f.getData(artifact, context), attr);
+        }
+        else {
+            logger.warn("Unknown facet name: " + name);
+            return;
+        }
+    }
+
+
+    /**
+     * Add items to dataseries which describes the differences.
+     */
+    protected void doWDifferencesOut(WKms wkms, Document theme) {
+        logger.debug("WDifferencesCurveGenerator.doWDifferencesOut");
+        if (wkms == null) {
+            logger.warn("No data to add to WDifferencesChart.");
+            return;
+        }
+
+       int size = wkms.size();
+       // TODO get series name
+       XYSeries series = new StyledXYSeries(getSeriesName(wkms, "delta"), theme);
+
+       if (logger.isDebugEnabled()) {
+           if (wkms.size() > 0) {
+               logger.debug("Generate series: " + series.getKey());
+               logger.debug("Start km: " + wkms.getKm(0));
+               logger.debug("End   km: " + wkms.getKm(size-1));
+               logger.debug("Values  : " + size);
+           }
+       }
+
+       for (int i = 0; i < size; i++) {
+           series.add(wkms.getKm(i), wkms.getW(i));
+       }
+
+       addFirstAxisSeries(series);
+    }
+
+
+    /**
+     * Get name of series (displayed in legend).
+     * @return name of the series.
+     */
+    protected String getSeriesName(WKms wqkms, String mode) {
+        String name   = wqkms.getName();
+        String prefix = (name != null && name.indexOf(mode) >= 0)
+                      ? null
+                      : mode;
+
+        return (prefix != null && prefix.length() > 0)
+                ? prefix + "(" + name +")"
+                : name;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org