# HG changeset patch # User Ingo Weinzierl # Date 1328110871 0 # Node ID 59af81364eb1e5b91a06641440a2031b9a3bda0b # Parent 9dc81827b1877f91d6d7d8808c393b238da51a73 Improved the 'historical discharge' calculation: implemented findValueForW(). flys-artifacts/trunk@3872 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9dc81827b187 -r 59af81364eb1 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Feb 01 15:00:13 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Feb 01 15:41:11 2012 +0000 @@ -1,3 +1,12 @@ +2012-02-01 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java: + Moved code to load values of a discharge table into an own static + function to be able to reuse it in Calculation6. + + * src/main/java/de/intevation/flys/artifacts/model/Calculation6.java: + Implemented the findValueForW(). + 2012-02-01 Felix Wolfsteller Fake some reference curve input values to have working prototype diff -r 9dc81827b187 -r 59af81364eb1 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 15:00:13 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation6.java Wed Feb 01 15:41:11 2012 +0000 @@ -26,6 +26,8 @@ public static final int MODE_W = 0; public static final int MODE_Q = 1; + public static final double SCALE = 100d; + public Calculation6(int mode, long[] timerange, double[] values) { this.mode = mode; @@ -115,6 +117,8 @@ protected WQTimerange[] prepareCalculationData(List dts) { List wqts = new ArrayList(values.length); + boolean debug = logger.isDebugEnabled(); + for (double value: values) { logger.debug("Prepare data for value: " + value); @@ -137,6 +141,10 @@ w = findValueForQ(dt, q); } + if (debug) { + logger.debug("Q=" + q + " | W=" + w); + } + wqt.add(w, q, t); } @@ -148,13 +156,15 @@ protected double findValueForW(DischargeTable dt, double w) { - logger.warn("TODO: IMPLEMENT ME!"); - return 5; + double[][] vs = DischargeTables.loadDischargeTableValues(dt,SCALE,true); + return DischargeTables.getQForW(vs, w); } protected double findValueForQ(DischargeTable dt, double q) { + double[][] vs = DischargeTables.loadDischargeTableValues(dt,SCALE,true); logger.warn("TODO: IMPLEMENT ME!"); + return 10; } diff -r 9dc81827b187 -r 59af81364eb1 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java Wed Feb 01 15:00:13 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java Wed Feb 01 15:41:11 2012 +0000 @@ -124,27 +124,10 @@ // TODO: Filter by time interval DischargeTable table = tables.get(0); - List dtvs = - table.getDischargeTableValues(); - - final double [][] vs = new double[2][dtvs.size()]; - boolean qSorted = true; - double lastQ = -Double.MAX_VALUE; - - int idx = 0; - for (DischargeTableValue dtv: dtvs) { - double q = dtv.getQ().doubleValue(); - vs[0][idx] = q * scale; - vs[1][idx] = dtv.getW().doubleValue() * scale; - ++idx; - - if (qSorted && lastQ > q) { - qSorted = false; - } - lastQ = q; - } + final double[][] vs = + loadDischargeTableValues(table, scale, qSorted); if (!qSorted) { log.debug("need to sort by q values"); @@ -182,6 +165,43 @@ return values; } + + /** + * @param table The discharge table + * @param scale The scale factor to adjust W and Q values. + * @param qSorted Boolean flag that is used to evaluate if the values should + * be sorted. + * + * @return the values of a discharge table. + */ + public static double[][] loadDischargeTableValues( + DischargeTable table, + double scale, + boolean qSorted + ) { + List dtvs = table.getDischargeTableValues(); + + final double [][] vs = new double[2][dtvs.size()]; + + double lastQ = -Double.MAX_VALUE; + + int idx = 0; + for (DischargeTableValue dtv: dtvs) { + double q = dtv.getQ().doubleValue(); + vs[0][idx] = q * scale; + vs[1][idx] = dtv.getW().doubleValue() * scale; + ++idx; + + if (qSorted && lastQ > q) { + qSorted = false; + } + lastQ = q; + } + + return vs; + } + + public static double getQForW(double [][] values, double w) { boolean debug = log.isDebugEnabled();