Mercurial > dive4elements > river
changeset 2182:5ff481ab24a1
Refactored class hierachy to integrate model for W~W.
flys-artifacts/trunk@3786 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 27 Jan 2012 10:45:34 +0000 |
parents | 38207b820dca |
children | a79d5cd26083 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java |
diffstat | 9 files changed, 289 insertions(+), 152 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Jan 27 10:45:34 2012 +0000 @@ -1,3 +1,35 @@ +2012-01-27 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + Refactored class hierachy to integrate model for W~W: + + NamedObjImpl + \-- W + +-- WW + \-- WQ + +-- WQDay + \-- WQKms + \-- WQCKms + + FIXME: WQDay should be removed from this tree because only + a Q/Day model is needed for the 'Dauerzahlen' calculation. + The Ws in WQDay are unused and only consume (cache) memory. + + * src/main/java/de/intevation/flys/artifacts/model/W.java: + New. Base class + + * src/main/java/de/intevation/flys/artifacts/model/WW.java: + New. Model for W~W + + * src/main/java/de/intevation/flys/artifacts/model/WQKms.java, + src/main/java/de/intevation/flys/artifacts/model/WQDay.java, + src/main/java/de/intevation/flys/artifacts/model/WQ.java, + src/main/java/de/intevation/flys/artifacts/model/WQCKms.java: + Adjusted to follow the new class hierarchy. + + * src/main/java/de/intevation/flys/exports/WaterlevelExporter.java, + src/main/java/de/intevation/flys/exports/ComputedDischargeCurveExporter.java: + Removed superfluous imports. + 2012-01-27 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/resources/messages.properties,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java Fri Jan 27 10:45:34 2012 +0000 @@ -0,0 +1,143 @@ +package de.intevation.flys.artifacts.model; + +import de.intevation.flys.utils.DataUtil; + +import gnu.trove.TDoubleArrayList; + +import org.apache.log4j.Logger; + +public class W +extends NamedObjectImpl +{ + private static Logger log = Logger.getLogger(W.class); + + protected TDoubleArrayList ws; + + public W() { + } + + public W(String name) { + super(name); + } + + public W(int capacity) { + this(capacity, ""); + } + + public W(int capacity, String name) { + super(name); + ws = new TDoubleArrayList(capacity); + } + + public void add(double value) { + ws.add(value); + } + + public int size() { + return ws.size(); + } + + public double getW(int idx) { + return ws.getQuick(idx); + } + + public double [] getWs() { + return ws.toNativeArray(); + } + + public double [] get(int idx) { + return get(idx, new double [1]); + } + + public double [] get(int idx, double [] dst) { + dst[0] = ws.getQuick(idx); + return dst; + } + + public static void removeNaNs(TDoubleArrayList [] arrays) { + + int dest = 0; + + int A = arrays.length; + int N = arrays[0].size(); + + OUTER: for (int i = 0; i < N; ++i) { + for (int j = 0; j < A; ++j) { + TDoubleArrayList a = arrays[j]; + double v = a.getQuick(i); + if (Double.isNaN(v)) { + continue OUTER; + } + a.setQuick(dest, v); + } + ++dest; + } + + if (dest < N) { + for (int i = 0; i < A; ++i) { + arrays[i].remove(dest, N-dest); + } + } + } + + public void removeNaNs() { + removeNaNs(new TDoubleArrayList [] { ws }); + } + + public boolean guessWaterIncreasing() { + return guessWaterIncreasing(0.05f); + } + + public boolean guessWaterIncreasing(float factor) { + return DataUtil.guessWaterIncreasing(ws, factor); + } + + public int [] longestIncreasingWRangeIndices() { + return longestIncreasingWRangeIndices(new int[2]); + } + + public int [] longestIncreasingWRangeIndices(int [] bounds) { + + int N = size(); + int start = 0; + int stop = 0; + + double lastW = Double.MAX_VALUE; + + for (int i = 0; i < N; ++i) { + double v = ws.getQuick(i); + if (v <= lastW) { + if (stop-start > bounds[1]-bounds[0]) { + bounds[0] = start; + bounds[1] = stop; + if (log.isDebugEnabled()) { + log.debug("new range: " + + bounds[0] + " - " + bounds[1] + " (" + + ws.getQuick(bounds[0]) + ", " + + ws.getQuick(bounds[1]) + ")"); + + } + } + start = stop = i; + } + else { + stop = i; + } + lastW = v; + } + + if (stop-start > bounds[1]-bounds[0]) { + bounds[0] = start; + bounds[1] = stop; + if (log.isDebugEnabled()) { + log.debug("new range @end: " + + bounds[0] + " - " + bounds[1] + " (" + + ws.getQuick(bounds[0]) + ", " + + ws.getQuick(bounds[1]) + ")"); + } + } + + return bounds; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Fri Jan 27 10:45:34 2012 +0000 @@ -3,34 +3,27 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import de.intevation.flys.utils.DataUtil; - import gnu.trove.TDoubleArrayList; import org.apache.log4j.Logger; public class WQ -extends NamedObjectImpl +extends W { public static final Pattern NUMBERS_PATTERN = Pattern.compile("\\D*(\\d++.\\d*)\\D*"); - - private static Logger logger = Logger.getLogger(WQ.class); + private static Logger log = Logger.getLogger(WQ.class); - // TODO: s/w/ws/g - protected TDoubleArrayList w; - - // TODO: s/q/qs/g - protected TDoubleArrayList q; + protected TDoubleArrayList qs; public WQ() { this(""); } public WQ(String name) { - w = new TDoubleArrayList(); - q = new TDoubleArrayList(); + super(name); + qs = new TDoubleArrayList(); } public WQ(int capacity) { @@ -39,9 +32,8 @@ public WQ(int capacity, String name) { - super(name); - w = new TDoubleArrayList(capacity); - q = new TDoubleArrayList(capacity); + super(capacity, name); + qs = new TDoubleArrayList(capacity); } public WQ(double [] qs, double [] ws) { @@ -50,8 +42,8 @@ public WQ(double [] qs, double [] ws, String name) { super(name); - w = new TDoubleArrayList(ws); - q = new TDoubleArrayList(qs); + this.ws = new TDoubleArrayList(ws); + this.qs = new TDoubleArrayList(qs); } @@ -77,127 +69,34 @@ return null; } - public void add(double w, double q) { - this.w.add(w); - this.q.add(q); - } - - public int size() { - return w.size(); - } - - public double getW(int idx) { - return w.getQuick(idx); + ws.add(w); + qs.add(q); } public double getQ(int idx) { - return q.getQuick(idx); + return qs.getQuick(idx); } + @Override public double [] get(int idx) { return get(idx, new double [2]); } + @Override public double [] get(int idx, double [] dst) { - dst[0] = w.getQuick(idx); - dst[1] = q.getQuick(idx); + dst[0] = ws.getQuick(idx); + dst[1] = qs.getQuick(idx); return dst; } - public double [] getWs() { - return w.toNativeArray(); - } - public double [] getQs() { - return q.toNativeArray(); - } - - public static void removeNaNs(TDoubleArrayList [] arrays) { - - int dest = 0; - - int A = arrays.length; - int N = arrays[0].size(); - - OUTER: for (int i = 0; i < N; ++i) { - for (int j = 0; j < A; ++j) { - TDoubleArrayList a = arrays[j]; - double v = a.getQuick(i); - if (Double.isNaN(v)) { - continue OUTER; - } - a.setQuick(dest, v); - } - ++dest; - } - - if (dest < N) { - for (int i = 0; i < A; ++i) { - arrays[i].remove(dest, N-dest); - } - } - } - - public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { w, q }); - } - - public boolean guessWaterIncreasing() { - return guessWaterIncreasing(0.05f); - } - - public boolean guessWaterIncreasing(float factor) { - return DataUtil.guessWaterIncreasing(w, factor); + return qs.toNativeArray(); } - public int [] longestIncreasingWRangeIndices() { - return longestIncreasingWRangeIndices(new int[2]); - } - - public int [] longestIncreasingWRangeIndices(int [] bounds) { - - int N = size(); - int start = 0; - int stop = 0; - - double lastW = Double.MAX_VALUE; - - for (int i = 0; i < N; ++i) { - double v = w.getQuick(i); - if (v <= lastW) { - if (stop-start > bounds[1]-bounds[0]) { - bounds[0] = start; - bounds[1] = stop; - if (logger.isDebugEnabled()) { - logger.debug("new range: " + - bounds[0] + " - " + bounds[1] + " (" + - w.getQuick(bounds[0]) + ", " + - w.getQuick(bounds[1]) + ")"); - - } - } - start = stop = i; - } - else { - stop = i; - } - lastW = v; - } - - if (stop-start > bounds[1]-bounds[0]) { - bounds[0] = start; - bounds[1] = stop; - if (logger.isDebugEnabled()) { - logger.debug("new range @end: " + - bounds[0] + " - " + bounds[1] + " (" + - w.getQuick(bounds[0]) + ", " + - w.getQuick(bounds[1]) + ")"); - - } - } - - return bounds; + @Override + public void removeNaNs() { + removeNaNs(new TDoubleArrayList [] { ws, qs }); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Fri Jan 27 10:45:34 2012 +0000 @@ -2,40 +2,39 @@ import gnu.trove.TDoubleArrayList; - /** * This class represents a pool of data triples that consists of 'W', 'Q' and * 'KM' data with corrected 'W' values computed by a BackJumpCorrector. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class WQCKms extends WQKms { - - protected TDoubleArrayList cw; +public class WQCKms +extends WQKms +{ + protected TDoubleArrayList cws; public WQCKms() { } public WQCKms(WQKms other, double [] cws) { - this.w = other.w; - this.q = other.q; + this.ws = other.ws; + this.qs = other.qs; this.kms = other.kms; - this.cw = new TDoubleArrayList(cws); + this.cws = new TDoubleArrayList(cws); } public WQCKms(double[] kms, double[] qs, double[] ws, double[] cws) { super(kms, qs, ws); - this.cw = new TDoubleArrayList(cws); + this.cws = new TDoubleArrayList(cws); } @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { w, q, cw, kms }); + removeNaNs(new TDoubleArrayList [] { ws, qs, cws, kms }); } - /** * Adds a new row to this data pool with corrected W. * @@ -45,10 +44,14 @@ * @param cw The corrected W. */ public void add(double w, double q, double kms, double cw) { - add(w, q, kms); - this.cw.add(cw); + super.add(w, q, kms); + cws.add(cw); } + @Override + public double[] get(int idx) { + return get(idx, new double[4]); + } /** * This method returns a 4dim array of W, Q,Kms and corrected W. @@ -66,15 +69,15 @@ return dst; } - if (cw != null && cw.size() > idx) { - dst[3] = cw.getQuick(idx); + if (cws != null && cws.size() > idx) { + dst[3] = cws.getQuick(idx); } return dst; } public double getC(int idx) { - return cw.getQuick(idx); + return cws.getQuick(idx); } @@ -84,7 +87,7 @@ * @return the double array of corrected W values. */ public double[] getCWs() { - return cw.toNativeArray(); + return cws.toNativeArray(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java Fri Jan 27 10:45:34 2012 +0000 @@ -19,6 +19,7 @@ } public WQDay(int capacity) { + super(capacity); days = new TIntArrayList(capacity); } @@ -50,26 +51,26 @@ public void removeNaNs() { int dest = 0; - int N = w.size(); + int N = ws.size(); for (int i = 0; i < N; ++i) { - double wi = w.getQuick(i); - double qi = q.getQuick(i); + double wi = ws.getQuick(i); + double qi = qs.getQuick(i); if (Double.isNaN(wi) || Double.isNaN(qi)) { continue; } days.setQuick(dest, days.getQuick(i)); - w.setQuick(dest, wi); - q.setQuick(dest, qi); + ws.setQuick(dest, wi); + qs.setQuick(dest, qi); ++dest; } if (dest < N) { days.remove(dest, N-dest); - w .remove(dest, N-dest); - q .remove(dest, N-dest); + ws .remove(dest, N-dest); + qs .remove(dest, N-dest); } } }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Fri Jan 27 10:45:34 2012 +0000 @@ -38,7 +38,7 @@ public WQKms(int capacity, String name) { - super(name); + super(capacity, name); this.kms = new TDoubleArrayList(capacity); } @@ -54,7 +54,7 @@ @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { w, q, kms }); + removeNaNs(new TDoubleArrayList [] { ws, qs, kms }); } /** @@ -69,6 +69,11 @@ kms.add(km); } + @Override + public double [] get(int idx) { + return get(idx, new double [3]); + } + /** * This method returns a triple of W, Q and Kms in a single 3dim array. * @@ -78,9 +83,9 @@ * @return a triple of [W, Q, Kms] in dst. */ @Override - public double[] get(int idx, double [] dst) { - dst[0] = w .getQuick(idx); - dst[1] = q .getQuick(idx); + public double [] get(int idx, double [] dst) { + dst[0] = ws .getQuick(idx); + dst[1] = qs .getQuick(idx); dst[2] = kms.getQuick(idx); return dst; } @@ -97,7 +102,7 @@ @Override public TDoubleArrayList allWs() { - return w; + return ws; } public double[] getKms() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Fri Jan 27 10:45:34 2012 +0000 @@ -0,0 +1,56 @@ +package de.intevation.flys.artifacts.model; + +import gnu.trove.TDoubleArrayList; + +public class WW +extends W +{ + protected TDoubleArrayList ws2; + + public WW() { + } + + public WW(String name) { + super(name); + } + + public WW(int capacity) { + this(capacity, ""); + } + + public WW(int capacity, String name) { + super(capacity, name); + ws2 = new TDoubleArrayList(capacity); + } + + public void add(double w1, double w2) { + ws .add(w1); + ws2.add(w2); + } + + public double getW2(int idx) { + return ws2.getQuick(idx); + } + + public double [] getWs2() { + return ws2.toNativeArray(); + } + + @Override + public double [] get(int idx) { + return get(idx, new double[2]); + } + + @Override + public double [] get(int idx, double [] dst) { + dst[0] = ws .getQuick(idx); + dst[1] = ws2.getQuick(idx); + return dst; + } + + @Override + public void removeNaNs() { + removeNaNs(new TDoubleArrayList [] { ws, ws2 }); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveExporter.java Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveExporter.java Fri Jan 27 10:45:34 2012 +0000 @@ -17,7 +17,6 @@ import au.com.bytecode.opencsv.CSVWriter; -import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Fri Jan 27 10:32:09 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Fri Jan 27 10:45:34 2012 +0000 @@ -19,7 +19,6 @@ import au.com.bytecode.opencsv.CSVWriter; -import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint;