[PATCH] Only draw discharge curve if on same station as navigation

Wald Commits scm-commit at wald.intevation.org
Fri Oct 17 13:17:16 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1413544632 -7200
# Node ID 0fa963038c61ac5216ac2670c09b8d07fd4f9a1f
# Parent  8a14605fb64a9ef26a32ea4d4a86899d8fc8bbbb
Only draw discharge curve if on same station as navigation.

diff -r 8a14605fb64a -r 0fa963038c61 artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java	Fri Oct 17 12:50:35 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java	Fri Oct 17 13:17:12 2014 +0200
@@ -162,6 +162,21 @@
         return new double[] {getKm(0), getKm(size()-1)};
     }
 
+    private static final double EPS = 1e-5;
+
+    public Double sameKm() {
+        int s = size();
+        if (s < 1) return null;
+        if (s == 1) return getKm(0);
+        double a = getKm(0);
+        double b = getKm(s-1);
+        double c = getKm(s/2);
+
+        return Math.abs(a-b) > EPS || Math.abs(a-c) > EPS || Math.abs(b-c) > EPS
+            ? null
+            : a;
+    }
+
     @Override
     public boolean guessRTLData() {
         return DataUtil.guessSameDirectionData(ws, allKms());
diff -r 8a14605fb64a -r 0fa963038c61 artifacts/src/main/java/org/dive4elements/river/exports/process/ComputedDischargeProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/ComputedDischargeProcessor.java	Fri Oct 17 12:50:35 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/ComputedDischargeProcessor.java	Fri Oct 17 13:17:12 2014 +0200
@@ -77,16 +77,30 @@
         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);
-        Object data = bundle.getData(context);
 
         series.putMetaData(metaData, bundle.getArtifact(), context);
         yAxisLabel = metaData.get("Y");
 
-        WQKms wqkms = (WQKms) data;
+
+
         double[][] wqData = new double[2][wqkms.size()];
         for (int i = 0; i < wqkms.size(); i++) {
             wqData[0][i] = wqkms.getQ(i);
diff -r 8a14605fb64a -r 0fa963038c61 artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Fri Oct 17 12:50:35 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Fri Oct 17 13:17:12 2014 +0200
@@ -110,9 +110,13 @@
         Map<String, String> metaData = bundle.getFacet().getMetaData(
             bundle.getArtifact(), context);
         WQKms data = (WQKms)bundle.getData(context);
+        Double skm = data.sameKm();
+        if (skm != null && Math.abs(skm-km) > 0.00001) {
+            return;
+        }
         StyledXYSeries series = new StyledXYSeries(name, theme);
         double[][] wqData = new double[2][data.size()];
-        for (int i = 0; i < data.size(); i++) {
+        for (int i = 0, n = data.size(); i < n; i++) {
             wqData[0][i] = data.getQ(i);
             wqData[1][i] = data.getW(i);
         }


More information about the Dive4Elements-commits mailing list