changeset 9268:ae9dee74e43e

Fixed: current station of duration chart was not changed
author gernotbelger
date Wed, 18 Jul 2018 18:53:15 +0200
parents c7e5285d434f
children 83ebeb620b5a
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveFacet.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixChartGenerator.java
diffstat 3 files changed, 58 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveFacet.java	Wed Jul 18 15:34:53 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveFacet.java	Wed Jul 18 18:53:15 2018 +0200
@@ -8,17 +8,14 @@
 
 package org.dive4elements.river.artifacts.sinfo.flood_duration;
 
-import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM;
-
 import org.apache.log4j.Logger;
 import org.dive4elements.artifactdatabase.state.DefaultFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.D4EArtifact;
-import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
-import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
+import org.dive4elements.river.exports.fixings.FixChartGenerator;
 
 
 /**
@@ -26,6 +23,8 @@
  */
 public class FloodDurationCurveFacet extends DefaultFacet {
 
+    private static final long serialVersionUID = 1L;
+
     private static Logger log = Logger.getLogger(FloodDurationCurveFacet.class);
 
     // /** Blackboard data provider key for durationcurve (wqday) data. */
@@ -52,37 +51,12 @@
 
         final D4EArtifact flys = (D4EArtifact) artifact;
 
-        final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
-
-        final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
-
-        final double currentKm = getCurrentKm(context);
-        // TODO: entweder in data.getDurationCurve() reingeben, oder bei FloodDurationCalculationResults auswerten...
-        // TODO: was ist aus perfromanz/speicher-sicht besser?
-
-        // return data.getDurationCurve();
-        return new FloodDurationCalculation(context).calcStationCurve(currentKm, (SINFOArtifact) flys);
-    }
+        // TODO: wird das hier noch benötigt?
+        //        final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
+        //        final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
 
-    /**
-     * Returns the current km from the context.
-     * If the context is null or doesn't contain a currentKm
-     * then a double value of -1 will be returned.
-     *
-     * @param context
-     *            The CallContext instance
-     * @return the current km as double
-     */
-    // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet
-    private double getCurrentKm(final CallContext context) {
-        if (context == null)
-            return Double.NaN;
-
-        final Double dkm = (Double) context.getContextValue(CURRENT_KM);
-        if (dkm == null)
-            return Double.NaN;
-
-        return dkm.doubleValue();
+        final double currentKm = FixChartGenerator.getCurrentKm(context);
+        return new FloodDurationCalculation(context).calcStationCurve(currentKm, (SINFOArtifact) flys);
     }
 
     // private WQDay getTestData() {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java	Wed Jul 18 15:34:53 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java	Wed Jul 18 18:53:15 2018 +0200
@@ -10,6 +10,7 @@
 
 import java.awt.Font;
 import java.awt.geom.Point2D;
+import java.io.OutputStream;
 
 import org.apache.log4j.Logger;
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
@@ -18,6 +19,7 @@
 import org.dive4elements.river.artifacts.model.WQDay;
 import org.dive4elements.river.exports.IdentifiableNumberAxis;
 import org.dive4elements.river.exports.XYChartGenerator;
+import org.dive4elements.river.exports.fixings.FixChartGenerator;
 import org.dive4elements.river.jfree.Bounds;
 import org.dive4elements.river.jfree.RiverAnnotation;
 import org.dive4elements.river.jfree.StyledXYSeries;
@@ -27,6 +29,7 @@
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.Range;
 import org.jfree.data.xy.XYSeries;
+import org.w3c.dom.Document;
 
 /**
  * An OutGenerator that generates duration curves.
@@ -64,6 +67,13 @@
         super();
     }
 
+    @Override
+    public void init(final String outName, final Document request, final OutputStream out, final CallContext context) {
+        super.init(outName, request, out, context);
+
+        FixChartGenerator.initCurrentKm(request, context);
+    }
+
     /**
      * Create Axis for given index.
      *
@@ -88,10 +98,11 @@
     }
 
     @Override
-    protected String getDefaultChartSubtitle(final CallContext context) {
-
-        final double[] dist = getRange();
-        return msg(I18N_CHART_SUBTITLE, "", getRiverName(), dist[0]);
+    protected String getChartSubtitle(final CallContext context) {
+        // REMARK: can't use getDeaultChartSubtitle, because the standard implementation of getChartSubtitle will
+        // always use the subtitle from the settings, which will automatically be set during init.
+        final double currentKm = FixChartGenerator.getCurrentKm(context);
+        return msg(I18N_CHART_SUBTITLE, "", getRiverName(), currentKm);
     }
 
     @Override
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixChartGenerator.java	Wed Jul 18 15:34:53 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixChartGenerator.java	Wed Jul 18 18:53:15 2018 +0200
@@ -41,15 +41,7 @@
     ) {
         super.init(outName, request, out, context);
 
-        Double currentKm = getCurrentKmFromRequest(request);
-
-        if (log.isDebugEnabled()) {
-            log.debug("currentKm = " + currentKm);
-        }
-
-        if (currentKm != INVALID_KM) {
-            context.putContextValue(CURRENT_KM, currentKm);
-        }
+        initCurrentKm(request, context);
     }
 
     public static final Double getCurrentKmFromRequest(Document request) {
@@ -70,5 +62,39 @@
             return INVALID_KM;
         }
     }
+    
+    /**
+     * Returns the current km from the context.
+     * If the context is null or doesn't contain a currentKm
+     * then a double value of -1 will be returned.
+     *
+     * @param context
+     *            The CallContext instance
+     * @return the current km as double
+     */
+    // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet
+    public static final double getCurrentKm(final CallContext context) {
+        if (context == null)
+            return Double.NaN;
+
+        final Double dkm = (Double) context.getContextValue(CURRENT_KM);
+        if (dkm == null)
+            return Double.NaN;
+
+        return dkm.doubleValue();
+    }
+
+    public static void initCurrentKm(Document request, CallContext context) {
+        
+        Double currentKm = getCurrentKmFromRequest(request);
+
+        if (log.isDebugEnabled()) {
+            log.debug("currentKm = " + currentKm);
+        }
+
+        if (currentKm != INVALID_KM) {
+            context.putContextValue(CURRENT_KM, currentKm);
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org