changeset 3067:d87aadaa4f7e

Add FixDerivedCurveGenerator class flys-artifacts/trunk@4651 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Wed, 13 Jun 2012 12:21:22 +0000
parents 4c22194b733a
children 2fc9d0c65dc9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.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/exports/fixings/FixDerivedCurveGenerator.java
diffstat 5 files changed, 141 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 13 11:13:17 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 13 12:21:22 2012 +0000
@@ -1,3 +1,15 @@
+2012-06-13	Christian Lins	<christian.lins@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java:
+	  Workaround for IndexOutOfBoundsException.
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java:
+	  Output generator for fixing derived curve.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java:
+	  Use binary search with epsilon again.
+
 2012-06-13  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Jun 13 11:13:17 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Jun 13 12:21:22 2012 +0000
@@ -88,7 +88,10 @@
                 return null;
             }
 
-            QWD[] qwdData = periods[index].getQSectorAverages();
+            QWD[] qwdData = null;
+            if (index < periods.length) {
+                qwdData = periods[index].getQSectorAverages();
+            }
 
             if (logger.isDebugEnabled()) {
                 int resSize = qwdData != null ? qwdData.length : -1;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Wed Jun 13 11:13:17 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Wed Jun 13 12:21:22 2012 +0000
@@ -76,6 +76,10 @@
 
             Parameters params = result.getParameters();
             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];
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Wed Jun 13 11:13:17 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Wed Jun 13 12:21:22 2012 +0000
@@ -78,7 +78,7 @@
             for(String columnName : columnNames) {
                 logger.debug("FixWQCurveFacet.getData: columnName = '" + columnName + "'");
             }
-            int row = params.binarySearch("km", km /*, Math.pow(10, -4)*/); //FIXME Use epsilon as soon access.getCurrentKm() is fixed
+            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");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java	Wed Jun 13 12:21:22 2012 +0000
@@ -0,0 +1,120 @@
+package de.intevation.flys.exports.fixings;
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+
+import de.intevation.flys.artifacts.model.fixings.FixFunction;
+
+import de.intevation.flys.exports.ChartGenerator;
+import de.intevation.flys.exports.XYChartGenerator;
+
+import de.intevation.flys.jfree.Function2DAdapter;
+import de.intevation.flys.jfree.StyledXYSeries;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.data.general.DatasetUtilities;
+import org.jfree.data.xy.XYSeries;
+    
+import org.w3c.dom.Document;
+
+/**
+ * Generator for fixation derived function curve.
+ *
+ * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a>
+ */
+public class FixDerivedCurveGenerator 
+extends XYChartGenerator
+implements FacetTypes
+{
+    private static Logger logger = 
+        Logger.getLogger(FixDerivedCurveGenerator.class);
+
+    public static final String I18N_CHART_TITLE =
+        "chart.fixings.derived.title";
+
+    public static final String I18N_CHART_SUBTITLE = 
+        "chart.fixings.derived.subtitle";
+
+    public static final String I18N_XAXIS_LABEL =
+        "chart.fixings.derived.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL = 
+        "chart.fixings.derived.yaxis.label";
+
+    public static final String I18N_CHART_TITLE_DEFAULT = 
+        "Ableitungskurve";
+
+    public static final String I18N_XAXIS_LABEL_DEFAULT =
+        "Q [m\u00B3/s]";
+
+    public static final String I18N_YAXIS_LABEL_DEFAULT =
+        "W [NN + m]";
+
+    public static enum YAXIS {
+        W(0),
+        Q(1);
+        public int idx;
+        private YAXIS(int c) {
+            idx = c;
+        }   
+    }
+
+
+    @Override
+    public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+        logger.debug("doOut");
+
+        FixFunction func = (FixFunction)aaf.getData(context);
+        if(func.getMaxQ() > 0) {
+            XYSeries series = DatasetUtilities.sampleFunction2DToSeries(
+                new Function2DAdapter(func.getFunction()),
+                0,              // start
+                func.getMaxQ(), // end
+                500,            // number of samples
+                aaf.getFacetDescription());
+            addAxisSeries(series, 0, visible);
+        }
+        else {
+            logger.warn("doOut: func.getMaxQ() returns 0");
+        }
+    }
+
+
+    @Override
+    protected String getDefaultChartTitle() {
+        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
+    }
+
+
+    @Override
+    protected String getDefaultXAxisLabel() {
+        return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
+    }
+
+
+    @Override
+    protected String getDefaultYAxisLabel(int pos) {
+        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); 
+    }
+
+
+    @Override
+    protected ChartGenerator.YAxisWalker getYAxisWalker() {
+        return new YAxisWalker() {
+            @Override
+            public int length() {
+                return YAXIS.values().length;
+            }
+
+            @Override
+             public String getId(int idx) {
+                YAXIS[] yaxes = YAXIS.values();
+                return yaxes[idx].toString();
+            }
+        };
+    }
+}
+
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org