diff artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/StaticSQRelationFacet.java @ 7298:5b2126d21c2e

Polish SQ Datacage and Facets The starting point is now taken from the blackboard
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 11 Oct 2013 15:35:25 +0200
parents af13ceeba52a
children e4606eae8ea5
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/StaticSQRelationFacet.java	Fri Oct 11 12:44:25 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/StaticSQRelationFacet.java	Fri Oct 11 15:35:25 2013 +0200
@@ -8,10 +8,15 @@
 
 package org.dive4elements.river.artifacts.states.sq;
 
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
 import org.dive4elements.artifactdatabase.state.DefaultFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.DataProvider;
 import org.dive4elements.river.artifacts.math.fitting.Function;
 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
 import org.dive4elements.river.artifacts.model.sq.SQFunction;
@@ -26,6 +31,8 @@
 
     private StaticSQRelation relation;
 
+    private static final Logger logger =
+        Logger.getLogger(StaticSQRelationFacet.class);
 
     public StaticSQRelationFacet(
         int ndx,
@@ -43,7 +50,34 @@
         Function func = FunctionFactory.getInstance().getFunction(FUNCTION);
         org.dive4elements.river.artifacts.math.Function function =
             func.instantiate(coeffs);
-        SQFunction sqf = new SQFunction(function, 0, qmax);
+
+        /* Figure out a good starting point by checking for calculated
+         * SQ Curves and using their starting point */
+
+        // this is ok because we are a DefaultFacet and not a DataFacet
+        // and so we are not registred with Mr. Blackboard
+        List<DataProvider> providers = context.getDataProvider(name);
+
+        double startingPoint = Double.MAX_VALUE;
+
+        for (DataProvider dp: providers) {
+            SQFunction other = (SQFunction) dp.provideData(
+                name,
+                null,
+                context);
+            if (other == null) {
+                // name is not really unique here but it's our only key
+                // should not happen anyhow.
+                logger.error("Did not get data from: " + name);
+                continue;
+            }
+            startingPoint = Math.min(other.getMinQ(), startingPoint);
+        }
+        if (startingPoint == Double.MAX_VALUE) {
+            startingPoint = 0;
+        }
+
+        SQFunction sqf = new SQFunction(function, startingPoint, qmax);
         return sqf;
     }
 

http://dive4elements.wald.intevation.org