changeset 3062:7660cfe5e8f6

FixWQCurveGenerator can generate charts from Fix*-Facets (in theory and not complete) flys-artifacts/trunk@4642 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Tue, 12 Jun 2012 12:40:44 +0000
parents 49baebb39305
children 33c167d6fff6
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.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 9 files changed, 117 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 12 12:40:44 2012 +0000
@@ -1,3 +1,22 @@
+2012-06-12	Christian Lins	<christian.lins@intevation.de>
+
+	* doc/conf/conf.xml:
+	  Add fix_wq_curve output generator.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java:
+	  Add additional null-checks to prevent NullPointerExceptions when accessing empty
+	  facets.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java:
+	  getMaxQ() now returns constant '1000' until it is properly fixed.
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java:
+	  Code for generating charts more or less complete but untested due to bugs in facets.
+
 2012-06-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/Parameters.java:
--- a/flys-artifacts/doc/conf/conf.xml	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Tue Jun 12 12:40:44 2012 +0000
@@ -219,6 +219,7 @@
         <output-generator name="discharge_longitudinal_section">de.intevation.flys.exports.DischargeLongitudinalSectionGenerator</output-generator>
         <output-generator name="discharge_longitudinal_section_chartinfo">de.intevation.flys.exports.DischargeLongitudinalSectionInfoGenerator</output-generator>
         <output-generator name="waterlevel_export">de.intevation.flys.exports.WaterlevelExporter</output-generator>
+        <output-generator name="fix_wq_curve">de.intevation.flys.exports.fixings.FixWQCurveGenerator</output-generator>
         <output-generator name="durationcurve_export">de.intevation.flys.exports.DurationCurveExporter</output-generator>
         <output-generator name="computed_dischargecurve_export">de.intevation.flys.exports.ComputedDischargeCurveExporter</output-generator>
         <output-generator name="discharge_longitudinal_section_export">de.intevation.flys.exports.DischargeLongitudinalSectionExporter</output-generator>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Tue Jun 12 12:40:44 2012 +0000
@@ -73,8 +73,14 @@
             double km = access.getCurrentKm();
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
-            AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue();
+            KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = 
+                kmPeriods.binarySearch(km);
 
+            if(kmPeriodsEntry == null) {
+                return null;
+            }
+
+            AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
             if (periods == null) {
                 return null;
             }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Tue Jun 12 12:40:44 2012 +0000
