[PATCH 1 of 2] Use processors for historical discharge curves

Wald Commits scm-commit at wald.intevation.org
Thu Sep 4 15:27:51 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1409837215 -7200
# Node ID 407c9598352f2e860621013f0e1c8d3f34cb71ff
# Parent  baa7df019df3002c24d831b6c08c8962ca623ce6
Use processors for historical discharge curves.

diff -r baa7df019df3 -r 407c9598352f artifacts/doc/conf/generators/discharge-diagram-defaults.xml
--- a/artifacts/doc/conf/generators/discharge-diagram-defaults.xml	Thu Sep 04 11:15:34 2014 +0200
+++ b/artifacts/doc/conf/generators/discharge-diagram-defaults.xml	Thu Sep 04 15:26:55 2014 +0200
@@ -9,4 +9,5 @@
     <processor class="org.dive4elements.river.exports.process.DischargeProcessor" axis="W"/>
     <processor class="org.dive4elements.river.exports.process.MiscDischargeProcessor" axis="W"/>
     <processor class="org.dive4elements.river.exports.process.ComputedDischargeProcessor" axis="W"/>
+    <processor class="org.dive4elements.river.exports.process.HistoricalDischargeProcessor" axis="W"/>
 </discharge-defaults>
diff -r baa7df019df3 -r 407c9598352f artifacts/src/main/java/org/dive4elements/river/exports/process/HistoricalDischargeProcessor.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/HistoricalDischargeProcessor.java	Thu Sep 04 15:26:55 2014 +0200
@@ -0,0 +1,90 @@
+package org.dive4elements.river.exports.process;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+import org.jfree.data.xy.XYSeries;
+
+
+public class HistoricalDischargeProcessor
+extends DefaultProcessor
+implements FacetTypes
+{
+
+    private final static Logger logger =
+            Logger.getLogger(HistoricalDischargeProcessor.class);
+
+    /** Station for which the diagram is shown. */
+    private double km;
+
+    /** Tolerance for comparison of kilometers. */
+    public static final double KM_EPSILON = 0.001d;
+
+
+    /** This processor needs to be constructed with a given km. */
+    public HistoricalDischargeProcessor() {
+        km = Double.NaN;
+    }
+
+
+    public HistoricalDischargeProcessor(double km) {
+        this.km = km;
+    }
+
+
+    /** Process data, add it to plot. */
+    @Override
+    public void doOut(
+            DiagramGenerator generator,
+            ArtifactAndFacet bundle,
+            ThemeDocument theme,
+            boolean visible
+    ) {
+        logger.debug("do out: " + bundle.getFacetName());
+        CallContext context = generator.getCallContext();
+        Object data = bundle.getData(context);
+        if (data instanceof WQKms) {
+            doDischargeOut(generator, bundle, theme, visible);
+        }
+    }
+
+    /** True if this processor knows how to deal with facetType. */
+    @Override
+    public boolean canHandle(String facetType) {
+        return HISTORICAL_DISCHARGE_WQ_CURVE.equals(facetType);
+    }
+
+
+    /** The station of the current calculation/view. */
+    protected double getKm() {
+        return km;
+    }
+
+    /**
+     * Add series with discharge curve to diagram.
+     */
+    protected void doDischargeOut(
+        DiagramGenerator generator,
+        ArtifactAndFacet bundle,
+        ThemeDocument theme,
+        boolean       visible
+    ) {
+        CallContext context = generator.getCallContext();
+        WQKms data = (WQKms)bundle.getData(context);
+        XYSeries series = new StyledXYSeries(bundle.getFacetName(), theme);
+        double[][] wqData = new double[2][data.size()];
+        for (int i = 0; i < data.size(); i++) {
+            wqData[0][i] = data.getQ(i);
+            wqData[1][i] = data.getW(i);
+        }
+        StyledSeriesBuilder.addPoints(series, wqData, false);
+
+        generator.addAxisSeries(series, axisName, visible);
+    }
+}
diff -r baa7df019df3 -r 407c9598352f artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java	Thu Sep 04 11:15:34 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java	Thu Sep 04 15:26:55 2014 +0200
@@ -25,6 +25,7 @@
 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
 import org.dive4elements.river.jfree.RiverAnnotation;
 import org.dive4elements.river.jfree.StickyAxisAnnotation;
+import org.dive4elements.river.jfree.StyledValueMarker;
 import org.dive4elements.river.jfree.StyledXYSeries;
 import org.dive4elements.river.themes.ThemeDocument;
 
@@ -62,7 +63,13 @@
             boolean          visible) {
         CallContext context = generator.getCallContext();
         Object data = bundle.getData(context);
-        if (data instanceof WQKms) {
+        if (HISTORICAL_DISCHARGE_WQ_Q.equals(bundle.getFacetName())) {
+            doHistoricalDischargeOutQ(generator, bundle, theme, visible);
+        }
+        else if (HISTORICAL_DISCHARGE_WQ_W.equals(bundle.getFacetName())) {
+            doHistoricalDischargeOutW(generator, bundle, theme, visible);
+        }
+        else if (data instanceof WQKms) {
             doWQKmsPointOut(
                 generator, (WQKms) data, bundle, theme, visible);
             return;
@@ -241,7 +248,11 @@
             || MAINVALUES_W.equals(facetType)
             || STATIC_W_INTERPOL.equals(facetType)
             || STATIC_WQ.equals(facetType)
-            || STATIC_WQ_ANNOTATIONS.equals(facetType);
+            || STATIC_WQ_ANNOTATIONS.equals(facetType)
+            || HISTORICAL_DISCHARGE_MAINVALUES_Q.equals(facetType)
+            || HISTORICAL_DISCHARGE_MAINVALUES_W.equals(facetType)
+            || HISTORICAL_DISCHARGE_WQ_W.equals(facetType)
+            || HISTORICAL_DISCHARGE_WQ_Q.equals(facetType);
     }
 
 
@@ -250,6 +261,28 @@
         return km;
     }
 
+    protected void doHistoricalDischargeOutQ(
+        DiagramGenerator generator,
+        ArtifactAndFacet bundle,
+        ThemeDocument theme,
+        boolean visible
+    ) {
+        double value = Double.valueOf(
+            bundle.getData(generator.getCallContext()).toString());
+        generator.addDomainMarker(new StyledValueMarker(value, theme), visible);
+    }
+
+    protected void doHistoricalDischargeOutW(
+        DiagramGenerator generator,
+        ArtifactAndFacet bundle,
+        ThemeDocument theme,
+        boolean visible
+    ) {
+        double value = Double.valueOf(
+            bundle.getData(generator.getCallContext()).toString());
+        generator.addValueMarker(new StyledValueMarker(value, theme), visible);
+    }
+
     private void doPointsOut(
         DiagramGenerator generator,
         double[][] data,


More information about the Dive4Elements-commits mailing list