[PATCH] Fixed: current station of duration chart was not changed
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 18 18:53:20 CEST 2018
# HG changeset patch
# User gernotbelger
# Date 1531932795 -7200
# Node ID ae9dee74e43ee08d997a5aa862f9b5cbf564a7fe
# Parent c7e5285d434f616ed420f18f54860955e1c9bf1b
Fixed: current station of duration chart was not changed
diff -r c7e5285d434f -r ae9dee74e43e artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveFacet.java
--- 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,39 +51,14 @@
final D4EArtifact flys = (D4EArtifact) artifact;
- final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
+ // TODO: wird das hier noch benötigt?
+ // final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
+ // final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
- 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();
+ final double currentKm = FixChartGenerator.getCurrentKm(context);
return new FloodDurationCalculation(context).calcStationCurve(currentKm, (SINFOArtifact) flys);
}
- /**
- * 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();
- }
-
// private WQDay getTestData() {
// final int[] days = new int[366];
// final double[] ws = new double[366];
diff -r c7e5285d434f -r ae9dee74e43e artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java
--- 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
diff -r c7e5285d434f -r ae9dee74e43e artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixChartGenerator.java
--- 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 :
More information about the Dive4Elements-commits
mailing list