diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 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 71086a3a1c5f
children 9d2a06c3a134
line wrap: on
line diff
--- 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);
     }
 

http://dive4elements.wald.intevation.org