changeset 3028:77b5f5a26700

Added facets for fix analysis. flys-artifacts/trunk@4597 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 06 Jun 2012 08:07:32 +0000
parents 52aac4941d2a
children fa5d5b48028a
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/fixanalysis.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java
diffstat 9 files changed, 371 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 05 17:17:26 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 06 08:07:32 2012 +0000
@@ -1,3 +1,27 @@
+2012-06-06  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Added facets for fix analysis.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixEventsFacet.java:
+	  New. Facets for W/Q-Chart in fix analysis. FixAvSectorFacet is implemented,
+	  the others are just stubs.
+
+	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java:
+	  Add facets to artifact after calculation.
+
+	* src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java:
+	  Added method to get the current km for charts. The km is used for
+	  synchronous navigation in fix analysis charts.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java:
+	  Added new facet types.
+
+	* doc/conf/artifacts/fixanalysis.xml:
+	  Added facets to config.
+
 2012-06-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/Parameters.java:
--- a/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Tue Jun 05 17:17:26 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Wed Jun 06 08:07:32 2012 +0000
@@ -127,6 +127,10 @@
                 <outputmode name="fix_deltawt_export" description="output.fix_deltawt_export" mine-type="text/plain" type="export">
                     <facets>
                         <facet name="csv" description="face.fix_deltawt.csv" />
+                        <facet name="fix_sector_average" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_events" description="Raw event values used in the calculation"/>
+                        <facet name="fix_wq_curve" description="WQ curve"/>
+                        <facet name="fix_outlier" description="The outliers"/>
                     </facets>
                 </outputmode>
                 <outputmode name="fix_report" description="output.fix_report.report" mime-type="text/plain" type="report">
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Tue Jun 05 17:17:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Wed Jun 06 08:07:32 2012 +0000
@@ -396,5 +396,11 @@
         }
         return qs;
     }
+
+
+    public double getCurrentKm() {
+        //TODO: get the current km.
+        return this.from.doubleValue();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Tue Jun 05 17:17:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 06 08:07:32 2012 +0000
@@ -157,5 +157,10 @@
     String MIDDLE_BED_HEIGHT_ANNOTATION = "bedheight_middle.annotation";
 
     String RELATIVE_POINT = "relativepoint";
+
+    String FIX_EVENTS = "fix_events";
+    String FIX_SECTOR_AVERAGE = "fix_sector_average";
+    String FIX_WQ_CURVE = "fix_wq_curve";
+    String FIX_OUTLIER = "fix_outlier";
 }
 // 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/model/fixings/FixAvSectorFacet.java	Wed Jun 06 08:07:32 2012 +0000
