[Dive4elements-commits] [PATCH 4 of 4] issue1235: Values are valid until next measurements station range start

Wald Commits scm-commit at wald.intevation.org
Fri Jun 14 17:02:52 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1371222693 -7200
# Node ID 588e99129883357d3d5f5eb63c0003cbf0689dff
# Parent  b8cd8e2d0c3553411512c10783ebe43e4bfb1161
issue1235: Values are valid until next measurements station range start.

diff -r b8cd8e2d0c35 -r 588e99129883 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java	Fri Jun 14 17:09:25 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java	Fri Jun 14 17:11:33 2013 +0200
@@ -120,16 +120,24 @@
         int i = 0;
         for (Map.Entry<Double, Double> kmLoad: sortedKmLoad.entrySet()) {
             boolean matchFound = false;
-            // For now, ignore overlaps like (B> next A)
-            for (MeasurementStation station: stations) {
-                if (Math.abs(station.getStation() - kmLoad.getKey()) < EPSILON ||
-                    station.getRange().containsTolerant(kmLoad.getKey())) {
-                    // TODO: In rare cases, two matches can be found.
-                    values[0][i*3] = station.getRange().getA().doubleValue() + EPSILON;
-                    values[1][i*3] = kmLoad.getValue();
-                    values[0][i*3+1] = station.getRange().getB().doubleValue() - EPSILON;
+            for (int k = 0; k < stations.size(); k++) {
+                MeasurementStation station = stations.get(k);
+                if (Math.abs(station.getStation() - kmLoad.getKey()) < EPSILON) {
+                    // Value has been taken at measurement station.
+                    values[0][i*3]   = station.getRange().getA().doubleValue() + EPSILON;
+                    values[1][i*3]   = kmLoad.getValue();
+                    double endValue = 0d;
+                    // Valid until next measurements stations begin of range,
+                    // or end of current range if last value.
+                    if (k+2 <= stations.size()) {
+                        endValue = stations.get(k+1).getRange().getA().doubleValue();
+                    }
+                    else {
+                        endValue = station.getRange().getB().doubleValue();
+                    }
+                    values[0][i*3+1] = endValue;
                     values[1][i*3+1] = kmLoad.getValue();
-                    values[0][i*3+2] = station.getRange().getB().doubleValue();
+                    values[0][i*3+2] = endValue;
                     values[1][i*3+2] = kmLoad.getValue();
                     matchFound = true;
                 }


More information about the Dive4elements-commits mailing list