# HG changeset patch # User Ingo Weinzierl # Date 1328103238 0 # Node ID 4b6e9b377a84757e04e0ad5a9f1548d71a800a77 # Parent 39933df6d0fe360763262b57c82f948d06ce44ef Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters. flys-artifacts/trunk@3858 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 39933df6d0fe -r 4b6e9b377a84 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Feb 01 13:32:10 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Feb 01 13:33:58 2012 +0000 @@ -1,3 +1,13 @@ +2012-02-01 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Fetch + necessary parameters for 'historical discharge curve' calculation and call + Calculation6 with those parameters. + + * src/main/java/de/intevation/flys/artifacts/model/Calculation6.java: + Modified default constructor and calculate() signatures and added a + parameter check which is evaluated before the calculation starts. + 2012-02-01 Felix Wolfsteller * src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java, diff -r 39933df6d0fe -r 4b6e9b377a84 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Feb 01 13:32:10 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Feb 01 13:33:58 2012 +0000 @@ -738,7 +738,15 @@ public CalculationResult getHistoricalDischargeData() { - return new Calculation6().calculate(); + Gauge gauge = FLYSUtils.getReferenceGauge(this); + String rawTimerange = getDataAsString("year_range"); + String rawValues = getDataAsString("historical_values"); + int mode = getDataAsInteger("historical_mode"); + + int[] timerange = FLYSUtils.intArrayFromString(rawTimerange); + double[] values = FLYSUtils.doubleArrayFromString(rawValues); + + return new Calculation6(mode, timerange, values).calculate(gauge); } diff -r 39933df6d0fe -r 4b6e9b377a84 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java Wed Feb 01 13:32:10 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java Wed Feb 01 13:33:58 2012 +0000 @@ -2,6 +2,8 @@ import org.apache.log4j.Logger; +import de.intevation.flys.model.Gauge; + /** * @author Ingo Weinzierl @@ -10,14 +12,73 @@ private static final Logger logger = Logger.getLogger(Calculation6.class); + private int mode; + private int[] timerange; + private double[] values; - public Calculation6() { + + public static final int MODE_W = 0; + public static final int MODE_Q = 1; + + + public Calculation6(int mode, int[] timerange, double[] values) { + this.mode = mode; + this.timerange = timerange; + this.values = values; } - public CalculationResult calculate() { + public CalculationResult calculate(Gauge gauge) { + if (!checkParameters() || gauge == null) { + logger.warn("Parameters not valid for calculation."); + + return null; + } + + if (logger.isDebugEnabled()) { + debug(); + } + logger.warn("TODO: IMPLEMENT ME"); + return null; } + + + protected boolean checkParameters() { + if (!(mode == MODE_W || mode == MODE_Q)) { + logger.warn("Invalid mode '" + mode + "' for calculation."); + return false; + } + + if (timerange == null || timerange.length < 2) { + logger.warn("Invalid timerange for calculation."); + return false; + } + + if (values == null || values.length == 0) { + logger.warn("No values for W or Q specified."); + return false; + } + + return true; + } + + + /** + * Writes the parameters used for this calculation to logger. + */ + public void debug() { + StringBuilder sb = new StringBuilder(); + for (double value: values) { + sb.append(String.valueOf(value) + " "); + } + + logger.debug("========== Calculation6 =========="); + logger.debug(" Mode: " + mode); + logger.debug(" Timerange: " + timerange[0] + " - " + timerange[1]); + logger.debug(" Input values: " + sb.toString()); + logger.debug("=================================="); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :