changeset 3101:b31397addf2f

Create Facets for each SQResult and SQFractionResult. flys-artifacts/trunk@4700 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 19 Jun 2012 12:25:01 +0000
parents c0abfb695332
children 581f97001419
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQFractionResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQMeasurementFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java
diffstat 8 files changed, 236 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 19 12:25:01 2012 +0000
@@ -1,3 +1,25 @@
+2012-06-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java: Renamed
+	  the former SQResult to SQFractionResult. This class is now used to store a
+	  set of SQFractionResults for each SQ calculation.
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/SQFractionResult.java:
+	  Former SQResult.
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java:
+	  Create new fake SQFractionResults for fraction A, B and C (used for
+	  testing).
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/sq/SQCurveFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/sq/SQMeasurementFacet.java:
+	  Added the 'fractionIdx' property to get to know which fraction should be
+	  represented.
+
+	* src/main/java/de/intevation/flys/artifacts/states/SQRelation.java: Create
+	  Facets for each SQResult and SQFractionResult.
+
 2012-06-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQCurveFacet.java	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQCurveFacet.java	Tue Jun 19 12:25:01 2012 +0000
@@ -22,12 +22,23 @@
     private static final Logger log = Logger.getLogger(SQCurveFacet.class);
 
 
+    private int fractionIdx;
+
+
     public SQCurveFacet() {
     }
 
 
