changeset 8436:17c3aaa17112

More cleanup in discharge data processing.
author "Tom Gottfried <tom@intevation.de>"
date Mon, 20 Oct 2014 13:52:15 +0200
parents 6ebad936d82b
children 4fd063703487
files artifacts/doc/conf/generators/discharge-diagram-defaults.xml artifacts/doc/conf/generators/sqrelation-diagram-defaults.xml artifacts/src/main/java/org/dive4elements/river/artifacts/states/ComputedDischargeCurveState.java artifacts/src/main/java/org/dive4elements/river/exports/process/ComputedDischargeProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java
diffstat 5 files changed, 6 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/generators/discharge-diagram-defaults.xml	Mon Oct 20 13:48:51 2014 +0200
+++ b/artifacts/doc/conf/generators/discharge-diagram-defaults.xml	Mon Oct 20 13:52:15 2014 +0200
@@ -6,7 +6,6 @@
                  include-zero="true"/>
     <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"/>
     <processor class="org.dive4elements.river.exports.process.FixWQProcessor" axis="W"/>
     <processor class="org.dive4elements.river.exports.process.FixDerivedProcessor" axis="W"/>
--- a/artifacts/doc/conf/generators/sqrelation-diagram-defaults.xml	Mon Oct 20 13:48:51 2014 +0200
+++ b/artifacts/doc/conf/generators/sqrelation-diagram-defaults.xml	Mon Oct 20 13:52:15 2014 +0200
@@ -6,7 +6,6 @@
     <processor class="org.dive4elements.river.exports.process.SQRelationProcessor" axis="Transport"/>
     <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"/>
     <processor class="org.dive4elements.river.exports.process.FixWQProcessor" axis="W"/>
     <processor class="org.dive4elements.river.exports.process.FixDerivedProcessor" axis="W"/>
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/ComputedDischargeCurveState.java	Mon Oct 20 13:48:51 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/ComputedDischargeCurveState.java	Mon Oct 20 13:52:15 2014 +0200
@@ -85,7 +85,6 @@
                     String name = Resources.getMsg(
                         context.getMeta(),
                         "chart.computed.discharge.curve.curve.label",
-                        "",
                         args);
 
                     facets.add(new WaterlevelFacet(i, COMPUTED_DISCHARGE_Q, name));
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/ComputedDischargeProcessor.java	Mon Oct 20 13:48:51 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-package org.dive4elements.river.exports.process;
-
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
-import org.dive4elements.artifacts.CallContext;
-import org.dive4elements.artifacts.CallMeta;
-import org.dive4elements.river.artifacts.D4EArtifact;
-import org.dive4elements.river.artifacts.access.RiverAccess;
-import org.dive4elements.river.artifacts.model.FacetTypes;
-import org.dive4elements.river.artifacts.model.WQKms;
-import org.dive4elements.river.artifacts.resources.Resources;
-import org.dive4elements.river.exports.DiagramGenerator;
-import org.dive4elements.river.exports.StyledSeriesBuilder;
-import org.dive4elements.river.jfree.StyledXYSeries;
-import org.dive4elements.river.themes.ThemeDocument;
-
-
-public class ComputedDischargeProcessor
-extends DefaultProcessor
-implements FacetTypes
-{
-    private static Logger log =
-        Logger.getLogger(ComputedDischargeProcessor.class);
-
-    private String yAxisLabel = "";
-
-    private String I18N_AXIS_LABEL = "chart.discharge.curve.yaxis.label";
-
-    @Override
-    public void doOut(
-            DiagramGenerator generator,
-            ArtifactAndFacet bundle,
-            ThemeDocument    theme,
-            boolean          visible
-    ) {
-        CallContext context = generator.getCallContext();
-        Object data = bundle.getData(context);
-        if (data instanceof WQKms) {
-            doDischargeOut(generator, bundle, theme, visible);
-        }
-    }
-
-    @Override
-    public String getAxisLabel(DiagramGenerator generator) {
-        CallMeta meta = generator.getCallContext().getMeta();
-        RiverAccess access = new RiverAccess((D4EArtifact)generator.getMaster());
-        String unit = access.getRiver().getWstUnit().getName();
-        if (yAxisLabel != null && !yAxisLabel.isEmpty()) {
-            return Resources.getMsg(
-                meta,
-                yAxisLabel,
-                new Object[] { unit });
-        }
-        return Resources.getMsg(
-                meta,
-                I18N_AXIS_LABEL,
-                new Object[] { unit });
-    }
-
-    /**
-     * Returns true if the Processor class is able to generate output for a facet type
-     *
-     * @param facettype Name of the facet type
-     * @return true if the facettype can be processed
-     */
-    @Override
-    public boolean canHandle(String facettype) {
-        return COMPUTED_DISCHARGE_Q.equals(facettype);
-    }
-
-    private void doDischargeOut(
-        DiagramGenerator generator,
-        ArtifactAndFacet bundle,
-        ThemeDocument theme,
-        boolean visible
-    ) {
-        CallContext context = generator.getCallContext();
-
-        Object data = bundle.getData(context);
-        WQKms wqkms = (WQKms) data;
-
-        Object currentKm = context.getContextValue("currentkm");
-        if (currentKm instanceof Number) {
-            double ckm = ((Number)currentKm).doubleValue();
-            Double skm = wqkms.sameKm();
-            if (skm != null && Math.abs(skm-ckm) > 0.00001) {
-                return;
-            }
-        }
-
-        Map<String, String> metaData = bundle.getFacet().getMetaData(
-            bundle.getArtifact(), context);
-
-        StyledXYSeries series =
-            new StyledXYSeries(bundle.getFacetDescription(), theme);
-
-        series.putMetaData(metaData, bundle.getArtifact(), context);
-        yAxisLabel = metaData.get("Y");
-
-
-
-        double[][] wqData = new double[2][wqkms.size()];
-        for (int i = 0; i < wqkms.size(); i++) {
-            wqData[0][i] = wqkms.getQ(i);
-            wqData[1][i] = wqkms.getW(i);
-        }
-        StyledSeriesBuilder.addPoints(series, wqData, false);
-        generator.addAxisSeries(series, axisName, visible);
-    }
-}
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Mon Oct 20 13:48:51 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Mon Oct 20 13:52:15 2014 +0200
@@ -23,8 +23,6 @@
 import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.exports.StyledSeriesBuilder;
 import org.dive4elements.river.jfree.StyledXYSeries;
