changeset 2723:5ce5abd173b9

Added skeleton for gauge discharge curves. flys-artifacts/trunk@4454 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 22 May 2012 09:06:02 +0000
parents 36631f23acdf
children 43474b346272
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/gaugedischarge.xml flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java
diffstat 7 files changed, 309 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon May 21 12:21:35 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue May 22 09:06:02 2012 +0000
@@ -1,3 +1,16 @@
+2012-05-21  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* doc/conf/winfo.xml: Extend compatibility lists.
+
+	* doc/conf/conf.xml: Add gaugedischarge factory and artifact.
+
+	* src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java:
+	  New, State, Facet and Artifact to access discharge curves of gauges.
+
+	* doc/conf/gaugedischarge.xml: New trivial state model for gaugedis.
+
 2012-05-21  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Allow loading of prev. reference curves.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/artifacts/gaugedischarge.xml	Tue May 22 09:06:02 2012 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<artifact name="gaugedischarge">
+  <states>
+    <state id="state.gaugedischarge.init"
+               description="state.gaugedischarge.init"
+               state="de.intevation.flys.artifacts.states.GaugeDischargeState">
+      <outputmodes>
+        <outputmode name="computed_discharge_curve" description="computed_discharge_curve" mime-type="image/png" type="chart">
+          <facets>
+            <facet name="discharge_curve.curve" description="facet.discharge_curve.curve" />
+          </facets>
+        </outputmode>
+      </outputmodes>
+    </state>
+  </states>
+</artifact>
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Mon May 21 12:21:35 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Tue May 22 09:06:02 2012 +0000
@@ -253,6 +253,8 @@
                     <facets>
                         <facet name="duration_curve.w" description="facet.duration_curve.w"/>
                         <facet name="duration_curve.q" description="facet.duration_curve.q"/>
+                        <facet name="other.wq"         description="Point-like data like fixations"/>
+                        <facet name="other.wkms"       description="facet.other.wkms"/>
                         <facet name="duration_curve.mainvalues.q" description="Q Main Values at optional second axis"/>
                         <facet name="computed_discharge_curve.mainvalues.w" description="W Main Values"/>
                         <facet name="duration_curve.manualpoints" description="Manuelle Punkte"/>
@@ -279,6 +281,7 @@
                         <facet name="computed_discharge_curve.q" description="facet.computed_discharge_curve.q"/>
                         <facet name="computed_discharge_curve.mainvalues.q" description="facet.computed_discharge_curve.mainvalues.q"/>
                         <facet name="computed_discharge_curve.mainvalues.w" description="facet.computed_discharge_curve.mainvalues.w"/>
+                        <facet name="discharge_curve.curve" description="facet.discharge_curve.curve"/>
                         <facet name="other.wqkms" description="facet.other.wqkms"/>
                         <facet name="other.wq"    description="Point-like data like fixations"/>
                         <facet name="other.wq"    description="Point-like data like fixations"/>
--- a/flys-artifacts/doc/conf/conf.xml	Mon May 21 12:21:35 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Tue May 22 09:06:02 2012 +0000
@@ -98,6 +98,9 @@
             <artifact-factory name="fixanalysis" description="Factory to create an artifact to be used in fixation analysis."
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.FixationArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+            <artifact-factory name="gaugedischarge" description="Factory to create an artifact to host historical qs."
+                ttl="3600000"
+                artifact="de.intevation.flys.artifacts.GaugeDischargeArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
 
             <!-- MINFO specific Artifacts -->
             <artifact-factory name="minfo" description="Factory to create an artifact to be used in module minfo."
@@ -185,6 +188,7 @@
         <artifact name="new_chart" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/chart.xml" />
         <artifact name="staticwqkms" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/staticwqkms.xml" />
         <artifact name="fixanalysis" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/fixanalysis.xml" />
