Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java @ 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 | 6fb211753674 |
children | ec9aab93f292 |
line wrap: on
line diff
--- 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 :