changeset 3073:0ace00c0c12a

FixA: Improved W/Q facet code flys-artifacts/trunk@4664 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Jun 2012 14:03:16 +0000
parents 0d3dd8230064
children 6502b17931b9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java
diffstat 4 files changed, 33 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jun 14 13:46:07 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Jun 14 14:03:16 2012 +0000
@@ -1,3 +1,14 @@
+2012-06-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java:
+	  Added more debug output.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java:
+	  Interpolate the coeffs for the function to be drawn.
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java:
+	  Made code more robust for none existing data.
+
 2012-06-14  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: Added
@@ -29,8 +40,8 @@
 
 2012-06-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
-    * src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java:
-      Use binary search again.
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java:
+	  Use binary search again.
 
 2012-06-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Thu Jun 14 13:46:07 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Thu Jun 14 14:03:16 2012 +0000
@@ -145,6 +145,7 @@
         }
 
         if (xs.size() < 2) {
+            log.warn("Too less points.");
             return false;
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Thu Jun 14 13:46:07 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Thu Jun 14 14:03:16 2012 +0000
@@ -75,23 +75,19 @@
 
             Parameters params = result.getParameters();
             String[] columnNames = params.getColumnNames();
-            for(String columnName : columnNames) {
-                logger.debug("FixWQCurveFacet.getData: columnName = '" + columnName + "'");
+
+            String[] paramNames = ff.getParameterNames();
+
+            double [] coeffs = params.interpolate("km", km, paramNames);
+
+            if (coeffs == null) {
+                return null;
             }
-            int row = params.binarySearch("km", km, Math.pow(10, -4));
-            if(row < 0) {
-                row = -row - 1;
-                logger.debug("getData: no direct hit in params.binarySearch");
-            }
-            String[] paramNames = ff.getParameterNames();
-            int[] paramInd = params.columnIndices(paramNames);
-            double[] coeffs = new double[paramNames.length];
-            params.get(row, paramInd, coeffs);
 
             de.intevation.flys.artifacts.math.Function mf =
                 ff.instantiate(coeffs);
 
-            double maxQ = getMaxQ(result, km);
+            double maxQ = getMaxQ(params, km);
             logger.debug("getData: maxQ = " + maxQ);
 
             FixFunction fix = new FixFunction(
@@ -109,47 +105,13 @@
     }
 
 
-    protected double getMaxQ(FixResult result, double km) {
-        double maxQ = 0;
-
-        KMIndex<QW []> kmQWRef = result.getReferenced();
-
-        KMIndex.Entry<QW []> qwEntry = kmQWRef.binarySearch(km);
-        if(qwEntry != null) {
-            QW[] qwRef = qwEntry.getValue();
-            if (qwRef != null) {
-                for (int i = 0; i < qwRef.length; i++) {
-                    if (qwRef[i].getQ() > maxQ) {
-                        maxQ = qwRef[i].getQ();
-                    }
-                }
-            }
-        } else {
-            logger.debug("getMaxQ: qwEntry is null, that's odd...");
+    protected double getMaxQ(Parameters params, double km) {
+        double [] maxQ = params.interpolate("km", km, new String[] { "max_q" });
+        if (maxQ == null) {
+            return 1000;
         }
-
-        KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods();
-        KMIndex.Entry<AnalysisPeriod []> periodsEntry = kmQWDAna.binarySearch(km);
-
-        if(periodsEntry != null) {
-            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();
-                            }
-                        }
-                    }
-                }
-            }
-        } else {
-            logger.debug("getMaxQ: periodsEntry is null, that's odd...");
-        }
-        //return maxQ;
-        return 1000; //FIXME replace by parameters.interpolate("q_max")...
+        double mQ = Math.min(10000, Math.abs(maxQ[0]));
+        return mQ + 0.05*mQ;
     }
 
     /**
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Thu Jun 14 13:46:07 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Thu Jun 14 14:03:16 2012 +0000
@@ -136,6 +136,11 @@
         logger.debug("doWQCurveOut");
 
         FixFunction func = (FixFunction)aaf.getData(context);
+
+        if (func == null) {
+            return;
+        }
+
         if(func.getMaxQ() > 0) {
             XYSeries series = DatasetUtilities.sampleFunction2DToSeries(
                 new Function2DAdapter(func.getFunction()),

http://dive4elements.wald.intevation.org