-import org.dive4elements.river.model.Gauge;
-import org.dive4elements.river.model.River;
 import org.dive4elements.river.themes.ThemeDocument;
 
 
@@ -38,9 +36,6 @@
     /** Station for which the diagram is shown. */
     private double km;
 
-    /** Tolerance for comparison of kilometers. */
-    public static final double KM_EPSILON = 0.001d;
-
     private String yAxisLabel = "";
 
     private String I18N_AXIS_LABEL = "chart.discharge.curve.yaxis.label";
@@ -71,7 +66,6 @@
             doDischargeOut(
                 generator,
                 bundle,
-                bundle.getFacetDescription().trim(),
                 theme,
                 visible);
         }
@@ -86,7 +80,8 @@
     @Override
     public boolean canHandle(String facetType) {
         return DISCHARGE_CURVE.equals(facetType)
-            || GAUGE_DISCHARGE_CURVE.equals(facetType);
+            || GAUGE_DISCHARGE_CURVE.equals(facetType)
+            || COMPUTED_DISCHARGE_Q.equals(facetType);
     }
 
 
@@ -101,11 +96,9 @@
     protected void doDischargeOut(
         DiagramGenerator generator,
         ArtifactAndFacet bundle,
-        String        name,
         ThemeDocument theme,
-        boolean       visible)
-    {
-        log.debug("DischargeCurveGenerator.doDischargeOut");
+        boolean       visible
+    ) {
         CallContext context = generator.getCallContext();
         Map<String, String> metaData = bundle.getFacet().getMetaData(
             bundle.getArtifact(), context);
@@ -114,7 +107,8 @@
         if (skm != null && Math.abs(skm-km) > 0.00001) {
             return;
         }
-        StyledXYSeries series = new StyledXYSeries(name, theme);
+        StyledXYSeries series = new StyledXYSeries(
+            bundle.getFacetDescription().trim(), theme);
         double[][] wqData = new double[2][data.size()];
         for (int i = 0, n = data.size(); i < n; i++) {
             wqData[0][i] = data.getQ(i);
@@ -124,22 +118,6 @@
 
         series.putMetaData(metaData, bundle.getArtifact(), context);
         yAxisLabel = metaData.get("Y");
-
-        String gaugeName = data.getName();
-        RiverAccess access = new RiverAccess((D4EArtifact)bundle.getArtifact());
-        River river = access.getRiver();
-
-        if (river == null) {
-            log.debug("no river found");
-            return;
-        }
-
-        Gauge gauge = river.determineGaugeByName(gaugeName);
-
-        if (gauge == null) {
-            log.debug("no gauge found");
-            return;
-        }
         generator.addAxisSeries(series, axisName, visible);
     }
 

http://dive4elements.wald.intevation.org