changeset 2186:ec2574eb2d32

Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact. flys-artifacts/trunk@3792 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 27 Jan 2012 12:42:20 +0000
parents a9a8df1473fd
children de5f391fdc8f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java
diffstat 4 files changed, 94 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jan 27 11:58:35 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jan 27 12:42:20 2012 +0000
@@ -1,3 +1,18 @@
+2012-01-27	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	 * src/main/java/de/intevation/flys/artifacts/model/Calculation5.java:
+	   New. Calcutation to be created from WINFOArtifact
+	   for the 'Bezugslinienverfahren'.
+	
+	 * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java:
+	   Added TODO about optimization of the 'Bezugslinienverfahren'.
+	   Added number of default samples of the W~W relation.
+
+	 * src/main/java/de/intevation/flys/artifacts/model/WW.java:
+	   Added convinience constructor to store the calculation results.
+
+	 * ChangeLog: Removed false TODO.
+
 2012-01-27  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/WaterlevelExporter.java,
@@ -56,13 +71,9 @@
 	\-- W
 	    +-- WW
 	    \-- WQ
-		    +-- WQDay
+	        +-- 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.
+	            \-- WQCKms
 
 	* src/main/java/de/intevation/flys/artifacts/model/W.java:
 	  New. Base class
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java	Fri Jan 27 12:42:20 2012 +0000
@@ -0,0 +1,56 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.ArrayList;
+
+import org.apache.log4j.Logger;
+
+
+public class Calculation5
+extends      Calculation
+{
+    private static Logger log = Logger.getLogger(Calculation5.class);
+
+    protected double    startKm;
+    protected double [] endKms;
+
+    public Calculation5() {
+    }
+
+    public Calculation5(double startKm, double [] endKms) {
+        this.startKm = startKm;
+        this.endKms  = endKms;
+    }
+
+    public CalculationResult calculate(WstValueTable wst) {
+        ArrayList<WW> results = new ArrayList<WW>();
+
+        int numProblems = numProblems();
+
+        for (double endKm: endKms) {
+
+            double [][] wws = wst.relateWs(startKm, endKm, this);
+            int newNumProblems = numProblems();
+
+            if (wws.length == 2) {
+                WW ww = new WW(generateName(startKm, endKm), wws[0], wws[1]);
+
+                if (newNumProblems > newNumProblems) {
+                    ww.removeNaNs();
+                }
+
+                results.add(ww);
+            }
+            numProblems = newNumProblems;
+        }
+
+        return new CalculationResult(
+            results.toArray(new WW[results.size()]),
+            this);
+    }
+
+    protected static String generateName(double startKm, double endKm) {
+        // TODO: I18N
+        return "W(km " + startKm + ") ~ W(km " + endKm + ")";
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java	Fri Jan 27 11:58:35 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java	Fri Jan 27 12:42:20 2012 +0000
@@ -23,6 +23,12 @@
         ws2 = new TDoubleArrayList(capacity);
     }
 
+    public WW(String name, double [] ws, double [] ws2) {
+        this.name = name;
+        this.ws  = new TDoubleArrayList(ws);
+        this.ws2 = new TDoubleArrayList(ws2);
+    }
+
     public void add(double w1, double w2) {
         ws .add(w1);
         ws2.add(w2);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Jan 27 11:58:35 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Jan 27 12:42:20 2012 +0000
@@ -32,6 +32,8 @@
 
     public static final int DEFAULT_Q_STEPS = 500;
 
+    public static final int RELATE_WS_SAMPLES = 150;
+
     /**
      * A Column in the table, typically representing one measurement session.
      */
@@ -892,6 +894,19 @@
     public double [][] relateWs(
         double      km1, 
         double      km2,
+        Calculation errors
+    ) {
+        return relateWs(km1, km2, RELATE_WS_SAMPLES, errors);
+    }
+
+    /* 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,
         int         numSamples,
         Calculation errors
     ) {

http://dive4elements.wald.intevation.org