changeset 3055:1fbf8462f808

FixWQCurveGenerator generates randomized curves as the Facets crashes when retrieving data flys-artifacts/trunk@4631 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Sat, 09 Jun 2012 13:46:04 +0000
parents 8bd4cf11c25a
children 0b5a7a2c3724
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java
diffstat 4 files changed, 204 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Fri Jun 08 04:53:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Sat Jun 09 13:46:04 2012 +0000
@@ -400,7 +400,9 @@
 
     public double getCurrentKm() {
         //TODO: get the current km.
-        return this.from.doubleValue();
+        //return this.from.doubleValue();
+        //FIXME
+        return 13.37;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Fri Jun 08 04:53:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Sat Jun 09 13:46:04 2012 +0000
@@ -74,7 +74,7 @@
             Function ff = FunctionFactory.getInstance().getFunction(function);
 
             Parameters params = result.getParameters();
-            int row = params.binarySearch("km", km, Math.pow(10, -4));
+            int row = 0; //params.binarySearch("km", km, Math.pow(10, -4)); //FIXME: search failes as access.getCurrentKm() always returns 13.37...
             String[] paramNames = ff.getParameterNames();
             int[] paramInd = params.columnIndices(paramNames);
             double[] coeffs = new double[paramNames.length];
@@ -83,7 +83,7 @@
             de.intevation.flys.artifacts.math.Function mf =
                 ff.instantiate(coeffs);
 
-            double maxQ = getMaxQ(result, km);
+            double maxQ = 100; //getMaxQ(result, km); //FIXME
 
             FixFunction fix = new FixFunction(
                 ff.getName(),
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQChartGenerator.java	Fri Jun 08 04:53:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-package de.intevation.flys.exports.fixings;
-
-import de.intevation.artifactdatabase.state.ArtifactAndFacet;
-import de.intevation.flys.artifacts.model.FacetTypes;
-import de.intevation.flys.exports.ChartGenerator;
-import de.intevation.flys.exports.XYChartGenerator;
-
-import org.apache.log4j.Logger;
-
-import org.w3c.dom.Document;
-
-public class FixWQChartGenerator 
-extends XYChartGenerator 
-implements FacetTypes
-{
-	private static Logger logger =
-		Logger.getLogger(FixWQChartGenerator.class);
-
-	public static final String I18N_CHART_TITLE =
-		"chart.fixings.wq.title";
-
-	public static final String I18N_CHART_SUBTITLE =
-		"chart.fixings.wq.subtitle";
-
-	public static final String I18N_XAXIS_LABEL =
-		"chart.fixings.wq.xaxis.label";
-
-	public static final String I18N_YAXIS_LABEL =
-		"chart.fixings.wq.yaxis.label";
-
-	public static final String I18N_CHART_TITLE_DEFAULT  =
-		"Fixierungsanalyse";
-
-	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 bundle, Document attr, boolean visible) {
-		String name = bundle.getFacetName();
-		logger.debug("FixWQChartGenerator.doOut: " + name);
-	}
-
-	@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();
-			}
-		};
-	}	
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Sat Jun 09 13:46:04 2012 +0000
@@ -0,0 +1,199 @@
+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.WQDay;
+import de.intevation.flys.artifacts.model.fixings.QW;
+import de.intevation.flys.exports.ChartGenerator;
+import de.intevation.flys.exports.XYChartGenerator;
+import de.intevation.flys.jfree.StyledXYSeries;
+
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.data.xy.XYSeries;
+
+import org.w3c.dom.Document;
+
+public class FixWQCurveGenerator 
+extends XYChartGenerator 
+implements FacetTypes
+{
+    private static Logger logger =
+        Logger.getLogger(FixWQChartGenerator.class);
+
+    public static final String I18N_CHART_TITLE =
+        "chart.fixings.wq.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+        "chart.fixings.wq.subtitle";
+
+    public static final String I18N_XAXIS_LABEL =
+        "chart.fixings.wq.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL =
+        "chart.fixings.wq.yaxis.label";
+
+    public static final String I18N_CHART_TITLE_DEFAULT  =
+        "Fixierungsanalyse";
+
+    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 bundle, Document doc, boolean visible) {
+        String name = bundle.getFacetName();
+/*        Object data;
+        try {
+            data = bundle.getData(context);
+        } catch(NullPointerException ex) { // FIXME it's crashing on every edge 
+            logger.error("doOut Exception catched", ex);
+            data = new Object();
+        }*/
+        logger.debug("doOut: " + name);
+        //logger.debug("doOut: data is instanceof " + data.toString());
+        
+        if(FIX_SECTOR_AVERAGE_WQ.equals(name)) {
+            doSectorAverageOut(bundle, doc, visible);
+        } else if(FIX_ANALYSIS_EVENTS_WQ.equals(name)) {
+            doAnalysisEventsOut(bundle, doc, visible);
+        } else if(FIX_ANALYSIS_PERIODS_WQ.equals(name)) {
+            doAnalysisPeriodsOut(bundle, doc, visible);
+        } else if(FIX_REFERENCE_EVENTS_WQ.equals(name)) {
+            doReferenceEventsOut(bundle, doc, visible);
+        } else if(FIX_WQ_CURVE.equals(name)) {
+            doWQOut(new QW(13.37, 42.23, "Unknown point", new Date()), bundle, doc, visible);
+        } else if(FIX_OUTLIER.equals(name)) {
+            doOutlierOut(bundle, doc, visible);
+        } else {
+            logger.warn("Unknown facet name " + name);
+            return;
+        }
+    }
+
+    protected void doSectorAverageOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+       logger.debug("doSectorAverageOut");
+
+       XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+       java.util.Random rand = new java.util.Random(7000);
+       for(int n = 0; n < 10; n++) {
+           series.add(rand.nextDouble(), rand.nextDouble());
+       }
+
+       addAxisSeries(series, 0, visible);
+    }
+
+    protected void doAnalysisEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+       logger.debug("doAnalysisEventsOut");
+
+       XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+       java.util.Random rand = new java.util.Random(4000);
+       for(int n = 0; n < 10; n++) {
+           series.add(rand.nextDouble(), rand.nextDouble());
+       }
+
+       addAxisSeries(series, 0, visible);
+    }
+
+    protected void doAnalysisPeriodsOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+       logger.debug("doAnalysisPeriodsOut");
+
+       XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+       java.util.Random rand = new java.util.Random(5000);
+       for(int n = 0; n < 10; n++) {
+           series.add(rand.nextDouble(), rand.nextDouble());
+       }
+
+       addAxisSeries(series, 0, visible);
+    }
+
+    protected void doReferenceEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+       logger.debug("doReferenceEventsOut");
+
+       XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+       java.util.Random rand = new java.util.Random(3000);
+       for(int n = 0; n < 10; n++) {
+           series.add(rand.nextDouble(), rand.nextDouble());
+       }
+
+       addAxisSeries(series, 0, visible);
+    }
+
+    protected void doWQOut(
+        QW            wqdays,
+        ArtifactAndFacet aaf,
+        Document         theme,
+        boolean          visible
+    ) {
+        logger.debug("doWQOut");
+
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
+        java.util.Random rand = new java.util.Random(1000);
+        int size = 10; //wqdays.size();
+        for (int i = 0; i < size; i++) {
+            //int  day = wqdays.getDate(i);
+            //double q = wqdays.getQ(i);
+
+            series.add(rand.nextDouble(), rand.nextDouble());
+        }
+
+        addAxisSeries(series, 0, visible);
+    }
+
+    protected void doOutlierOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+        logger.debug("doOutlierOut");
+
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+        java.util.Random rand = new java.util.Random(2000);
+        for(int n = 0; n < 10; n++) {
+            series.add(rand.nextDouble(), rand.nextDouble());
+        }
+
+        addAxisSeries(series,0, visible);
+    }
+
+    @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