changeset 2396:2c62bbe2e415

Give more precise message when an error occurs in W~W relation. flys-artifacts/trunk@4022 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Feb 2012 10:12:12 +0000 (2012-02-10)
parents cd4fb19ab892
children c38063bf99da
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 6 files changed, 91 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Feb 10 08:56:19 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Feb 10 10:12:12 2012 +0000
@@ -1,3 +1,14 @@
+2012-02-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java:
+	  Give more precise message when an error occurs in W~W relation.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties:
+	  Improved error messages.
+
 2012-02-09  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartGenerator.java: Modified
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Feb 10 08:56:19 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Feb 10 10:12:12 2012 +0000
@@ -903,11 +903,28 @@
         return relateWs(km1, km2, RELATE_WS_SAMPLES, errors);
     }
 
+    private static class ErrorHandler {
+
+        boolean     hasErrors;
+        Calculation errors;
+
+        ErrorHandler(Calculation errors) {
+            this.errors = errors;
+        }
+
+        void error(double km, String key, Object ... args) {
+            if (errors != null && !hasErrors) {
+                hasErrors = true;
+                errors.addProblem(km, key, args);
+            }
+        }
+    } // class ErrorHandler
+
+
     /* TODO: Add optimized methods of relateWs to relate one
      *       start km to many end kms. The index generation/spline stuff for 
      *       the start km is always the same.
      */
