Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java @ 3426:e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
flys-artifacts/trunk@5082 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 20 Jul 2012 09:34:47 +0000 |
parents | 56f62b5209f5 |
children | 1df6984628c3 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java Fri Jul 20 07:50:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java Fri Jul 20 09:34:47 2012 +0000 @@ -12,7 +12,6 @@ import de.intevation.flys.backend.SedDBSessionHolder; -import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; @@ -24,20 +23,20 @@ public static final String SQ_FUNCTION_NAME = "sq-pow"; - protected String river; - protected double location; - protected DateRange [] periods; - protected double outliers; + protected String river; + protected double location; + protected DateRange period; + protected double outliers; public SQRelationCalculation() { } public SQRelationCalculation(SQRelationAccess access) { - String river = access.getRiver(); - Double location = access.getLocation(); - DateRange [] periods = access.getPeriods(); - Double outliers = access.getOutliers(); + String river = access.getRiver(); + Double location = access.getLocation(); + DateRange period = access.getPeriod(); + Double outliers = access.getOutliers(); //river = "Rhein"; @@ -51,7 +50,7 @@ addProblem("sq.missing.location"); } - if (periods == null || periods.length == 0) { + if (period == null) { // TODO: i18n addProblem("sq.missing.periods"); } @@ -64,7 +63,7 @@ if (!hasProblems()) { this.river = river; this.location = location; - this.periods = periods; + this.period = period; this.outliers = outliers; } } @@ -103,56 +102,45 @@ String [] parameterNames = function.getParameterNames(); - List<SQResult> results = new ArrayList<SQResult>(periods.length); - Fitting fitting = new Fitting(function, outliers); - for (DateRange period: periods) { Measurements measurements = MeasurementFactory.getMeasurements(river, location, period); - /* - if (debug) { - log.debug(measurements.toString()); - } - */ - - SQFractionResult [] fractionResults = - new SQFractionResult[SQResult.NUMBER_FRACTIONS]; + SQFractionResult [] fractionResults = + new SQFractionResult[SQResult.NUMBER_FRACTIONS]; - for (int i = 0; i < fractionResults.length; ++i) { - List<SQ> sqs = measurements.getSQs(i); + for (int i = 0; i < fractionResults.length; ++i) { + List<SQ> sqs = measurements.getSQs(i); - SQFractionResult fractionResult; + SQFractionResult fractionResult; - if (!fitting.fit(sqs)) { - // TODO: i18n - addProblem("sq.fitting.failed." + i); - fractionResult = new SQFractionResult(); + if (!fitting.fit(sqs)) { + // TODO: i18n + addProblem("sq.fitting.failed." + i); + fractionResult = new SQFractionResult(); + } + else { + Parameters parameters = createParameters(parameterNames); + int row = parameters.newRow(); + double [] coeffs = fitting.getParameters(); + for (int j = 0; j < parameterNames.length; ++j) { + parameters.set(row, parameterNames[j], coeffs[j]); } - else { - Parameters parameters = createParameters(parameterNames); - int row = parameters.newRow(); - double [] coeffs = fitting.getParameters(); - for (int j = 0; j < parameterNames.length; ++j) { - parameters.set(row, parameterNames[j], coeffs[j]); - } - parameters.set(row, "chi_sqr", fitting.getChiSqr()); - parameters.set(row, "std_dev", fitting.getStandardDeviation()); + parameters.set(row, "chi_sqr", fitting.getChiSqr()); + parameters.set(row, "std_dev", fitting.getStandardDeviation()); - fractionResult = new SQFractionResult( - parameters, - fitting.getRemaining(), - fitting.getOutliers()); - } - fitting.reset(); - fractionResults[i] = fractionResult; + fractionResult = new SQFractionResult( + parameters, + fitting.getRemaining(), + fitting.getOutliers()); } - results.add(new SQResult(location, fractionResults)); + fitting.reset(); + fractionResults[i] = fractionResult; } return new CalculationResult( - results.toArray(new SQResult[results.size()]), + new SQResult[] { new SQResult(location, fractionResults) }, this); }