changeset 2747:94c6f4ad9b98

Handle case of points in wqday (durationcurve) scenarios. flys-artifacts/trunk@4482 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 23 May 2012 20:39:18 +0000
parents 4634cf5574f7
children 6717b4725ddf
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java
diffstat 2 files changed, 68 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed May 23 20:34:02 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed May 23 20:39:18 2012 +0000
@@ -1,3 +1,8 @@
+2012-05-23	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java:
+	  Handle duration curve case. Do a linear interpolation of the day.
+
 2012-05-23	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java	Wed May 23 20:34:02 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java	Wed May 23 20:39:18 2012 +0000
@@ -10,10 +10,13 @@
 import de.intevation.artifacts.DataProvider;
 
 import de.intevation.flys.artifacts.StaticWKmsArtifact;
+import de.intevation.flys.artifacts.math.Linear;
 import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.RelativePointFacet;
+import de.intevation.flys.artifacts.model.WQDay;
 
 /**
- * Facet to access a point
+ * Facet to access a point.
  */
 public class RelativePointFacet
 extends      BlackboardDataFacet
@@ -26,6 +29,7 @@
         this(RELATIVE_POINT, description);
     }
 
+
     public RelativePointFacet(String name, String description) {
         this.name        = name;
         this.description = description;
@@ -43,37 +47,74 @@
      */
     @Override
     public Object getData(Artifact artifact, CallContext context) {
-        /* CrossSectionWaterLineFacet:
-        List<DataProvider> providers = context.
-            getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA);
-        if (providers.size() < 1) {
-            logger.warn("Could not find Cross-Section data provider.");
-            return new Lines.LineData(new double[][] {}, 0d, 0d);
-        }
-        
-        Object crossSection = providers.get(0)
-            .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context);
-
-        WaterLineArtifact winfo = (WaterLineArtifact)artifact;
-        */
         // Find out whether we live in a duration curve context, there we would
         // provide only a single point.
+        Object wqdays = null;
+        double km = 0d;
         List<DataProvider> providers = context.
             getDataProvider("durationcurve");
         if (providers.size() < 1) {
-            logger.debug("Could not find durationcurve data provider.");
-            //return new Lines.LineData(new double[][] {}, 0d, 0d);
+            logger.warn("Could not find durationcurve data provider.");
         }
         else {
-        Object crossSection = providers.get(0)
-            .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context);
-        
+            wqdays = providers.get(0).provideData(
+                DurationCurveFacet.BB_DURATIONCURVE,
+                null,
+                context);
         }
-        
+        List<DataProvider> kmproviders = context.
+            getDataProvider(DurationCurveFacet.BB_DURATIONCURVE_KM);
+        if (kmproviders.size() < 1) {
+            logger.warn("Could not find durationcurve.km data provider.");
+        }
+        else {
+            logger.debug("Found durationcurve.km data provider.");
+            String dckm = providers.get(0).provideData(
+                DurationCurveFacet.BB_DURATIONCURVE_KM,
+                null,
+                context).toString();
+            km = Double.valueOf(dckm);
+        }
+
         StaticWKmsArtifact staticData =
             (StaticWKmsArtifact) artifact;
-        //return staticData.getWKms(0);
-        return new Point2D.Double(10d,180d);
+
+        if (wqdays != null) {
+            // Which W at this km?
+            double w = staticData.getWAtKmLin(staticData.getWKms(0), km);
+            if (w == -1) {
+                logger.warn("w is -1, already bad sign!");
+            }
+            // Where is this W passed by in the wq-curve?
+            WQDay wqday = (WQDay) wqdays;
+            // Doing a linear Day Of KM.
+            int idx = 0;
+            boolean wIncreases = wqday.getW(0) < wqday.getW(wqday.size()-1);
+            if (wIncreases) {
+                while (idx < wqday.size() && wqday.getW(idx) < w) {
+                    idx++;
+                }
+            }
+            else {
+                idx = wqday.size() -1;
+                while (idx > 0 && wqday.getW(idx) > w) {
+                    idx--;
+                }
+            }
+
+            double day = 0d;
+            int mod = (wIncreases) ? -1 : +1;
+            if (idx != 0 && idx <= wqday.size()-1) {
+                day = Linear.linear(w, wqday.getW(idx +mod), wqday.getW(idx),
+                    wqday.getDay(idx+mod), wqday.getDay(idx));
+            }
+
+            return new Point2D.Double((double) day, w);
+        }
+        logger.warn("not wqkms / w / day found");
+        
+        // TODO better signal failure.
+        return new Point2D.Double(0d, 0d);
     }
 
 

http://dive4elements.wald.intevation.org