changeset 4091:a91c7e982c32

Make W/Q values from AFT and FLYS loadable. flys-aft/trunk@3601 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 05 Jan 2012 16:41:26 +0000
parents d556e29592f5
children b3fc044f75ba
files flys-aft/ChangeLog flys-aft/src/main/java/de/intevation/aft/DischargeTable.java flys-aft/src/main/java/de/intevation/aft/WQ.java flys-aft/src/main/resources/sql/aft-common.properties flys-aft/src/main/resources/sql/flys-common.properties
diffstat 5 files changed, 120 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/ChangeLog	Wed Jan 04 17:59:26 2012 +0000
+++ b/flys-aft/ChangeLog	Thu Jan 05 16:41:26 2012 +0000
@@ -1,3 +1,16 @@
+2012-01-04	Sascha L. Teichmann	<sascha.teichmann@inteavtion.de>
+
+	* src/main/java/de/intevation/aft/WQ.java: New. W/Q model used
+	  for AFT and FLYS.
+
+	* src/main/java/de/intevation/aft/DischargeTable.java: Holds
+	  a list of its W/Q values now. Values are loadable from AFT
+	  and FLYS.
+
+	* src/main/resources/sql/aft-common.properties,
+	  src/main/resources/sql/flys-common.properties: Added statements
+	  to load W/Q values for a given discharge table.
+
 2012-01-04	Sascha L. Teichmann	<sascha.teichmann@inteavtion.de>
 
 	* src/main/java/de/intevation/aft/SyncContext.java(fetchOrCreateFLYSTimeInterval):
--- a/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java	Wed Jan 04 17:59:26 2012 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java	Thu Jan 05 16:41:26 2012 +0000
@@ -1,11 +1,20 @@
 package de.intevation.aft;
 
+import java.util.List;
+import java.util.ArrayList;
+
+import java.sql.SQLException;
+import java.sql.ResultSet;
+
+import de.intevation.db.SymbolicStatement;
+
 public class DischargeTable
 {
     protected int          id;
     protected int          gaugeId;
     protected TimeInterval timeInterval;
     protected String       description;
+    protected List<WQ>     values;
 
     public DischargeTable() {
     }
@@ -18,6 +27,7 @@
         this.gaugeId      = gaugeId;
         this.timeInterval = timeInterval;
         this.description  = description;
+        values = new ArrayList<WQ>();
     }
 
     public DischargeTable(
@@ -61,6 +71,32 @@
     public void setDescription(String description) {
         this.description = description;
     }
+
+    protected void loadValues(SymbolicStatement.Instance query) 
+    throws SQLException
+    {
+        ResultSet rs = query.executeQuery();
+        while (rs.next()) {
+            int    id = rs.getInt("id");
+            double w  = rs.getDouble("w");
+            double q  = rs.getDouble("q");
+            values.add(new WQ(id, w, q));
+        }
+        rs.close();
+    }
+
+    public void loadAftValues(SyncContext context) throws SQLException {
+        loadValues(context.getAftStatements()
+            .getStatement("select.tafelwert")
+            .clearParameters()
+            .setInt("number", getId()));
+    }
+
+    public void loadFlysValues(SyncContext context) throws SQLException {
+        loadValues(context.getFlysStatements()
+            .getStatement("select.discharge.table.values")
+            .clearParameters()
+            .setInt("table_id", getId()));
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/WQ.java	Thu Jan 05 16:41:26 2012 +0000
@@ -0,0 +1,67 @@
+package de.intevation.aft;
+
+import java.util.Comparator;
+
+public class WQ
+{
+    public static final double EPSILON = 1e-4;
+
+    public static final Comparator<WQ> WQ_EPS_CMP = new Comparator<WQ>() {
+        @Override
+        public int compare(WQ a, WQ b) {
+            int cmp = compareEpsilon(a.w, b.w);
+            if (cmp != 0) return cmp;
+            return compareEpsilon(a.q, b.q);
+        }
+    };
+
+    protected int id;
+
+    protected double w;
+    protected double q;
+
+    public WQ() {
+    }
+
+    public WQ(double w, double q) {
+        this.w = w;
+        this.q = q;
+    }
+
+    public WQ(int id, double w, double q) {
+        this.id = id;
+        this.w  = w;
+        this.q  = q;
+    }
+
+    public static final int compareEpsilon(double a, double b) {
+        double diff = a - b;
+        if (diff < -EPSILON) return -1;
+        return diff > EPSILON ? +1 : 0;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public double getW() {
+        return w;
+    }
+
+    public void setW(double w) {
+        this.w = w;
+    }
+
+    public double getQ() {
+        return q;
+    }
+
+    public void setQ(double q) {
+        this.q = q;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-aft/src/main/resources/sql/aft-common.properties	Wed Jan 04 17:59:26 2012 +0000
+++ b/flys-aft/src/main/resources/sql/aft-common.properties	Thu Jan 05 16:41:26 2012 +0000
@@ -5,4 +5,6 @@
                              strftime('%s', GUELTIG_VON) * 1000 AS GUELTIG_VON, \
                              strftime('%s', GUELTIG_BIS) * 1000 AS GUELTIG_BIS, \
                              PEGELNULLPUNKT FROM ABFLUSSTAFEL WHERE MESSSTELLE_NR LIKE :number
+select.tafelwert = SELECT TAFELWERT_NR AS id, WASSERSTAND AS w, ABFLUSS AS q FROM TAFELWERT \
+                          WHERE ABFLUSSTAFEL_NR = :number
 
--- a/flys-aft/src/main/resources/sql/flys-common.properties	Wed Jan 04 17:59:26 2012 +0000
+++ b/flys-aft/src/main/resources/sql/flys-common.properties	Thu Jan 05 16:41:26 2012 +0000
@@ -9,4 +9,4 @@
 next.discharge.id = SELECT NEXTVAL('DISCHARGE_TABLES_ID_SEQ') AS discharge_table_id
 insert.dischargetable = INSERT INTO discharge_tables (id, gauge_id, description, kind, time_interval_id) \
                         VALUES (:id, :gauge_id, :description, 0, :time_interval_id)
-
+select.discharge.table.values = SELECT id, w, q FROM discharge_table_values WHERE table_id = :table_id

http://dive4elements.wald.intevation.org