[PATCH] (issue1755) Add good defaults for bedquality distance selection

Wald Commits scm-commit at wald.intevation.org
Tue Mar 24 18:17:29 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427217443 -3600
# Node ID 39ce099a655198bef522969e4485d4b933e4c164
# Parent  b5854a9b101c6e2cc26fa8259331562361d09966
(issue1755) Add good defaults for bedquality distance selection

diff -r b5854a9b101c -r 39ce099a6551 artifacts/doc/conf/artifacts/minfo.xml
--- a/artifacts/doc/conf/artifacts/minfo.xml	Tue Mar 24 15:22:16 2015 +0100
+++ b/artifacts/doc/conf/artifacts/minfo.xml	Tue Mar 24 18:17:23 2015 +0100
@@ -41,7 +41,7 @@
 
         <transition transition="org.dive4elements.river.artifacts.transitions.ValueCompareTransition">
             <from state="state.minfo.calculation_mode"/>
-            <to state="state.minfo.distance"/>
+            <to state="state.minfo.bed.distance"/>
             <condition data="calculation_mode" value="calc.bed.quality" operator="equal"/>
         </transition>
 
@@ -84,7 +84,7 @@
         </transition>
 
         <transition transition="org.dive4elements.river.artifacts.transitions.DefaultTransition">
-            <from state="state.minfo.distance"/>
+            <from state="state.minfo.bed.distance"/>
             <to state="state.minfo.bed.periods"/>
             <condition data="calculation_mode" value="calc.bed.quality" operator="equal"/>
         </transition>
@@ -113,6 +113,12 @@
             <data name="periods" type="String"/>
         </state>
 
+        <state id="state.minfo.bed.distance" description="state.minfo.distance" state="org.dive4elements.river.artifacts.states.minfo.BedQualityDistanceSelect" helpText="help.state.minfo.distance">
+            <data name="ld_from" type="Double" />
+            <data name="ld_to"   type="Double" />
+            <data name="ld_step" type="Double" />
+        </state>
+
         <transition transition="org.dive4elements.river.artifacts.transitions.DefaultTransition">
             <from state="state.minfo.dischargestate"/>
             <to state="state.minfo.flow_velocity"/>
diff -r b5854a9b101c -r 39ce099a6551 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java	Tue Mar 24 18:17:23 2015 +0100
@@ -0,0 +1,80 @@
+/* Copyright (C) 2011, 2012, 2013, 2015 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.states.minfo;
+
+import java.util.Date;
+import java.util.List;
+
+import org.w3c.dom.Element;
+
+import org.apache.log4j.Logger;
+
+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.artifacts.common.utils.XMLUtils;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+
+import org.dive4elements.artifactdatabase.data.StateData;
+
+/** Extended Distance Select with default values appropiate for BedQuality */
+public class BedQualityDistanceSelect extends DistanceSelect {
+
+    private static Logger log = Logger.getLogger(BedQualityDistanceSelect.class);
+
+    /**
+     * The default constructor that initializes an empty State object.
+     */
+    public BedQualityDistanceSelect() {
+    }
+
+    @Override
+    protected Element createData(
+        XMLUtils.ElementCreator cr,
+        Artifact    artifact,
+        StateData   data,
+        CallContext context)
+    {
+        Element ele = super.createData(cr, artifact, data, context);
+        if (!data.getName().equals("ld_from") && !data.getName().equals("ld_to")) {
+            return ele;
+        }
+
+        D4EArtifact arti = (D4EArtifact) artifact;
+        RiverAccess access = new RiverAccess(arti);
+
+        /* Bit of an overkill here but it will be cached and accessed
+         * in the next state anyway. */
+        BedOverview overview = BedOverviewFactory.getOverview(access.getRiverName());
+
+        if (overview == null) {
+            log.warn("No overview found for river '" + access.getRiverName() + "'");
+            return ele;
+        }
+
+        KMIndex<List<Date>> entries = overview.filter(BedOverview.ACCEPT);
+        entries.sort();
+
+        if (data.getName().equals("ld_from")) {
+            cr.addAttr(ele, "defaultLabel", data.getName(), true);
+            cr.addAttr(ele, "defaultValue", Double.toString(entries.get(0).getKm()), 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);
+        }
+
+        return ele;
+    }
+}
diff -r b5854a9b101c -r 39ce099a6551 artifacts/src/main/java/org/dive4elements/river/utils/KMIndex.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/KMIndex.java	Tue Mar 24 15:22:16 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/KMIndex.java	Tue Mar 24 18:17:23 2015 +0100
@@ -80,6 +80,14 @@
         Collections.sort(entries);
     }
 
+    public int size() {
+        return entries.size();
+    }
+
+    public Entry<A> get(int idx) {
+        return entries.get(idx);
+    }
+
     /** Return the first entry at km. */
     public Entry<A> search(double km) {
         for (Entry<A> entry: entries) {


More information about the Dive4Elements-commits mailing list