changeset 2624:3f24865082da

Generate error message when more than one Q is found for given Q in "W auf freier Strecke". flys-artifacts/trunk@4212 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 11 Apr 2012 10:14:13 +0000
parents c4591312f3d3
children 72ce02d1a568
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.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 7 files changed, 72 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Apr 11 10:14:13 2012 +0000
@@ -1,3 +1,18 @@
+2012-04-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Generate error message when more than one Q is found for given
+	  Q in "W auf freier Strecke".
+
+	* src/main/java/de/intevation/flys/artifacts/model/Calculation.java:
+	  Added feature to adopt problems from other reports.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties:
+	  Added i18n for the error message.
+
 2012-04-11  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/WQSelect.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Apr 11 10:14:13 2012 +0000
@@ -277,6 +277,33 @@
         }
     }
 
+    protected static boolean reportGeneratedWs(
+        Calculation report,
+        double []   ws
+    ) {
+        if (ws == null || ws.length < 2) {
+            return false;
+        }
+
+        double  lastW = ws[0];
+        boolean alreadyReported = false;
+
+        for (int i = 1; i < ws.length; ++i) {
+            if (Math.abs(lastW - ws[i]) < 1e-5) {
+                if (!alreadyReported) {
+                    alreadyReported = true;
+                    report.addProblem("more.than.one.q.for.w", ws[i]);
+                }
+            }
+            else {
+                alreadyReported = false;
+            }
+            lastW = ws[i];
+        }
+
+        return true;
+    }
+
 
     //
     // METHODS FOR RETRIEVING COMPUTED DATA FOR DIFFERENT CHART TYPES
@@ -305,6 +332,8 @@
         double[] ws   = null;
         boolean  qSel = true;
 
+        Calculation report = new Calculation();
+
         if (qs == null) {
             logger.debug("Determine Q values based on a set of W values.");
             qSel = false;
@@ -315,8 +344,7 @@
             }
             qs = qws[0];
 
-            if (qws[1] != null) { // If new ws where generated.
-                // TODO: Inform user!
+            if (reportGeneratedWs(report, qws[1])) { 
                 ws = qws[1];
             }
         }
@@ -351,7 +379,7 @@
                 "reference gauge: " + gauge.getName() + " (km " + refKm + ")");
         }
 
-        return computeWaterlevelData(kms, qs, ws, wst, refKm);
+        return computeWaterlevelData(kms, qs, ws, wst, refKm, report);
     }
 
 
@@ -370,12 +398,17 @@
         double []     qs,
         double []     ws,
         WstValueTable wst,
-        double        refKm
+        double        refKm,
+        Calculation   report
     ) {
         logger.info("WINFOArtifact.computeWaterlevelData");
 
         Calculation1 calc1 = new Calculation1(kms, qs, ws, refKm);
 
+        if (report != null) {
+            calc1.addProblems(report);
+        }
+
         return calc1.calculate(wst);
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java	Wed Apr 11 10:14:13 2012 +0000
@@ -92,6 +92,18 @@
         return problems;
     }
 
+    public void addProblems(Calculation other) {
+        List<Problem> otherProblems = other.problems;
+        if (otherProblems != null) {
+            List<Problem> problems = checkProblems();
+            for (Problem problem: otherProblems) {
+                if (!problems.contains(problem)) {
+                    problems.add(problem);
+                }
+            }
+        }
+    }
+
     public void addProblem(Problem problem) {
         List<Problem> problems = checkProblems();
         if (!problems.contains(problem)) {
--- a/flys-artifacts/src/main/resources/messages.properties	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Wed Apr 11 10:14:13 2012 +0000
@@ -203,6 +203,8 @@
 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.
 
+more.than.one.q.for.w = Found more Qs for W = {0,number,#.##}.
+
 no.river.selected = No river selected.
 no.gauge.selected = No gauge selected.
 no.locations.selected = No locations selected.
--- a/flys-artifacts/src/main/resources/messages_de.properties	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Wed Apr 11 10:14:13 2012 +0000
@@ -203,6 +203,8 @@
 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.
 
+more.than.one.q.for.w = Mehr als ein Q f\u00fcr W = {0,number,#.##} gefunden.
+
 no.river.selected = Kein Gew\u00e4sser ausgew\u00e4hlt.
 no.gauge.selected = Kein Pegel ausgew\u00e4hlt.
 no.locations.selected = Keine Orte angegeben.
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Wed Apr 11 10:14:13 2012 +0000
@@ -202,6 +202,8 @@
 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.
 
+more.than.one.q.for.w = Mehr als ein Q f\u00fcr W = {0,number,#.##} gefunden.
+
 no.river.selected = Kein Gew\u00e4sser ausgew\u00e4hlt.
 no.gauge.selected = Kein Pegel ausgew\u00e4hlt.
 no.locations.selected = Keine Orte angegeben.
--- a/flys-artifacts/src/main/resources/messages_en.properties	Wed Apr 11 09:17:03 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Wed Apr 11 10:14:13 2012 +0000
@@ -199,6 +199,8 @@
 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.
 
+more.than.one.q.for.w = Found more Qs for W = {0,number,#.##}.
+
 no.river.selected = No river selected.
 no.gauge.selected = No gauge selected.
 no.locations.selected = No locations selected.

http://dive4elements.wald.intevation.org