changeset 2709:cd6bcca17de6

Added states and improved transition model for MINFO middle bed height calculation. flys-artifacts/trunk@4431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 15:09:55 +0000 (2012-05-16)
parents 282db12a5bdf
children 013882485011
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/minfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiStringArrayState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SoundingsSelect.java
diffstat 5 files changed, 275 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed May 16 14:56:28 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed May 16 15:09:55 2012 +0000
@@ -1,3 +1,20 @@
+2012-05-16  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/artifacts/minfo.xml: Added states and transitions for MINFO
+	  middle bed height calculation.
+
+	* src/main/java/de/intevation/flys/artifacts/states/MultiStringArrayState.java:
+	  New. Nearly a copy of MultiIntArrayState but uses String values.
+
+	* src/main/java/de/intevation/flys/artifacts/states/SoundingsSelect.java:
+	  New subclass of MultiStringArrayState. It will be used for bed heights
+	  selection. We need to do handle the values as string, because singles
+	  and epochs are mixed, so the DB ID is not enough as parameter value.
+
+	* src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java:
+	  New. This state will trigger the calculation for middle bed height in
+	  MINFO module.
+
 2012-05-16  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java:
--- a/flys-artifacts/doc/conf/artifacts/minfo.xml	Wed May 16 14:56:28 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/minfo.xml	Wed May 16 15:09:55 2012 +0000
@@ -21,14 +21,27 @@
             <condition data="calculation_mode" value="calc.flow.velocity" operator="equal"/>
         </transition>
 
+        <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
+            <from state="state.minfo.calculation_mode"/>
+            <to state="state.minfo.distance_only"/>
+            <condition data="calculation_mode" value="calc.bed.middle" operator="equal"/>
+        </transition>
+
         <state id="state.minfo.distance_only" description="state.minfo.distance_only" state="de.intevation.flys.artifacts.states.DistanceOnlySelect" helpText="help.minfo.distance">
             <data name="ld_from" type="Double" />
             <data name="ld_to"   type="Double" />
         </state>
 
-        <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+        <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
             <from state="state.minfo.distance_only"/>
             <to state="state.minfo.dischargestate"/>
+            <condition data="calculation_mode" value="calc.flow.velocity" operator="equal"/>
+        </transition>
+
+        <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
+            <from state="state.minfo.distance_only"/>
+            <to state="state.minfo.soundings"/>
+            <condition data="calculation_mode" value="calc.bed.middle" operator="equal"/>
         </transition>
 
         <state id="state.minfo.dischargestate" description="state.minfo.dischargestate" state="de.intevation.flys.artifacts.states.DischargeState" helpText="help.minfo.dischargestate">
@@ -36,11 +49,20 @@
             <data name="main.channel"  type="intoptions"/>
         </state>
 
+        <state id="state.minfo.soundings" description="state.minfo.soundingsstate" state="de.intevation.flys.artifacts.states.SoundingsSelect" helpText="help.minfo.soundingsstate">
+            <data name="soundings" type="options"/>
+        </state>
+
         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
             <from state="state.minfo.dischargestate"/>
             <to state="state.minfo.flow_velocity"/>
         </transition>
 
+        <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+            <from state="state.minfo.soundings"/>
+            <to state="state.minfo.bedheight_middle"/>
+        </transition>
+
         <state id="state.minfo.flow_velocity" description="state.minfo.flow_velocity" state="de.intevation.flys.artifacts.states.FlowVelocityState" helpText="help.minfo.flowvelocity">
             <outputmodes>
                 <outputmode name="flow_velocity" description="output.flow_velocity" mime-type="image/png" type="chart">
@@ -61,6 +83,24 @@
             </outputmodes>
         </state>
 
+        <state id="state.minfo.bedheight_middle" description="state.minfo.bedheight_middle" state="de.intevation.flys.artifacts.states.MiddleBedHeight" helpText="help.minfo.bedheight_middle">
+            <outputmodes>
+                <outputmode name="bedheight_middle" description="output.bedheight_middle" mime-type="image/png" type="chart">
+                    <facets>
+                        <!-- TODO -->
+                    </facets>
+                </outputmode>
+                <outputmode name="bedheight_middle_export" description="output.bedheight_middle_export" mime-type="text/plain" type="export">
+                    <facets>
+                        <facet name="csv" description="facet.bedheight_middle_export.csv" />
+                        <!--
+                        <facet name="pdf" description="facet.historical_discharge.pdf" />
+                        -->
+                    </facets>
+                </outputmode>
+            </outputmodes>
+        </state>
+
     </states>
 
 </artifact>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java	Wed May 16 15:09:55 2012 +0000