-    public SQCurveFacet(int idx, String name, String description) {
-        super(idx, name, description, ComputeType.ADVANCE, null, null);
+    public SQCurveFacet(
+        int    idx,
+        int    fractionIdx,
+        String name,
+        String description,
+        String hash,
+        String stateId
+    ) {
+        super(idx, name, description, ComputeType.ADVANCE, hash, stateId);
+        this.fractionIdx = fractionIdx;
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQFractionResult.java	Tue Jun 19 12:25:01 2012 +0000
@@ -0,0 +1,78 @@
+package de.intevation.flys.artifacts.model.sq;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import de.intevation.flys.artifacts.model.Parameters;
+
+
+public class SQFractionResult implements Serializable {
+
+    protected Parameters parameters;
+
+    protected SQ[] measurements;
+    protected List<SQ[]> outliers;
+
+
+    public SQFractionResult() {
+        this.outliers = new ArrayList<SQ[]>();
+    }
+
+
+    public SQFractionResult(
+        Parameters parameters,
+        SQ[]       measurements,
+        List<SQ[]> outliers
+    ) {
+        this.parameters   = parameters;
+        this.measurements = measurements;
+        this.outliers     = outliers;
+    }
+
+
+    public Parameters getParameters() {
+        return parameters;
+    }
+
+    public void setParameters(Parameters parameters) {
+        this.parameters = parameters;
+    }
+
+
+    public SQ[] getMeasurements() {
+        return measurements;
+    }
+
+    public void setMeasurements(SQ[] measurements) {
+        this.measurements = measurements;
+    }
+
+
+    public List<SQ[]> getOutliers() {
+        return outliers;
+    }
+
+    public void setOutliers(List<SQ[]> outliers) {
+        this.outliers = outliers;
+    }
+
+
+    public int getOutliersCount() {
+        return outliers.size();
+    }
+
+
+    public SQ[] getOutliers(int idx) {
+        if (idx < outliers.size()) {
+            return outliers.get(idx);
+        }
+
+        return null;
+    }
+
+    public void addOutliers(SQ[] outliers) {
+        this.outliers.add(outliers);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQMeasurementFacet.java	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQMeasurementFacet.java	Tue Jun 19 12:25:01 2012 +0000
@@ -9,7 +9,6 @@
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
-import de.intevation.flys.artifacts.model.sq.SQResult;
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 
 
@@ -23,18 +22,23 @@
     private static final Logger log = Logger.getLogger(SQMeasurementFacet.class);
 
 
+    private int fractionIdx;
+
+
     public SQMeasurementFacet() {
     }
 
 
     public SQMeasurementFacet(
         int    idx,
+        int    fractionIdx,
         String name,
         String description,
         String hash,
         String stateId
     ) {
         super(idx, name, description, ComputeType.ADVANCE, hash, stateId);
+        this.fractionIdx = fractionIdx;
     }
 
 
@@ -48,9 +52,10 @@
             CalculationResult res = (CalculationResult) flys.compute(
                 context, ComputeType.ADVANCE, false);
 
-            SQResult[] result = (SQResult[]) res.getData();
+            SQResult[]       result  = (SQResult[]) res.getData();
+            SQFractionResult fResult = result[index].getFraction(fractionIdx);
 
-            return result[index].getMeasurements();
+            return fResult.getMeasurements();
         }
 
         return null;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java	Tue Jun 19 12:25:01 2012 +0000
@@ -5,7 +5,6 @@
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 
-
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.DataFacet;
@@ -25,6 +24,7 @@
 
 
     private int iteration;
+    private int fractionIdx;
 
 
     public SQOutlierFacet() {
@@ -33,6 +33,7 @@
 
     public SQOutlierFacet(
         int    idx,
+        int    fractionIdx,
         int    iteration,
         String name,
         String description,
@@ -40,6 +41,7 @@
         String stateId
     ) {
         super(idx, name, description, ComputeType.ADVANCE, hash, stateId);
+        this.fractionIdx = fractionIdx;
     }
 
 
@@ -53,9 +55,10 @@
             CalculationResult res = (CalculationResult) flys.compute(
                 context, ComputeType.ADVANCE, false);
 
-            SQResult[] result = (SQResult[]) res.getData();
+            SQResult[]       result  = (SQResult[]) res.getData();
+            SQFractionResult fResult = result[index].getFraction(fractionIdx);
 
-            return result[index].getOutliers(iteration);
+            return fResult.getOutliers(iteration);
         }
 
         return null;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java	Tue Jun 19 12:25:01 2012 +0000
@@ -48,7 +48,21 @@
         outliers.add(fOutliers);
         outliers.add(tOutliers);
 
-        return new SQResult[] { new SQResult(null, measurements, outliers) };
+        SQResult res = new SQResult();
+
+        res.setFraction(
+            SQResult.FRACTION_A,
+            new SQFractionResult(null, measurements, outliers));
+
+        res.setFraction(
+            SQResult.FRACTION_B,
+            new SQFractionResult(null, measurements, outliers));
+
+        res.setFraction(
+            SQResult.FRACTION_C,
+            new SQFractionResult(null, measurements, outliers));
+
+        return new SQResult[] { res };
     }
 
     protected SQ[] getFakeMeasurements() {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java	Tue Jun 19 12:25:01 2012 +0000
@@ -9,70 +9,34 @@
 
 public class SQResult implements Serializable {
 
-    protected Parameters parameters;
+    public static final int FRACTION_A = 0;
+    public static final int FRACTION_B = 1;
+    public static final int FRACTION_C = 2;
+    public static final int FRACTION_D = 3;
+    public static final int FRACTION_E = 4;
+    public static final int FRACTION_F = 5;
 
-    protected SQ[] measurements;
-    protected List<SQ[]> outliers;
+
+    protected SQFractionResult[] fractions;
 
 
     public SQResult() {
-        this.outliers = new ArrayList<SQ[]>();
-    }
-
-
-    public SQResult(
-        Parameters parameters,
-        SQ[]       measurements,
-        List<SQ[]> outliers
-    ) {
-        this.parameters   = parameters;
-        this.measurements = measurements;
-        this.outliers     = outliers;
+        fractions = new SQFractionResult[6];
     }
 
 
-    public Parameters getParameters() {
-        return parameters;
-    }
-
-    public void setParameters(Parameters parameters) {
-        this.parameters = parameters;
-    }
-
-
-    public SQ[] getMeasurements() {
-        return measurements;
-    }
-
-    public void setMeasurements(SQ[] measurements) {
-        this.measurements = measurements;
-    }
-
-
-    public List<SQ[]> getOutliers() {
-        return outliers;
-    }
-
-    public void setOutliers(List<SQ[]> outliers) {
-        this.outliers = outliers;
-    }
-
-
-    public int getOutliersCount() {
-        return outliers.size();
-    }
-
-
-    public SQ[] getOutliers(int idx) {
-        if (idx < outliers.size()) {
-            return outliers.get(idx);
+    public SQFractionResult getFraction(int idx) {
+        if (idx < fractions.length) {
+            return fractions[idx];
         }
 
         return null;
     }
 
-    public void addOutliers(SQ[] outliers) {
-        this.outliers.add(outliers);
+    public void setFraction(int idx, SQFractionResult fraction) {
+        if (idx < fractions.length) {
+            this.fractions[idx] = fraction;
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java	Tue Jun 19 11:13:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java	Tue Jun 19 12:25:01 2012 +0000
@@ -15,6 +15,7 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.sq.SQCurveFacet;
+import de.intevation.flys.artifacts.model.sq.SQFractionResult;
 import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet;
 import de.intevation.flys.artifacts.model.sq.SQOutlierFacet;
 import de.intevation.flys.artifacts.model.sq.SQRelationCalculation;
@@ -54,6 +55,8 @@
         }
 
         SQResult[] sqr = (SQResult[]) res.getData();
+        logger.info("Calculation computed " + sqr.length + " SQResult objects");
+
         createFacets(newFacets, sqr, hash);
 
         Facet csv = new DataFacet(
@@ -80,27 +83,84 @@
     ) {
         String stateId = getID();
 
-        // TODO Create facets for each parameter type (A-F)
-        container.add(new SQMeasurementFacet(
-            0,
-            SQ_A_MEASUREMENT,
-            "Measurement TODO",
-            hash,
-            stateId
-        ));
+        for (int res = 0, n = sqr.length; res < n; res++) {
 
-        container.add(new SQCurveFacet(0, SQ_A_CURVE, "TODO"));
+            for (int i = 0; i < 6; i++) {
+                SQFractionResult result = sqr[res].getFraction(i);
 
-        for (int i = 0, C = sqr[0].getOutliersCount(); i < C; i++) {
-            container.add(new SQOutlierFacet(
-                0,
-                i,
-                SQ_A_OUTLIER,
-                "OUTLIER AT" + i,
-                hash,
-                stateId
-            ));
+                if (result == null) {
+                    logger.warn("Fraction at index " + i + " is empty!");
+                    continue;
+                }
+
+                container.add(new SQMeasurementFacet(
+                    res,
+                    i,
+                    getFractionFacetname(1, i),
+                    "Measurement (Fraction " + i + ")",
+                    hash,
+                    stateId
+                ));
+
+                container.add(new SQCurveFacet(
+                    res,
+                    i,
+                    getFractionFacetname(0, i),
+                    "CURVE AT " + i,
+                    hash,
+                    stateId
+                ));
+
+                for (int j = 0, C = result.getOutliersCount(); j < C; j++) {
+                    container.add(new SQOutlierFacet(
+                        res,
+                        i,
+                        j,
+                        getFractionFacetname(2, i),
+                        "OUTLIER AT " + i,
+                        hash,
+                        stateId
+                    ));
+                }
+            }
         }
     }
+
+
+    protected String getFractionFacetname(int type, int fractionIdx) {
+        logger.debug("getFractionFacetname(): " + type + " | " + fractionIdx);
+
+        switch (type) {
+            case 0:
+                switch (fractionIdx) {
+                    case 0: return SQ_A_CURVE;
+                    case 1: return SQ_B_CURVE;
+                    case 2: return SQ_C_CURVE;
+                    case 3: return SQ_D_CURVE;
+                    case 4: return SQ_E_CURVE;
+                    case 5: return SQ_F_CURVE;
+                }
+            case 1:
+                switch (fractionIdx) {
+                    case 0: return SQ_A_MEASUREMENT;
+                    case 1: return SQ_B_MEASUREMENT;
+                    case 2: return SQ_C_MEASUREMENT;
+                    case 3: return SQ_D_MEASUREMENT;
+                    case 4: return SQ_E_MEASUREMENT;
+                    case 5: return SQ_F_MEASUREMENT;
+                }
+            case 2:
+                switch (fractionIdx) {
+                    case 0: return SQ_A_OUTLIER;
+                    case 1: return SQ_B_OUTLIER;
+                    case 2: return SQ_C_OUTLIER;
+                    case 3: return SQ_D_OUTLIER;
+                    case 4: return SQ_E_OUTLIER;
+                    case 5: return SQ_F_OUTLIER;
+                }
+        }
+
+        return null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org