Mercurial > dive4elements > river
changeset 2993:70469e3d34b9
FixA: Made Delta W/t calculation finally work
flys-artifacts/trunk@4545 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 28 May 2012 20:59:27 +0000 |
parents | 0abdede5a0b8 |
children | a2b265b9b2f7 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java |
diffstat | 8 files changed, 104 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon May 28 20:59:27 2012 +0000 @@ -1,3 +1,29 @@ +2012-05-28 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + Made Delta W/t calculation work. + + * src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java: + Added toString() method. + + * src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java: + Fixed problem accessing Ws. + + * src/main/java/de/intevation/flys/artifacts/model/Parameters.java: + Fixed silly 'name.equals(name)' bug. This mainly prevented delta W/t + computation from working. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java: + More deug code. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java: + More debug code. Simplified access to data a bit. + + * src/main/java/de/intevation/flys/exports/AbstractExporter.java: + Allow CSV exporter to throw IOExceptions. + + * src/main/java/de/intevation/flys/exports/DeltaWtExporter.java: + More debug output. Flush CSV after writing. + 2012-05-28 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java Mon May 28 20:59:27 2012 +0000 @@ -47,12 +47,16 @@ idx = -idx - 1; - w[index] = Linear.linear(km, kms[idx], kms[idx+1], ws[idx], ws[idx+1]); + w[index] = Linear.linear(km, kms[idx-1], kms[idx], ws[idx-1], ws[idx]); return false; } public double getQ(double km) { return qs.findQ(km); } + + public QRangeTree getQRanges() { + return 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/Parameters.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Mon May 28 20:59:27 2012 +0000 @@ -30,7 +30,7 @@ public int columnIndex(String name) { for (int i = 0; i < columnNames.length; ++i) { - if (name.equals(name)) { + if (columnNames[i].equals(name)) { return i; } }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon May 28 20:59:27 2012 +0000 @@ -212,6 +212,27 @@ return root != null ? root.findQ(pos) : Double.NaN; } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + inorder(root, sb); + return sb.toString(); + } + + protected static void inorder(Node node, StringBuilder sb) { + if (node != null) { + inorder(node.left, sb); + sb.append('[') + .append(node.a) + .append(", ") + .append(node.b) + .append(": ") + .append(node.q) + .append(']'); + inorder(node.right, sb); + } + } + private static final String name(Object o) { return String.valueOf(System.identityHashCode(o) & 0xffffffffL); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java Mon May 28 20:59:27 2012 +0000 @@ -47,6 +47,10 @@ deltaWTs.add(deltaWT); } + public int size() { + return deltaWTs.size(); + } + @Override public int compareTo(KM other) { double d = km - other.km;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java Mon May 28 20:59:27 2012 +0000 @@ -251,6 +251,8 @@ FixingsOverview overview, Parameters results ) { + boolean debug = log.isDebugEnabled(); + DeltaWTsKM deltaWTsKM = new DeltaWTsKM(results.size()); Column [][] analysisColumns = getAnalysisColumns(overview); @@ -263,8 +265,10 @@ double [] ow = new double[1]; + int kmIdx = results.columnIndex("km"); + for (int i = 0, N = results.size(); i < N; ++i) { - double km = results.get(i, "km"); + double km = results.get(i, kmIdx); results.get(i, parameterIndices, parameterValues); DeltaWTsKM.KM dwtkm = new DeltaWTsKM.KM(km); @@ -278,18 +282,24 @@ for (int j = 0; j < analysisColumns.length; ++j) { Column [] periodColumns = analysisColumns[j]; + int failedQ = 0; + int failedW = 0; + int failedC = 0; + for (int k = 0; k < periodColumns.length; ++k) { Column pc = periodColumns[k]; // Q from real data. double q = pc.data.getQ(km); if (Double.isNaN(q)) { + ++failedQ; continue; } // Calculate W from function. double nw = instance.value(q); if (Double.isNaN(nw)) { + ++failedC; continue; } @@ -297,6 +307,7 @@ pc.data.getW(km, ow); if (Double.isNaN(ow[0])) { + ++failedW; continue; } @@ -309,6 +320,13 @@ dwtkm.add(deltaWT); } + if (debug) { + log.debug("failed W: " + failedW); + log.debug("failed Q: " + failedQ); + log.debug("failed C: " + failedC); + log.debug("input size: " + periodColumns.length); + log.debug("outpt size: " + dwtkm.size()); + } } } @@ -335,6 +353,11 @@ /** Fetch meta and data columns for analysis periods. */ protected Column [][] getAnalysisColumns(FixingsOverview overview) { + boolean debug = log.isDebugEnabled(); + if (debug) { + log.debug("number analysis periods: " + analysisPeriods.length); + } + Column columns [][] = new Column[analysisPeriods.length][]; Range range = new Range(from, to); @@ -360,6 +383,10 @@ List<Fixing.Column> metaCols = overview.filter(range, filter); + if (debug) { + log.debug("number of filtered columns: " + metaCols.size()); + } + ArrayList<Column> cols = new ArrayList<Column>(metaCols.size()); // Only use columns which have data. @@ -369,6 +396,10 @@ cols.add(new Column(meta, data)); } } + + if (debug) { + log.debug("failed loading: " + (metaCols.size()-cols.size())); + } columns[i] = cols.toArray(new Column[cols.size()]); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java Mon May 28 20:59:27 2012 +0000 @@ -76,7 +76,7 @@ * * @param writer The CSVWriter. */ - protected abstract void writeCSVData(CSVWriter writer); + protected abstract void writeCSVData(CSVWriter writer) throws IOException; /**
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java Mon May 28 18:35:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java Mon May 28 20:59:27 2012 +0000 @@ -98,7 +98,9 @@ } @Override - protected void writeCSVData(CSVWriter writer) { + protected void writeCSVData(CSVWriter writer) throws IOException { + + boolean debug = log.isDebugEnabled(); writeCSVHeader(writer); @@ -109,12 +111,22 @@ Locale locale = Resources.getLocale(meta); DateFormat dF = DateFormat.getDateInstance(DateFormat.SHORT, locale); + if (debug) { + log.debug("DeltaWTsKMs: " + deltaWTsKMs.size()); + } + for (DeltaWTsKM deltaWTsKM: deltaWTsKMs) { List<DeltaWTsKM.KM> dkms = deltaWTsKM.getKms(); + if (debug) { + log.debug("DeltaWTsKM.KM: " + dkms.size()); + } for (DeltaWTsKM.KM dkm: dkms) { double km = dkm.getKm(); String kmS = kmF.format(km); List<DeltaWT> deltaWTs = dkm.getDeltaWTs(); + if (debug) { + log.debug("deltaWTs: " + deltaWTs.size()); + } for (DeltaWT dwt: deltaWTs) { double deltaW = dwt.getDeltaW(); Date date = dwt.getDate(); @@ -131,6 +143,7 @@ } } } + writer.flush(); }