@@ -0,0 +1,34 @@
+package de.intevation.flys.artifacts.states;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+
+public class MiddleBedHeight extends DefaultState {
+
+    private static final Logger logger = Logger.getLogger(MiddleBedHeight.class);
+
+
+    @Override
+    public Object computeAdvance(
+        FLYSArtifact artifact,
+        String       hash,
+        CallContext  context,
+        List<Facet>  facets,
+        Object       old
+    ) {
+        logger.debug("MiddleBedHeight.computeAdvance");
+
+        logger.warn("TODO: Implement MiddleBedHeight.computeAdvance");
+
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiStringArrayState.java	Wed May 16 15:09:55 2012 +0000
@@ -0,0 +1,94 @@
+package de.intevation.flys.artifacts.states;
+
+import org.w3c.dom.Element;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+import de.intevation.artifacts.common.model.KVP;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.resources.Resources;
+
+
+/**
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public abstract class MultiStringArrayState extends DefaultState {
+
+    private static final Logger logger =
+        Logger.getLogger(MultiStringArrayState.class);
+
+
+    @Override
+    protected void appendItems(
+        Artifact       artifact,
+        ElementCreator creator,
+        String         name,
+        CallContext    context,
+        Element        select
+    ) {
+        try {
+            creator.addAttr(select, "type", "options", true);
+
+            for (KVP kvp: getOptions(artifact, name)) {
+                Element item = creator.create("item");
+                creator.addAttr(item, "label", kvp.getValue().toString(), true);
+                creator.addAttr(item, "value", kvp.getKey().toString(), true);
+
+                select.appendChild(item);
+            }
+        }
+        catch (IllegalArgumentException iae) {
+            logger.warn("Illegal argument", iae);
+        }
+    }
+
+
+    @Override
+    protected Element createStaticData(
+        FLYSArtifact   flys,
+        ElementCreator creator,
+        CallContext    cc,
+        String         name,
+        String         value,
+        String         type
+    ) {
+        Element data = creator.create("data");
+        creator.addAttr(data, "name",  name, true);
+        creator.addAttr(data, "type",  type, true);
+        creator.addAttr(data, "label",
+            Resources.getMsg(cc.getMeta(), name, name), true);
+
+        String[] values = value.split(";");
+
+        for (String val: values) {
+            Element item = creator.create("item");
+            creator.addAttr(item, "value", val, true);
+            creator.addAttr(item, "label", getLabelFor(cc, name, val), true);
+
+            data.appendChild(item);
+        }
+
+        return data;
+    }
+
+
+    protected abstract KVP<String, String>[] getOptions(
+        Artifact artifact,
+        String   parameterName
+    )
+    throws IllegalArgumentException;
+
+
+    protected abstract String getLabelFor(
+        CallContext cc,
+        String      parameterName,
+        String      value
+    )
+    throws IllegalArgumentException;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SoundingsSelect.java	Wed May 16 15:09:55 2012 +0000
@@ -0,0 +1,89 @@
+package de.intevation.flys.artifacts.states;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifacts.common.model.KVP;
+
+
+public class SoundingsSelect extends MultiStringArrayState {
+
+    public static final String SOUNDINGS  = "soundings";
+
+
+    private static final Logger logger = Logger.getLogger(SoundingsSelect.class);
+
+
+    @Override
+    public String getUIProvider() {
+        return "parameter-matrix";
+    }
+
+
+    @Override
+    protected KVP<String, String>[] getOptions(
+        Artifact artifact,
+        String   parameterName
+    )
+    throws IllegalArgumentException
+    {
+        logger.debug("Get options for parameter: '" + parameterName + "'");
+
+        if (!testParameterName(parameterName)) {
+            throw new IllegalArgumentException(
+                "Invalid parameter for state: '" + parameterName + "'");
+        }
+
+        KVP[] kvp = new KVP[10];
+
+        for (int i = 0; i < 10; i++) {
+            String id    = String.valueOf(i);
+            String value = "#" + id;
+
+            kvp[i] = new KVP(id, value);
+        }
+
+        return kvp;
+    }
+
+
+    @Override
+    protected String getLabelFor(
+        CallContext cc,
+        String      parameterName,
+        String      value
+    ) throws IllegalArgumentException
+    {
+        if (!testParameterName(parameterName)) {
+            throw new IllegalArgumentException(
+                "Invalid parameter for state: '" + parameterName + "'");
+        }
+
+        return "#" + value;
+    }
+
+
+    /**
+     * This method might be used to test, if a parameter name is handled by this
+     * state.
+     *
+     * @param parameterName The name of a parameter.
+     *
+     * @return true, if parameterName is one of <i>MAIN_CHANNEL</i> or
+     * <i>TOTAL_CHANNEL</i>. Otherwise false.
+     */
+    protected boolean testParameterName(String parameterName) {
+        if (parameterName == null || parameterName.length() == 0) {
+            return false;
+        }
+        else if (parameterName.equals(SOUNDINGS)) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org