+        <artifact name="gaugedischarge" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/gaugedischarge.xml" />
     </artifacts>
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java	Tue May 22 09:06:02 2012 +0000
@@ -0,0 +1,131 @@
+package de.intevation.flys.artifacts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+
+import de.intevation.flys.artifacts.states.DefaultState;
+
+
+
+/**
+ * Artifact to store user-added points.
+ */
+public class GaugeDischargeArtifact
+extends      WINFOArtifact
+implements   FacetTypes
+{
+    /** The logger for this class. */
+    private static Logger logger = Logger.getLogger(GaugeDischargeArtifact.class);
+
+    /** The name of the artifact. */
+    public static final String ARTIFACT_NAME = "historicalq";
+
+    // TODO make this one globally available
+    public static final String XPATH_DATA =
+        "/art:action/art:ids/@value";
+
+    /**
+     * Trivial Constructor.
+     */
+    public GaugeDischargeArtifact() {
+        logger.debug("GaugeDischargeArtifact.HistoricalQArtifact()");
+    }
+
+
+    /**
+     * Gets called from factory, to set things up.
+     * Especially, when loaded via datacage mechanisms, provide the
+     * data document.
+     * @param data filled with stuff from dc, if any.
+     */
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.debug("GaugeDischargeArtifact.setup");
+        super.setup(identifier, factory, context, callMeta, data);
+        String ids = XMLUtils.xpathString(
+            data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE);
+        logger.debug("id for gaugedischarge: " + ids);
+    }
+
+
+    /** Return the name of this artifact. */
+    public String getName() {
+        return ARTIFACT_NAME;
+    }
+
+
+    /** Access state data storing the jsonstring with points. 
+    public String getPointsData(String facetName) {
+        return getDataAsString(facetName + ".data");
+    }*/
+
+
+    /**
+     * Setup state and facet, copy from master artifact.
+     */
+    @Override
+    protected void initialize(Artifact art, Object context, CallMeta meta) {
+        logger.debug("GaugeDischargeArtifact.initialize");
+        List<Facet> fs = new ArrayList<Facet>();
+        FLYSArtifact artifact = (FLYSArtifact) art;
+
+        // Get the location(s)
+        importData(artifact, "ld_mode");
+        importData(artifact, "ld_from");
+        importData(artifact, "ld_to");
+        importData(artifact, "ld_locations");
+
+        DefaultState state = (DefaultState) getCurrentState(context);
+        state.computeInit(this, hash(), context, meta, fs);
+        if (!fs.isEmpty()) { 
+            logger.debug("Facets to add in GaugeDischargeArtifact.initialize ."); 
+            facets.put(getCurrentStateId(), fs); 
+        } 
+        else { 
+            logger.debug("No facets to add in GaugeDischargeArtifact.initialize ("
+                + state.getID() + ").");
+        }
+    }
+
+
+
+    /**
+     * Determines Facets initial disposition regarding activity (think of
+     * selection in Client ThemeList GUI). This will be checked one time
+     * when the facet enters a collections describe document.
+     *
+     * @param facetName name of the facet.
+     * @param index     index of the facet.
+     * @return 0 if not active
+     */
+    @Override
+    public int getInitialFacetActivity(
+        String outputName,
+        String facetName,
+        int index)
+    {
+        return 1;
+    }
+}
+// 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/model/GaugeDischargeFacet.java	Tue May 22 09:06:02 2012 +0000
@@ -0,0 +1,73 @@
+package de.intevation.flys.artifacts.model;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ */
+public class GaugeDischargeFacet extends DataFacet {
+
+    private static final Logger logger =
+        Logger.getLogger(GaugeDischargeFacet.class);
+
+
+    public GaugeDischargeFacet() {
+    }
+
+
+    public GaugeDischargeFacet(int index, String name, String desc) {
+        super(index, name, desc, ComputeType.ADVANCE, null, null);
+    }
+
+
+    public GaugeDischargeFacet(
+        int         index,
+        String      name,
+        String      description,
+        ComputeType type,
+        String      stateID,
+        String      hash
+
+    ) {
+        super(index, name, description, type, hash, stateID);
+    }
+
+
+    @Override
+    public Facet deepCopy() {
+        // TODO why waterlevel?
+        GaugeDischargeFacet copy = new GaugeDischargeFacet();
+        copy.set(this);
+        copy.type    = type;
+        copy.hash    = hash;
+        copy.stateId = stateId;
+        return copy;
+    }
+
+
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Get data for discharge curves at index: " +
+                index + " / stateId: " + stateId);
+        }
+
+        FLYSArtifact flys = (FLYSArtifact) artifact;
+
+        CalculationResult res = (CalculationResult)
+            flys.compute(context, hash, stateId, type,  false);
+
+        WQKms[] discharge = (WQKms[]) res.getData();
+
+        return discharge[index];
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java	Tue May 22 09:06:02 2012 +0000
@@ -0,0 +1,69 @@
+package de.intevation.flys.artifacts.states;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.model.GaugeDischargeFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
+
+import de.intevation.flys.artifacts.resources.Resources;
+
+
+/**
+ * The only state for an GaugeDischargeState (River and km known).
+ */
+public class GaugeDischargeState
+extends      DefaultState
+implements   FacetTypes
+{
+    /** Developer-centric description of facet. */
+    public static final String I18N_DESCRIPTION = "facet.discharge.curve";
+
+    /** The logger that is used in this state. */
+    private static final Logger logger = Logger.getLogger(GaugeDischargeState.class);
+
+
+    /**
+     * Add an GaugeDischargeFacet to list of Facets.
+     *
+     * @param artifact Ignored.
+     * @param hash Ignored.
+     * @param context Ignored.
+     * @param meta CallMeta to be used for internationalization.
+     * @param facets List to add AnnotationFacet to.
+     *
+     * @return null.
+     */
+    @Override
+    public Object computeInit(
+        FLYSArtifact artifact,
+        String       hash,
+        Object       context,
+        CallMeta     meta,
+        List<Facet>  facets
+    ) {
+        logger.debug("GaugeDischargeState.computeInit()");
+
+        // TODO caching, / CalculationResultusage
+
+        GaugeDischargeFacet facet = new GaugeDischargeFacet(
+            0,
+            DISCHARGE_CURVE,
+            DISCHARGE_CURVE);
+            //Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION));
+        facets.add(facet);
+
+        return null;
+    }
+    // computeAdvance
+    //WINFOArtifact#getDischargeCurveData
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org