Mercurial > dive4elements > river
changeset 3222:116b342893e3
SQ: Connect calculation with artifact parameter access.
flys-artifacts/trunk@4845 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 01 Jul 2012 18:00:04 +0000 |
parents | 06ae0258269b |
children | 282c9da923ab |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java |
diffstat | 3 files changed, 87 insertions(+), 160 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Sun Jul 01 12:43:20 2012 +0000 +++ b/flys-artifacts/ChangeLog Sun Jul 01 18:00:04 2012 +0000 @@ -1,3 +1,11 @@ +2012-07-02 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/SQRelation.java: + Made it more symmetrical to FixationCompute. + + * src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java: + Removed fake result stuff. Fetch parameters from SQRelationAccess. + 2012-07-01 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java Sun Jul 01 12:43:20 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java Sun Jul 01 18:00:04 2012 +0000 @@ -1,156 +1,74 @@ 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.access.SQRelationAccess; import de.intevation.flys.artifacts.model.Calculation; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.Parameters; +import de.intevation.flys.artifacts.model.DateRange; -import de.intevation.flys.artifacts.MINFOArtifact; - +import org.apache.log4j.Logger; public class SQRelationCalculation extends Calculation { - private static final Logger logger = + private static final Logger log = Logger.getLogger(SQRelationCalculation.class); - - public CalculationResult calculate(MINFOArtifact artifact) { - logger.info("SQRelationCalculation.calculate"); - - // TODO Collect input params and use them for buildCalculationResult() - - return buildCalculationResult(); - } + protected String river; + protected double location; + protected DateRange [] periods; + protected double outliers; - - protected CalculationResult buildCalculationResult( - // TODO Insert input params here - ) { - logger.info("SQRelationCalculation.buildCalculationResult"); - logger.error("Not implemented!"); - - SQResult[] result = getFakeResult(); - - return new CalculationResult(result, this); + public SQRelationCalculation() { } - - protected SQResult[] getFakeResult() { - - Parameters params = getFakeParameters(); - SQ[] measurements = getFakeMeasurements(); - SQ[] fOutliers = getFakeOutliers(10); - SQ[] tOutliers = getFakeOutliers(20); - - List<SQ[]> outliers = new ArrayList<SQ[]>(); - outliers.add(fOutliers); - outliers.add(tOutliers); + public SQRelationCalculation(SQRelationAccess access) { - SQResult res = new SQResult(); - - res.setFraction( - SQResult.FRACTION_A, - new SQFractionResult(params, measurements, outliers)); + String river = access.getRiver(); + Double location = access.getLocation(); + DateRange [] periods = access.getPeriods(); + Double outliers = access.getOutliers(); - res.setFraction( - SQResult.FRACTION_B, - new SQFractionResult(params, measurements, outliers)); + if (river == null) { + // TODO: i18n + addProblem("sq.missing.river"); + } - res.setFraction( - SQResult.FRACTION_C, - new SQFractionResult(params, measurements, outliers)); + if (location == null) { + // TODO: i18n + addProblem("sq.missing.location"); + } - return new SQResult[] { res }; + if (periods == null) { + // TODO: i18n + addProblem("sq.missing.periods"); + } + + if (outliers == null) { + // TODO: i18n + addProblem("sq.missing.outliers"); + } + + if (!hasProblems()) { + this.river = river; + this.location = location; + this.periods = periods; + this.outliers = outliers; + } } - protected Parameters getFakeParameters() { - Parameters params = new Parameters(new String[] { - "a", - "b" - }); - - params.set(0, 0, 0.0082); - params.set(0, 1, 1.09); - - return params; - } - - - 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>(); + public CalculationResult calculate() { + log.debug("SQRelationCalculation.calculate"); - double[][] values = new double[15][2]; - - values[0][0] = 11.172500000000001-diff; - values[0][1] = 1250.0; - values[1][0] = 13.407000000000002+diff; - values[1][1] = 1500.0; - values[2][0] = 25.641500000000002-diff; - values[2][1] = 1750.0; - values[3][0] = 17.876000000000005+diff; - values[3][1] = 2000.0; - values[4][0] = 20.110500000000005-diff; - values[4][1] = 2250.0; - values[5][0] = 22.345000000000002+diff; - values[5][1] = 2500.0; - values[6][0] = 24.579500000000003-diff; - values[6][1] = 2750.0; - values[7][0] = 26.814000000000004+diff; - values[7][1] = 3000.0; - values[8][0] = 29.048500000000004-diff; - values[8][1] = 3250.0; - values[9][0] = 31.283000000000005+diff; - values[9][1] = 3500.0; - values[10][0] = 33.517500000000005-diff; - values[10][1] = 3750.0; - values[11][0] = 35.75200000000001-diff; - values[11][1] = 4000.0; - values[12][0] = 37.98650000000001+diff; - values[12][1] = 4250.0; - values[13][0] = 40.22100000000001+diff; - values[13][1] = 4500.0; - values[14][0] = 42.45550000000001+diff; - values[14][1] = 4750.0; - - for (double[] value: values) { - double s = value[0]; - double q = value[1]; - - s = s > 0 ? s : s * -1; - q = q > 0 ? q : q * -1; - - a.add(new SQ(s, q)); + if (hasProblems()) { + return new CalculationResult(this); } - return (SQ[]) a.toArray(new SQ[a.size()]); + SQResult [] result = null; + + // TODO: Implement me! + + return new CalculationResult(result, this); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java Sun Jul 01 12:43:20 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java Sun Jul 01 18:00:04 2012 +0000 @@ -1,35 +1,39 @@ package de.intevation.flys.artifacts.states; -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; +import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; -import de.intevation.artifactdatabase.state.Facet; +import de.intevation.flys.artifacts.FLYSArtifact; -import de.intevation.flys.artifacts.FLYSArtifact; -import de.intevation.flys.artifacts.MINFOArtifact; +import de.intevation.flys.artifacts.access.SQRelationAccess; + +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.CalculationResult; + import de.intevation.flys.artifacts.model.sq.SQCurveFacet; import de.intevation.flys.artifacts.model.sq.SQFractionResult; 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.resources.Resources; + import de.intevation.flys.artifacts.states.DefaultState; +import java.util.List; + +import org.apache.log4j.Logger; + /** * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ public class SQRelation extends DefaultState implements FacetTypes { - private static Logger logger = Logger.getLogger(SQRelation.class); + private static Logger log = Logger.getLogger(SQRelation.class); public static final String I18N_FACET_CURVE = @@ -54,22 +58,23 @@ List<Facet> facets, Object old ) { - logger.debug("SQRelation.computeAdvance"); - - List<Facet> newFacets = new ArrayList<Facet>(); + log.debug("SQRelation.computeAdvance"); CalculationResult res = old instanceof CalculationResult - ? (CalculationResult) old - : new SQRelationCalculation().calculate((MINFOArtifact) artifact); + ? (CalculationResult)old + : new SQRelationCalculation( + new SQRelationAccess(artifact)).calculate(); - if (facets == null || res == null) { + if (facets == null) { return res; } - SQResult[] sqr = (SQResult[]) res.getData(); - logger.info("Calculation computed " + sqr.length + " SQResult objects"); + SQResult [] sqr = (SQResult [])res.getData(); + if (sqr == null) { + return res; + } - createFacets(context, newFacets, sqr, hash); + createFacets(context, facets, sqr, hash); Facet csv = new DataFacet( CSV, "CSV data", ComputeType.ADVANCE, hash, id); @@ -77,12 +82,8 @@ Facet pdf = new DataFacet( PDF, "PDF data", ComputeType.ADVANCE, hash, id); - newFacets.add(csv); - newFacets.add(pdf); - - logger.debug("Created " + newFacets.size() + " new Facets."); - - facets.addAll(newFacets); + facets.add(csv); + facets.add(pdf); return res; } @@ -103,7 +104,7 @@ SQFractionResult result = sqr[res].getFraction(i); if (result == null) { - logger.warn("Fraction at index " + i + " is empty!"); + log.warn("Fraction at index " + i + " is empty!"); continue; } @@ -138,11 +139,11 @@ index = index << 16; index = index + j; - if (logger.isDebugEnabled()) { - logger.debug("new outliers facet (index=" +index+ ")"); - logger.debug(" result index = " + res); - logger.debug(" fraction idx = " + i); - logger.debug(" iteration = " + j); + if (log.isDebugEnabled()) { + log.debug("new outliers facet (index=" +index+ ")"); + log.debug(" result index = " + res); + log.debug(" fraction idx = " + i); + log.debug(" iteration = " + j); } container.add(new SQOutlierFacet( @@ -165,7 +166,7 @@ protected String getFractionFacetname(int type, int fractionIdx) { - logger.debug("getFractionFacetname(): " + type + " | " + fractionIdx); + log.debug("getFractionFacetname(): " + type + " | " + fractionIdx); switch (type) { case 0: