# HG changeset patch # User Christian Lins # Date 1339504844 0 # Node ID 7660cfe5e8f6fe703fb8b694753fb3fad5ac31aa # Parent 49baebb3930574817d8688aeaadcb7e119ca6e59 FixWQCurveGenerator can generate charts from Fix*-Facets (in theory and not complete) flys-artifacts/trunk@4642 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/model/Parameters.java: diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/doc/conf/conf.xml --- 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 @@ de.intevation.flys.exports.DischargeLongitudinalSectionGenerator de.intevation.flys.exports.DischargeLongitudinalSectionInfoGenerator de.intevation.flys.exports.WaterlevelExporter + de.intevation.flys.exports.fixings.FixWQCurveGenerator de.intevation.flys.exports.DurationCurveExporter de.intevation.flys.exports.ComputedDischargeCurveExporter de.intevation.flys.exports.DischargeLongitudinalSectionExporter diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java --- 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 kmPeriods = result.getAnalysisPeriods(); - AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue(); + KMIndex.Entry kmPeriodsEntry = + kmPeriods.binarySearch(km); + if(kmPeriodsEntry == null) { + return null; + } + + AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); if (periods == null) { return null; } diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java --- 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 kmPeriods = result.getAnalysisPeriods(); - AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue(); + KMIndex.Entry kmPeriodsEntry = + kmPeriods.binarySearch(km); + + if (kmPeriodsEntry == null) { + return null; + } + + AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); if (periods == null) { return null; diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/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 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 kmPeriods = result.getAnalysisPeriods(); - AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue(); + KMIndex.Entry kmPeriodsEntry = + kmPeriods.binarySearch(km); + + if (kmPeriodsEntry == null) { + return null; + } + + AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); if (periods == null) { return null; diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java --- 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 kmQWs = result.getOutliers(); - QW[] qws = kmQWs.binarySearch(km).getValue(); - if (qws == null) { - return null; + KMIndex.Entry qwsEntry = kmQWs.binarySearch(km); + QW[] qws = null; + if(qwsEntry != null) { + qws = qwsEntry.getValue(); } return qws; } diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java --- 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 kmQWs = result.getReferenced(); - - QW[] qws = kmQWs.binarySearch(km).getValue(); - if (qws == null) { - return null; + KMIndex.Entry kmQWsEntry = kmQWs.binarySearch(km); + QW[] qws = null; + if (kmQWsEntry != null) { + qws = kmQWsEntry.getValue(); } return qws; } diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java --- 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")... } /** diff -r 49baebb39305 -r 7660cfe5e8f6 flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java --- 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