-
     public double [][] relateWs(
         double      km1, 
         double      km2,
@@ -951,31 +968,51 @@
         TDoubleArrayList qs1 = new TDoubleArrayList(numSamples);
         TDoubleArrayList qs2 = new TDoubleArrayList(numSamples);
 
-        boolean hadErrors = false;
+        ErrorHandler err = new ErrorHandler(errors);
 
         int i = 0;
         for (double p = 0d; p <= N-1; p += stepWidth, ++i) {
+
+            double q1;
             try {
-                double q1 = iQ1.value(p);
-                double w1 = qW1.value(q1);
-                double q2 = iQ2.value(p);
-                double w2 = qW2.value(q2);
-                ws1.add(w1);
-                ws2.add(w2);
-                qs1.add(q1);
-                qs2.add(q2);
+                q1 = iQ1.value(p);
             }
             catch (ArgumentOutsideDomainException aode) {
-                if (!hadErrors) {
-                    // XXX: I'm not sure if this really can happen
-                    //      and if we should report this more than once.
-                    hadErrors = true;
-                    if (errors != null) {
-                        errors.addProblem("relating.w.w.failed");
-                        log.warn("W~W failed", aode);
-                    }
-                }
+                err.error(km1, "w.w.qkm1.failed", p);
+                continue;
             }
+
+            double w1;
+            try {
+                w1 = qW1.value(q1);
+            }
+            catch (ArgumentOutsideDomainException aode) {
+                err.error(km1, "w.w.wkm1.failed", p);
+                continue;
+            }
+
+            double q2;
+            try {
+                q2 = iQ2.value(p);
+            }
+            catch (ArgumentOutsideDomainException aode) {
+                err.error(km2, "w.w.qkm2.failed", p);
+                continue;
+            }
+
+            double w2;
+            try {
+                w2 = qW2.value(q2);
+            }
+            catch (ArgumentOutsideDomainException aode) {
+                err.error(km2, "w.w.wkm2.failed", p);
+                continue;
+            }
+
+            ws1.add(w1);
+            ws2.add(w2);
+            qs1.add(q1);
+            qs2.add(q2);
         }
 
         return new double [][] {
--- a/flys-artifacts/src/main/resources/messages.properties	Fri Feb 10 08:56:19 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Fri Feb 10 10:12:12 2012 +0000
@@ -178,7 +178,12 @@
 km.not.found = Cannot find km.
 cannot.create.wq.relation = Cannot create W/Q relation.
 cannot.create.index.q.relation = Cannot create index/Q relation.
-relating.w.w.failed = Relating W with W failed.
+
+w.w.qkm1.failed = Calculating Q for WST index {0,number,#.##} failed.
+w.w.wkm1.failed = Calculating W for WST index {0,number,#.##} failed.
+w.w.qkm2.failed = Calculating Q for WST index {0,number,#.##} failed.
+w.w.wkm2.failed = Calculating W for WST index {0,number,#.##} failed.
+
 cannot.find.hist.q.for.w = Cannot find Q for W = {0,number,#.##} in timerange {1, date} - {2, date}
 cannot.find.hist.q.tables = Cannot find Discharge Tables for given timerange.
 cannot.find.hist.q.reftable = Cannot find reference Discharge Table for specified Gauge.
--- a/flys-artifacts/src/main/resources/messages_de.properties	Fri Feb 10 08:56:19 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Fri Feb 10 10:12:12 2012 +0000
@@ -178,7 +178,12 @@
 km.not.found = Passender Kilometer konnte nicht gefunden werden.
 cannot.create.wq.relation = W/Q-Beziehung konnte nicht ermittelt werden.
 cannot.create.index.q.relation = Spaltenindex/Q-Beziehung konnte nicht erstellt werden.
-relating.w.w.failed = W-zu-W-Zuordnung fehlgeschlagen.
+
+w.w.qkm1.failed = Berechnung von Q f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen.
+w.w.wkm1.failed = Berechnung von W f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen.
+w.w.qkm2.failed = Berechnung von Q f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen. 
+w.w.wkm2.failed = Berechnung von W f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen. 
+
 cannot.find.hist.q.for.w = Konnte zu W = {0,number,#.##} im Zeitraum ({1,date} - {2,date}) kein Abfluss ermitteln.
 cannot.find.hist.q.tables = Konnte f\u00fcr den angegebenen Zeitraum keine Abflusstafeln finden.
 cannot.find.hist.q.reftable = Konnte f\u00fcr den gew\u00e4hlten Pegel keine Bezugs-Abflusstafel ermitteln.
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Fri Feb 10 08:56:19 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Fri Feb 10 10:12:12 2012 +0000
@@ -178,7 +178,12 @@
 km.not.found = Passender Kilometer konnte nicht gefunden werden.
 cannot.create.wq.relation = W/Q-Beziehung konnte nicht ermittelt werden.
 cannot.create.index.q.relation = Spaltenindex/Q-Beziehung konnte nicht erstellt werden.
-relating.w.w.failed = W-zu-W-Zuordnung fehlgeschlagen.
+
+w.w.qkm1.failed = Berechnung von Q f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen.
+w.w.wkm1.failed = Berechnung von W f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen.
+w.w.qkm2.failed = Berechnung von Q f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen. 
+w.w.wkm2.failed = Berechnung von W f\u00fcr WST-Index {0,number,#.##} fehlgeschlagen. 
+
 cannot.find.hist.q.for.w = Konnte zu W = {0,number,#.##} im Zeitraum ({1,date} - {2,date}) kein Abfluss ermitteln.
 cannot.find.hist.q.tables = Konnte f\u00fcr den angegebenen Zeitraum keine Abflusstafeln finden.
 cannot.find.hist.q.reftable = Konnte f\u00fcr den gew\u00e4hlten Pegel keine Bezugs-Abflusstafel ermitteln.
--- a/flys-artifacts/src/main/resources/messages_en.properties	Fri Feb 10 08:56:19 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Fri Feb 10 10:12:12 2012 +0000
@@ -174,7 +174,12 @@
 km.not.found = Cannot find km.
 cannot.create.wq.relation = Cannot create W/Q relation.
 cannot.create.index.q.relation = Cannot create index/Q relation.
-relating.w.w.failed = Relating W with W failed.
+
+w.w.qkm1.failed = Calculating Q for WST index {0,number,#.##} failed.
+w.w.wkm1.failed = Calculating W for WST index {0,number,#.##} failed.
+w.w.qkm2.failed = Calculating Q for WST index {0,number,#.##} failed.
+w.w.wkm2.failed = Calculating W for WST index {0,number,#.##} failed.
+
 cannot.find.hist.q.for.w = Cannot find Q for W = {0,number,#.##} in timerange {1, date} - {2, date}
 cannot.find.hist.q.tables = Cannot find Discharge Tables for given timerange.
 cannot.find.hist.q.reftable = Cannot find reference Discharge Table for specified Gauge.

http://dive4elements.wald.intevation.org