changeset 8784:6714e07e18c2

Issue1854: Use the real data. There is no guarantee that the overviews contain the same data.
author Tom Gottfried <tom@intevation.de>
date Tue, 08 Dec 2015 18:10:18 +0100
parents b251a6ad46bb
children d55cbb45c565
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java
diffstat 1 files changed, 32 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java	Tue Dec 08 16:43:46 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java	Tue Dec 08 18:10:18 2015 +0100
@@ -10,6 +10,7 @@
 
 import java.util.Date;
 import java.util.List;
+import java.util.Collections;
 
 import org.w3c.dom.Element;
 
@@ -18,10 +19,8 @@
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.states.DistanceSelect;
-import org.dive4elements.river.utils.KMIndex;
 
-import org.dive4elements.river.artifacts.model.minfo.BedOverview;
-import org.dive4elements.river.artifacts.model.minfo.BedOverviewFactory;
+import org.dive4elements.river.artifacts.model.minfo.QualityMeasurementFactory;
 
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.Artifact;
@@ -53,36 +52,46 @@
             return ele;
         }
 
-        D4EArtifact arti = (D4EArtifact) artifact;
-        RiverAccess access = new RiverAccess(arti);
+        RiverAccess access = new RiverAccess((D4EArtifact)artifact);
+        String river = access.getRiverName();
+        double [] minMax = access.getRiver().determineMinMaxDistance();
 
-        /* Bit of an overkill here but it will be cached and accessed
-         * in the next state anyway. */
-        BedOverview overview = BedOverviewFactory
-            .getOverview(access.getRiverName());
+        List<Double> bKms = QualityMeasurementFactory.getBedMeasurements(
+            river,
+            minMax[0],
+            minMax[1],
+            new Date(Long.MIN_VALUE/100000),
+            new Date(Long.MAX_VALUE/1000)
+             // values expected to fit in SQL Date, though large enough
+        ).getKms();
 
-        if (overview == null) {
-            log.warn("No overview found for river '"
-                + access.getRiverName() + "'");
+        List<Double> blKms = QualityMeasurementFactory.getBedloadMeasurements(
+            river,
+            minMax[0],
+            minMax[1],
+            new Date(Long.MIN_VALUE/100000),
+            new Date(Long.MAX_VALUE/1000)
+             // values expected to fit in SQL Date, though large enough
+        ).getKms();
+
+        if (bKms.isEmpty() || blKms.isEmpty()) {
+            log.warn("Not all data found for river '" + river + "'");
             return ele;
         }
 
-        KMIndex<List<Date>> entries = overview.filter(BedOverview.ACCEPT);
-        if (entries.size() == 0) {
-            log.warn("No data found for river '"
-                + access.getRiverName() + "'");
-            return ele;
-        }
-        entries.sort();
+        Collections.sort(blKms);
+        Collections.sort(bKms);
+
+        double start = Math.min(bKms.get(0), blKms.get(0));
+        double end = Math.max(
+            bKms.get(bKms.size()-1), blKms.get(blKms.size()-1));
 
         if (data.getName().equals("ld_from")) {
             cr.addAttr(ele, "defaultLabel", data.getName(), true);
-            cr.addAttr(ele, "defaultValue",
-                Double.toString(entries.get(0).getKm()), true);
+            cr.addAttr(ele, "defaultValue", Double.toString(start), true);
         } else if (data.getName().equals("ld_to")) {
             cr.addAttr(ele, "defaultLabel", data.getName(), true);
-            cr.addAttr(ele, "defaultValue",
-                Double.toString(entries.get(entries.size()-1).getKm()), true);
+            cr.addAttr(ele, "defaultValue", Double.toString(end), true);
         }
 
         return ele;

http://dive4elements.wald.intevation.org