Mercurial > dive4elements > river
changeset 3079:8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
flys-artifacts/trunk@4675 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 15 Jun 2012 12:23:08 +0000 (2012-06-15) |
parents | 0e0efd1acb4f |
children | dc2765e31e1f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQ.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/sq/SQRelationGenerator.java |
diffstat | 8 files changed, 278 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Jun 15 12:16:49 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Jun 15 12:23:08 2012 +0000 @@ -1,3 +1,29 @@ +2012-06-15 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/sq/SQ.java: New model to + store values for S/Q. + + * src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java: New + model class that should be used to store calculation results of SQ + relation. + + * src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java: + Create a fake SQResult. + + * src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java: + Set missing required properties, so that this facet will be able to + re-calculate results again if the results are not in cache. + + * src/main/java/de/intevation/flys/artifacts/states/SQRelation.java: + Create correct number of facets for parameter A for outliers Facet. + + * src/main/java/de/intevation/flys/exports/sq/SQRelationGenerator.java: + Create a JFreeChart XYSeries from SQResult's outliers Facet. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Added a + method to create X axes. The SQRelationGenerator overrides this method, + because it requires a logarithmic axis. + 2012-06-15 Raimund Renkert <raimund.renkert@intevation.de> * src/main/java/de/intevation/flys/exports/ChartGenerator.java:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQ.java Fri Jun 15 12:23:08 2012 +0000 @@ -0,0 +1,37 @@ +package de.intevation.flys.artifacts.model.sq; + +import java.io.Serializable; + + +public class SQ implements Serializable { + + protected double s; + protected double q; + + public SQ() { + } + + public SQ(double s, double q) { + this.s = s; + this.q = q; + } + + + public double getS() { + return s; + } + + public void setS(double s) { + this.s = s; + } + + + public double getQ() { + return q; + } + + public void setQ(double q) { + this.q = q; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java Fri Jun 15 12:16:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQOutlierFacet.java Fri Jun 15 12:23:08 2012 +0000 @@ -6,8 +6,10 @@ import de.intevation.artifacts.CallContext; +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -22,19 +24,39 @@ private static final Logger log = Logger.getLogger(SQOutlierFacet.class); + private int iteration; + + public SQOutlierFacet() { } - public SQOutlierFacet(int idx, String name, String description) { - super(idx, name, description, ComputeType.ADVANCE, null, null); + public SQOutlierFacet( + int idx, + int iteration, + String name, + String description, + String hash, + String stateId + ) { + super(idx, name, description, ComputeType.ADVANCE, hash, stateId); } @Override public Object getData(Artifact artifact, CallContext context) { log.debug("SQOutlierFacet.getData"); - log.error("NOT IMPLEMENTED!"); + + if (artifact instanceof FLYSArtifact) { + FLYSArtifact flys = (FLYSArtifact) artifact; + + CalculationResult res = (CalculationResult) flys.compute( + context, ComputeType.ADVANCE, false); + + SQResult[] result = (SQResult[]) res.getData(); + + return result[index].getOutliers(iteration); + } return null; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java Fri Jun 15 12:16:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java Fri Jun 15 12:23:08 2012 +0000 @@ -1,5 +1,8 @@ package de.intevation.flys.artifacts.model.sq; +import java.util.ArrayList; +import java.util.List; + import org.apache.log4j.Logger; import de.intevation.flys.artifacts.model.Calculation; @@ -27,10 +30,70 @@ // TODO Insert input params here ) { logger.info("SQRelationCalculation.buildCalculationResult"); - logger.error("Not implemented!"); - return new CalculationResult(new Object[0], this); + SQResult[] result = getFakeResult(); + + return new CalculationResult(result, this); + } + + + protected SQResult[] getFakeResult() { + + SQ[] measurements = getFakeMeasurements(); + SQ[] fOutliers = getFakeOutliers(10); + SQ[] tOutliers = getFakeOutliers(20); + + List<SQ[]> outliers = new ArrayList<SQ[]>(); + outliers.add(fOutliers); + outliers.add(tOutliers); + + return new SQResult[] { new SQResult(null, measurements, outliers) }; + } + + protected SQ[] getFakeMeasurements() { + List<SQ> a = new ArrayList<SQ>(); + + a.add(new SQ(11.172500000000001, 1250.0)); + a.add(new SQ(13.407000000000002, 1500.0)); + a.add(new SQ(15.641500000000002, 1750.0)); + a.add(new SQ(17.876000000000005, 2000.0)); + a.add(new SQ(20.110500000000005, 2250.0)); + a.add(new SQ(22.345000000000002, 2500.0)); + a.add(new SQ(24.579500000000003, 2750.0)); + a.add(new SQ(26.814000000000004, 3000.0)); + a.add(new SQ(29.048500000000004, 3250.0)); + a.add(new SQ(31.283000000000005, 3500.0)); + a.add(new SQ(33.517500000000005, 3750.0)); + a.add(new SQ(35.75200000000001, 4000.0)); + a.add(new SQ(37.98650000000001, 4250.0)); + a.add(new SQ(40.22100000000001, 4500.0)); + a.add(new SQ(42.45550000000001, 4750.0)); + + return (SQ[]) a.toArray(new SQ[a.size()]); + } + + + protected SQ[] getFakeOutliers(int diff) { + List<SQ> a = new ArrayList<SQ>(); + + a.add(new SQ(11.172500000000001-diff, 1250.0)); + a.add(new SQ(13.407000000000002+diff, 1500.0)); + a.add(new SQ(25.641500000000002-diff, 1750.0)); + a.add(new SQ(17.876000000000005+diff, 2000.0)); + a.add(new SQ(20.110500000000005-diff, 2250.0)); + a.add(new SQ(22.345000000000002+diff, 2500.0)); + a.add(new SQ(24.579500000000003-diff, 2750.0)); + a.add(new SQ(26.814000000000004+diff, 3000.0)); + a.add(new SQ(29.048500000000004-diff, 3250.0)); + a.add(new SQ(31.283000000000005+diff, 3500.0)); + a.add(new SQ(33.517500000000005-diff, 3750.0)); + a.add(new SQ(35.75200000000001-diff, 4000.0)); + a.add(new SQ(37.98650000000001+diff, 4250.0)); + a.add(new SQ(40.22100000000001+diff, 4500.0)); + a.add(new SQ(42.45550000000001+diff, 4750.0)); + + return (SQ[]) a.toArray(new SQ[a.size()]); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQResult.java Fri Jun 15 12:23:08 2012 +0000 @@ -0,0 +1,78 @@ +package de.intevation.flys.artifacts.model.sq; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import de.intevation.flys.artifacts.model.Parameters; + + +public class SQResult implements Serializable { + + protected Parameters parameters; + + protected SQ[] measurements; + protected List<SQ[]> outliers; + + + public SQResult() { + this.outliers = new ArrayList<SQ[]>(); + } + + + public SQResult( + Parameters parameters, + SQ[] measurements, + List<SQ[]> outliers + ) { + this.parameters = parameters; + this.measurements = measurements; + this.outliers = outliers; + } + + + public Parameters getParameters() { + return parameters; + } + + public void setParameters(Parameters parameters) { + this.parameters = parameters; + } + + + public SQ[] getMeasurements() { + return measurements; + } + + public void setMeasurements(SQ[] measurements) { + this.measurements = measurements; + } + + + public List<SQ[]> getOutliers() { + return outliers; + } + + public void setOutliers(List<SQ[]> outliers) { + this.outliers = outliers; + } + + + public int getOutliersCount() { + return outliers.size(); + } + + + public SQ[] getOutliers(int idx) { + if (idx < outliers.size()) { + return outliers.get(idx); + } + + return null; + } + + public void addOutliers(SQ[] outliers) { + this.outliers.add(outliers); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java Fri Jun 15 12:16:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java Fri Jun 15 12:23:08 2012 +0000 @@ -18,6 +18,7 @@ import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet; import de.intevation.flys.artifacts.model.sq.SQOutlierFacet; import de.intevation.flys.artifacts.model.sq.SQRelationCalculation; +import de.intevation.flys.artifacts.model.sq.SQResult; import de.intevation.flys.artifacts.states.DefaultState; /** @@ -52,12 +53,8 @@ return res; } - logger.error("Facet creation NOT IMPLEMENTED!"); - // TODO - //for (int idx = 0; idx < res.length; idx++) { - int idx = 0; - createFacets(newFacets, idx); - //} + SQResult[] sqr = (SQResult[]) res.getData(); + createFacets(newFacets, sqr, hash); Facet csv = new DataFacet( CSV, "CSV data", ComputeType.ADVANCE, hash, id); @@ -76,56 +73,25 @@ } - protected void createFacets(List<Facet> container, int idx) { + protected void createFacets( + List<Facet> container, + SQResult[] sqr, + String hash + ) { // TODO Create facets for each parameter type (A-F) - Facet measurements, outliers, curve; - measurements = new SQMeasurementFacet(idx, SQ_A_MEASUREMENT, "TODO"); - outliers = new SQOutlierFacet(idx, SQ_A_OUTLIER, "TODO"); - curve = new SQCurveFacet(idx, SQ_A_CURVE, "TODO"); - - container.add(measurements); - container.add(outliers); - container.add(curve); - - measurements = new SQMeasurementFacet(idx, SQ_B_MEASUREMENT, "TODO"); - outliers = new SQOutlierFacet(idx, SQ_B_OUTLIER, "TODO"); - curve = new SQCurveFacet(idx, SQ_B_CURVE, "TODO"); - - container.add(measurements); - container.add(outliers); - container.add(curve); - - measurements = new SQMeasurementFacet(idx, SQ_C_MEASUREMENT, "TODO"); - outliers = new SQOutlierFacet(idx, SQ_C_OUTLIER, "TODO"); - curve = new SQCurveFacet(idx, SQ_C_CURVE, "TODO"); + container.add(new SQMeasurementFacet(0, SQ_A_MEASUREMENT, "TODO")); + container.add(new SQCurveFacet(0, SQ_A_CURVE, "TODO")); - container.add(measurements); - container.add(outliers); - container.add(curve); - - measurements = new SQMeasurementFacet(idx, SQ_D_MEASUREMENT, "TODO"); - outliers = new SQOutlierFacet(idx, SQ_D_OUTLIER, "TODO"); - curve = new SQCurveFacet(idx, SQ_D_CURVE, "TODO"); - - container.add(measurements); - container.add(outliers); - container.add(curve); - - measurements = new SQMeasurementFacet(idx, SQ_E_MEASUREMENT, "TODO"); - outliers = new SQOutlierFacet(idx, SQ_E_OUTLIER, "TODO"); - curve = new SQCurveFacet(idx, SQ_E_CURVE, "TODO"); - - container.add(measurements); - container.add(outliers); - container.add(curve); - - measurements = new SQMeasurementFacet(idx, SQ_F_MEASUREMENT, "TODO"); - outliers = new SQOutlierFacet(idx, SQ_F_OUTLIER, "TODO"); - curve = new SQCurveFacet(idx, SQ_F_CURVE, "TODO"); - - container.add(measurements); - container.add(outliers); - container.add(curve); + for (int i = 0; i < sqr[0].getOutliersCount(); i++) { + container.add(new SQOutlierFacet( + 0, + i, + SQ_A_OUTLIER, + "OUTLIER AT" + i, + getID(), + hash + )); + } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Jun 15 12:16:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Jun 15 12:23:08 2012 +0000 @@ -227,6 +227,8 @@ false); XYPlot plot = (XYPlot) chart.getPlot(); + plot.setDomainAxis(createXAxis(getXAxisLabel())); + chart.setBackgroundPaint(Color.WHITE); plot.setBackgroundPaint(Color.WHITE); addSubtitles(chart); @@ -258,6 +260,11 @@ } + protected NumberAxis createXAxis(String label) { + return new NumberAxis(label); + } + + @Override protected Series getSeriesOf(XYDataset dataset, int idx) { return ((XYSeriesCollection) dataset).getSeries(idx);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/sq/SQRelationGenerator.java Fri Jun 15 12:16:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/sq/SQRelationGenerator.java Fri Jun 15 12:23:08 2012 +0000 @@ -4,6 +4,7 @@ import org.jfree.chart.axis.LogarithmicAxis; import org.jfree.chart.axis.NumberAxis; +import org.jfree.data.xy.XYSeries; import org.w3c.dom.Document; @@ -11,7 +12,9 @@ import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.sq.SQ; import de.intevation.flys.exports.XYChartGenerator; +import de.intevation.flys.jfree.StyledXYSeries; /** * An OutGenerator that generates charts for MINFO sq relation. @@ -70,6 +73,12 @@ @Override + protected NumberAxis createXAxis(String label) { + return new LogarithmicAxis(label); + } + + + @Override protected NumberAxis createYAxis(int index) { return new LogarithmicAxis("TODO: LABEL " + index); } @@ -129,7 +138,16 @@ boolean visible ) { logger.debug("doSQOutliersOut"); - logger.error("NOT IMPLEMENTED: doSQOutliersOut"); + + Facet f = artifactAndFacet.getFacet(); + SQ[] sqs = (SQ[]) artifactAndFacet.getData(context); + XYSeries series = new StyledXYSeries(f.getDescription(), attr); + + for (SQ sq: sqs) { + series.add(sq.getQ(), sq.getS()); + } + + addAxisSeries(series, YAXIS.S.idx, visible); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :