changeset 3081:26119b7b3154

Fixing output generator hacking flys-artifacts/trunk@4677 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Sun, 17 Jun 2012 20:45:01 +0000
parents dc2765e31e1f
children 9e03960b3ab8
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java
diffstat 7 files changed, 57 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sun Jun 17 20:45:01 2012 +0000
@@ -1,3 +1,21 @@
+2012-06-17	Christian Lins <christian.lins@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/Parameters.java:
+	  Comments added.
+	  
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java:
+	  Logging output added.
+	  
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java:
+	  Max Q is now determined by parameter.interpolate().
+	  
+	* src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java,
+	  src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java:
+	  Use getCurrentKmFromRequest() in output generation.
+	  
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Typo in method description.
+
 2012-06-15  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java	Sun Jun 17 20:45:01 2012 +0000
@@ -184,7 +184,7 @@
     ) {
         int row = binarySearch(columnIndex, key, EPSILON);
 
-        if (row >= 0) {
+        if (row >= 0) { // direct hit
             for (int i = 0; i < values.length; ++i) {
                 values[i] = columns[i].getQuick(row);
             }
@@ -238,7 +238,8 @@
         }
 
         row = -row - 1;
-        if (row < 1 || row >= size()) { // out of bounds
+        if (row < 1 || row >= size()) {
+			log.warn("interpolate: row is out of bounds");
             return null;
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Sun Jun 17 20:45:01 2012 +0000
@@ -34,6 +34,7 @@
     private static Logger logger = Logger.getLogger(FixDerivateFacet.class);
 
     private double currentKm;
+    private double maxQ;
 
     /** Trivial Constructor. */
     public FixDerivateFacet() {
@@ -81,6 +82,14 @@
             Function.Derivative fd = ff.getDerivative();
 
             Parameters params = result.getParameters();
+            
+            // Determine maxQ
+            double[] maxQs = params
+                .interpolate("km", this.currentKm, new String [] { "max_q" });
+            if(maxQs != null) {
+                maxQ = maxQs[0];
+            }
+            
             int row = params.binarySearch("km", currentKm, Math.pow(10, -4));
             if(row < 0) {
                 row = -row - 1;
@@ -112,34 +121,6 @@
 
 
     protected double getMaxQ(FixResult result, double km) {
-        double maxQ = 0;
-
-        KMIndex<QW []> kmQWRef = result.getReferenced();
-
-        QW[] qwRef = kmQWRef.binarySearch(km).getValue();
-        if (qwRef != null) {
-            for (int i = 0; i < qwRef.length; i++) {
-                if (qwRef[i].getQ() > maxQ) {
-                    maxQ = qwRef[i].getQ();
-                }
-            }
-        }
-
-        KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods();
-        AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue();
-
-        if(periods != null) {
-            for (int i = 0; i < periods.length; i++) {
-                QWD[] qwdAna = periods[i].getQWDs();
-                if (qwdAna != null) {
-                    for (int j = 0; j < qwdAna.length; j++) {
-                        if (qwdAna[j].getQ() > maxQ) {
-                            maxQ = qwdAna[j].getQ();
-                        }
-                    }
-                }
-            }
-        }
         return maxQ;
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Sun Jun 17 20:45:01 2012 +0000
@@ -74,12 +74,13 @@
 
             FixResult result = (FixResult) res.getData();
 
-            logger.debug("FixWQCurveFacet.getData: km = " + currentKm);
+            logger.debug("getData: km = " + currentKm);
 
             String function = access.getFunction();
             Function ff = FunctionFactory.getInstance().getFunction(function);
 
             if (ff == null) {
+                logger.warn("getData: ff == null");
                 return null;
             }
 
@@ -89,6 +90,7 @@
             double [] coeffs = params.interpolate("km", currentKm, paramNames);
 
             if (coeffs == null) {
+                logger.warn("getData: coeffs == null");
                 return null;
             }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Sun Jun 17 20:45:01 2012 +0000
@@ -177,7 +177,7 @@
      * True if current MasterArtifact has given output.
      * @param name Name of the output of interest.
      * @param context current context
-     * @return true iff current mater artifact has given output.
+     * @return true if current master artifact has given output.
      */
     protected boolean outputExists(String name, CallContext context) {
         FLYSArtifact master = getMasterArtifact(context);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java	Sun Jun 17 20:45:01 2012 +0000
@@ -4,6 +4,7 @@
 
 import de.intevation.flys.artifacts.model.FacetTypes;
 
+import de.intevation.flys.artifacts.model.fixings.FixDerivateFacet;
 import de.intevation.flys.artifacts.model.fixings.FixFunction;
 
 import de.intevation.flys.exports.ChartGenerator;
@@ -66,19 +67,23 @@
     public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
         logger.debug("doOut");
 
-        FixFunction func = (FixFunction)aaf.getData(context);
-        if(func.getMaxQ() > 0) {
+        FixDerivateFacet facet = (FixDerivateFacet)aaf.getFacet();
+        FixFunction func = (FixFunction)facet.getData(
+            aaf.getArtifact(), context, getCurrentKmFromRequest());
+        
+        double maxQ = func.getMaxQ();
+        maxQ = Math.min(2000.0, Math.abs(maxQ));
+        maxQ += maxQ * 0.05;
+        
+        if(maxQ > 0) {
             XYSeries series = DatasetUtilities.sampleFunction2DToSeries(
                 new Function2DAdapter(func.getFunction()),
                 0,              // start
-                func.getMaxQ(), // end
+                maxQ, // end
                 500,            // number of samples
                 aaf.getFacetDescription());
             addAxisSeries(series, 0, visible);
         }
-        else {
-            logger.warn("doOut: func.getMaxQ() returns 0");
-        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Fri Jun 15 12:42:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Sun Jun 17 20:45:01 2012 +0000
@@ -6,6 +6,7 @@
 
 import de.intevation.flys.artifacts.model.fixings.DateRange;
 import de.intevation.flys.artifacts.model.fixings.FixFunction;
+import de.intevation.flys.artifacts.model.fixings.FixWQCurveFacet;
 import de.intevation.flys.artifacts.model.fixings.QW;
 import de.intevation.flys.artifacts.model.fixings.QWD;
 
@@ -95,12 +96,7 @@
         QWD[] qwds = (QWD[])aaf.getData(context);
 
         if(qwds != null) {
-            // Draw vertical markers
-            for(QWD qwd : qwds) {
-                if (qwd != null) {
-                    addDomainMarker(new ValueMarker(qwd.getQ()));
-                }
-            }
+            // TODO
         }
     }
 
@@ -135,13 +131,20 @@
     protected void doWQCurveOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
         logger.debug("doWQCurveOut");
 
-        FixFunction func = (FixFunction)aaf.getData(context);
+        FixWQCurveFacet facet = (FixWQCurveFacet)aaf.getFacet();
+        FixFunction func = (FixFunction)facet.getData(
+            aaf.getArtifact(), context, getCurrentKmFromRequest());
 
         if (func == null) {
+            logger.warn("doWQCurveOut: Facet does not contain FixFunction");
             return;
         }
+        
+        double maxQ = func.getMaxQ();
+        maxQ = Math.min(2000.0, Math.abs(maxQ));
+        maxQ += maxQ * 0.05;
 
-        if(func.getMaxQ() > 0) {
+        if(maxQ > 0) {
             XYSeries series = DatasetUtilities.sampleFunction2DToSeries(
                 new Function2DAdapter(func.getFunction()),
                 0,              // start
@@ -151,7 +154,7 @@
             addAxisSeries(series, 0, visible);
         }
         else {
-            logger.warn("doWQCurveOut: func.getMaxQ() returns 0");
+            logger.warn("doWQCurveOut: maxQ <= 0");
         }
     }
 

http://dive4elements.wald.intevation.org