@@ -73,7 +73,14 @@
             double km = access.getCurrentKm();
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
-            AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue();
+            KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = 
+                kmPeriods.binarySearch(km);
+
+            if (kmPeriodsEntry == null) {
+                return null;
+            }
+
+            AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
 
             if (periods == null) {
                 return null;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Tue Jun 12 12:40:44 2012 +0000
@@ -71,7 +71,14 @@
             double km = access.getCurrentKm();
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
-            AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue();
+            KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
+                kmPeriods.binarySearch(km);
+
+            if (kmPeriodsEntry == null) {
+                return null;
+            }
+
+            AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
 
             if (periods == null) {
                 return null;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Tue Jun 12 12:40:44 2012 +0000
@@ -68,9 +68,10 @@
             double km = access.getCurrentKm();
             KMIndex<QW []> kmQWs = result.getOutliers();
 
-            QW[] qws = kmQWs.binarySearch(km).getValue();
-            if (qws == null) {
-                return null;
+            KMIndex.Entry<QW []> qwsEntry = kmQWs.binarySearch(km);
+            QW[] qws = null;
+            if(qwsEntry != null) {
+                qws = qwsEntry.getValue();
             }
             return qws;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Tue Jun 12 12:40:44 2012 +0000
@@ -72,10 +72,10 @@
 
             double km = access.getCurrentKm();
             KMIndex<QW []> kmQWs = result.getReferenced();
-
-            QW[] qws = kmQWs.binarySearch(km).getValue();
-            if (qws == null) {
-                return null;
+            KMIndex.Entry<QW []> kmQWsEntry = kmQWs.binarySearch(km);
+            QW[] qws = null;
+            if (kmQWsEntry != null) {
+                qws = kmQWsEntry.getValue();
             }
             return qws;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Tue Jun 12 12:40:44 2012 +0000
@@ -148,7 +148,8 @@
         } else {
             logger.debug("getMaxQ: periodsEntry is null, that's odd...");
         }
-        return maxQ;
+        //return maxQ;
+        return 1000; //FIXME replace by parameters.interpolate("q_max")...
     }
 
     /**
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Tue Jun 12 08:11:36 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Tue Jun 12 12:40:44 2012 +0000
@@ -4,15 +4,22 @@
 
 import de.intevation.flys.artifacts.model.FacetTypes;
 
+import de.intevation.flys.artifacts.model.fixings.DateRange;
 import de.intevation.flys.artifacts.model.fixings.FixFunction;
+import de.intevation.flys.artifacts.model.fixings.QW;
+import de.intevation.flys.artifacts.model.fixings.QWD;
 
 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.chart.JFreeChart;
+import org.jfree.chart.plot.ValueMarker;
+import org.jfree.data.general.DatasetUtilities;
 import org.jfree.data.xy.XYSeries;
 
 import org.w3c.dom.Document;
@@ -61,93 +68,104 @@
 
         if(FIX_SECTOR_AVERAGE_WQ.equals(name)) {
             doSectorAverageOut(aaf, doc, visible);
-        } else if(FIX_ANALYSIS_EVENTS_WQ.equals(name)) {
+        }
+        else if(FIX_ANALYSIS_EVENTS_WQ.equals(name)) {
             doAnalysisEventsOut(aaf, doc, visible);
-        } else if(FIX_ANALYSIS_PERIODS_WQ.equals(name)) {
+        }
+        else if(FIX_ANALYSIS_PERIODS_WQ.equals(name)) {
             doAnalysisPeriodsOut(aaf, doc, visible);
-        } else if(FIX_REFERENCE_EVENTS_WQ.equals(name)) {
+        }
+        else if(FIX_REFERENCE_EVENTS_WQ.equals(name)) {
             doReferenceEventsOut(aaf, doc, visible);
-        } else if(FIX_WQ_CURVE.equals(name)) {
+        }
+        else if(FIX_WQ_CURVE.equals(name)) {
             doWQCurveOut(aaf, doc, visible);
-        } else if(FIX_OUTLIER.equals(name)) {
+        }
+        else if(FIX_OUTLIER.equals(name)) {
             doOutlierOut(aaf, doc, visible);
-        } else {
+        }
+        else {
             logger.warn("Unknown facet name " + name);
             return;
         }
     }
 
     protected void doSectorAverageOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
-       logger.debug("doSectorAverageOut");
+        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);
+        QWD[] qwds = (QWD[])aaf.getData(context);
+       
+        if(qwds != null) {
+            // Draw vertical markers
+            JFreeChart chart = generateChart();
+            for(QWD qwd : qwds) {
+                chart.getXYPlot().addDomainMarker(new ValueMarker(qwd.getQ()));
+            }
+        }
     }
 
     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());
-       }
+       QWD[] qwds = (QWD[])aaf.getData(context);
+       if(qwds != null) {
+            XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+            for(QW qw : qwds) {
+                series.add(qw.getQ(), qw.getW());
+            }
 
-       addAxisSeries(series, 0, visible);
+            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);
+       DateRange[] dateRanges = (DateRange[])aaf.getData(context);
+       //TODO What to do with Date ranges?    
     }
 
     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);
+       QW[] qws = (QW[])aaf.getData(context);
+       addQWSeries(qws, aaf, doc, visible);
     }
 
     protected void doWQCurveOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
         logger.debug("doWQCurveOut");
 
         FixFunction func = (FixFunction)aaf.getData(context);
-
-        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
-        for (int q = 0; q <= func.getMaxQ(); q += 1.0) {
-            series.add(q, func.getFunction().value(q));
+        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);
         }
-
-        addAxisSeries(series, 0, visible);
+        else {
+            logger.warn("doWQCurveOut: func.getMaxQ() returns 0");
+        }
     }
 
     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());
+        QW[] qws = (QW[])aaf.getData(context);
+        addQWSeries(qws, aaf, doc, visible);
+    }
+
+    protected void addQWSeries(QW[] qws, ArtifactAndFacet aaf, Document doc, boolean visible) {
+         if(qws != null) {
+            XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+            for(QW qw : qws) {
+                series.add(qw.getQ(), qw.getW());
+            }
+
+            addAxisSeries(series, 0, visible);
         }
-
-        addAxisSeries(series,0, visible);
     }
 
     @Override

http://dive4elements.wald.intevation.org