@@ -0,0 +1,100 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.FixationArtifactAccess;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.CalculationResult;
+
+import de.intevation.flys.utils.KMIndex;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Facet to show average W values for Q sectors.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixAvSectorFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(FixAvSectorFacet.class);
+
+    /** Trivial Constructor. */
+    public FixAvSectorFacet() {
+    }
+
+
+    public FixAvSectorFacet(int ndx, String description) {
+        super(
+            ndx,
+            FIX_SECTOR_AVERAGE,
+            description,
+            ComputeType.ADVANCE,
+            null,
+            null);
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext.
+     *
+     * @return the data as QWD array (QWD[]).
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("FixAvSectorFacet.getData");
+
+        if (artifact instanceof FLYSArtifact) {
+            FLYSArtifact flys = (FLYSArtifact)artifact;
+            FixationArtifactAccess access = new FixationArtifactAccess(flys);
+
+            CalculationResult res =
+                (CalculationResult) flys.compute(context,
+                                                 ComputeType.ADVANCE,
+                                                 false);
+
+            FixResult result = (FixResult) res.getData();
+
+            double km = access.getCurrentKm();
+
+            KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
+            AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue();
+
+            if (periods == null) {
+                return null;
+            }
+            QWD[] qwdData = periods[index].getQSectorAverages();
+            return periods;
+        }
+        else {
+            logger.debug("Not an instance of FixationArtifact.");
+            return null;
+        }
+    }
+
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public FixAvSectorFacet deepCopy() {
+        FixAvSectorFacet copy = new FixAvSectorFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// 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/fixings/FixEventsFacet.java	Wed Jun 06 08:07:32 2012 +0000
@@ -0,0 +1,66 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.DataFacet;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Facet to show W values for Q values at km for a date.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixEventsFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(FixEventsFacet.class);
+
+    /** Trivial Constructor. */
+    public FixEventsFacet() {
+    }
+
+
+    /**
+     * @param name
+     */
+    public FixEventsFacet(int index, String description) {
+        super(index, FIX_EVENTS, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext (ignored).
+     *
+     * @return the data.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("FixEventsFacet.getData");
+        return null;
+    }
+
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public FixEventsFacet deepCopy() {
+        FixEventsFacet copy = new FixEventsFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// 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/fixings/FixOutlierFacet.java	Wed Jun 06 08:07:32 2012 +0000
@@ -0,0 +1,66 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.DataFacet;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Facet to show the outliers in a fix calculation.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixOutlierFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(FixOutlierFacet.class);
+
+    /** Trivial Constructor. */
+    public FixOutlierFacet() {
+    }
+
+
+    /**
+     * @param name
+     */
+    public FixOutlierFacet(String description) {
+        super(0, FIX_OUTLIER, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext (ignored).
+     *
+     * @return the data.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("FixOutlierFacet.getData");
+        return null;
+    }
+
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public FixOutlierFacet deepCopy() {
+        FixOutlierFacet copy = new FixOutlierFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// 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/fixings/FixWQCurveFacet.java	Wed Jun 06 08:07:32 2012 +0000
@@ -0,0 +1,66 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.DataFacet;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Facet to show the W|Q values.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixWQCurveFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(FixWQCurveFacet.class);
+
+    /** Trivial Constructor. */
+    public FixWQCurveFacet() {
+    }
+
+
+    /**
+     * @param name
+     */
+    public FixWQCurveFacet(String description) {
+        super(0, FIX_WQ_CURVE, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext (ignored).
+     *
+     * @return the data.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("FixWQCurveFacet.getData");
+        return null;
+    }
+
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public FixWQCurveFacet deepCopy() {
+        FixWQCurveFacet copy = new FixWQCurveFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Tue Jun 05 17:17:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Wed Jun 06 08:07:32 2012 +0000
@@ -14,6 +14,14 @@
 
 import de.intevation.flys.artifacts.model.fixings.FixCalculation;
 
+import de.intevation.flys.artifacts.model.fixings.FixAvSectorFacet;
+import de.intevation.flys.artifacts.model.fixings.FixEventsFacet;
+import de.intevation.flys.artifacts.model.fixings.FixOutlierFacet;
+import de.intevation.flys.artifacts.model.fixings.FixWQCurveFacet;
+
+
+import de.intevation.flys.artifacts.model.fixings.DateRange;
+
 import de.intevation.flys.artifacts.states.DefaultState;
 
 import java.util.List;
@@ -50,13 +58,13 @@
 
         CalculationResult res;
 
+        FixationArtifactAccess access =
+            new FixationArtifactAccess(artifact);
+
         if (old instanceof CalculationResult) {
             res = (CalculationResult)old;
         }
         else {
-            FixationArtifactAccess access =
-                new FixationArtifactAccess(artifact);
-
             FixCalculation calc =
                 new FixCalculation(access);
 
@@ -73,6 +81,29 @@
         facets.add(
             new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
 
+        int count = access.getAnalysisPeriods().length;
+        for (int i = 0; i < count; i++) {
+            DateRange period = access.getAnalysisPeriods()[i];
+            for (int j = access.getQSectorStart().intValue();
+                 j < access.getQSectorEnd().intValue();
+                 j++) {
+                //TODO: replace j with q sector string.
+                String description = j + ": " +
+                                     period.getFrom().toString() + " - " +
+                                     period.getTo().toString();
+                facets.add(
+                    new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
+                                         description));
+            }
+            String eventDesc = period.getFrom().toString() +
+                               " - " +
+                               period.getTo().toString();
+            facets.add(new FixEventsFacet(i, eventDesc));
+        }
+        facets.add(new FixEventsFacet(0, "Referenceperiod"));
+        facets.add(new FixWQCurveFacet("W/Q"));
+        facets.add(new FixOutlierFacet("Outlier"));
+
         return res;
     }
 }

http://dive4elements.wald.intevation.org