changeset 5188:2b7f44c80857

Stations are now filtered by DiPS not AFT.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 07 Mar 2013 12:46:37 +0100
parents eec78b9f73b8
children 60b5fca4f357
files flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java flys-aft/src/main/java/de/intevation/aft/River.java flys-aft/src/main/java/de/intevation/aft/SyncContext.java flys-aft/src/main/resources/sql/aft-common.properties
diffstat 4 files changed, 46 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java	Thu Mar 07 12:02:02 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java	Thu Mar 07 12:46:37 2013 +0100
@@ -113,7 +113,7 @@
         String stationString = element.getAttribute("STATIONIERUNG");
         if (stationString.length() == 0) {
             log.warn("DIPS: Setting station of gauge '" + name + "' to zero.");
-            stationString = "0";
+            stationString = "-99999";
         }
         station = Double.parseDouble(stationString);
         if (station == 0d) {
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Mar 07 12:02:02 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Mar 07 12:46:37 2013 +0100
@@ -65,7 +65,8 @@
     public boolean sync(SyncContext context) throws SQLException {
         log.info("sync river: " + this);
 
-        Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges();
+        // Only take relevant gauges into account.
+        Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges(name, from, to);
 
         ConnectedStatements flysStatements = context.getFlysStatements();
         ConnectedStatements aftStatements  = context.getAftStatements();
@@ -78,14 +79,18 @@
             .getStatement("select.messstelle")
             .clearParameters()
             .setInt("GEWAESSER_NR", id2)
-            .setDouble("START_KM", from)
-            .setDouble("END_KM", to)
             .executeQuery();
 
         try {
             while (messstellenRs.next()) {
                 String name = messstellenRs.getString("NAME");
                 String num  = messstellenRs.getString("MESSSTELLE_NR");
+                double station = messstellenRs.getDouble("STATIONIERUNG");
+
+                if (!messstellenRs.wasNull() && station < from && station > to) {
+                    log.warn("Station found in AFT but in range: " + station);
+                    continue;
+                }
 
                 Long number = SyncContext.numberToLong(num);
                 if (number == null) {
--- a/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Thu Mar 07 12:02:02 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Thu Mar 07 12:46:37 2013 +0100
@@ -87,6 +87,36 @@
         return numberToGauge;
     }
 
+    public Map<Long, DIPSGauge> getDIPSGauges(
+        String riverName,
+        double from,
+        double to
+    ) {
+        if (from > to) {
+            double t = from;
+            from = to;
+            to = t;
+        }
+
+        riverName = riverName.toLowerCase();
+
+        Map<Long, DIPSGauge> result = new HashMap<Long, DIPSGauge>();
+
+        for (Map.Entry<Long, DIPSGauge> entry: numberToGauge.entrySet()) {
+            DIPSGauge gauge = entry.getValue();
+            // XXX: Maybe a bit too sloppy.
+            if (!riverName.contains(gauge.getRiverName().toLowerCase())) {
+                continue;
+            }
+            double station = gauge.getStation();
+            if (station >= from && station <= to) {
+                result.put(entry.getKey(), gauge);
+            }
+        }
+
+        return result;
+    }
+
     protected static Map<Long, DIPSGauge> indexByNumber(Document document) {
         Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
         NodeList nodes = document.getElementsByTagName("PEGELSTATION");
--- a/flys-aft/src/main/resources/sql/aft-common.properties	Thu Mar 07 12:02:02 2013 +0100
+++ b/flys-aft/src/main/resources/sql/aft-common.properties	Thu Mar 07 12:46:37 2013 +0100
@@ -1,8 +1,9 @@
-select.gewaesser = SELECT GEWAESSER_NR, NAME FROM SL_GEWAESSER
+select.gewaesser = \
+    SELECT GEWAESSER_NR, NAME FROM SL_GEWAESSER
 select.messstelle = \
-    SELECT NAME, MESSSTELLE_NR \
+    SELECT NAME, MESSSTELLE_NR, STATIONIERUNG \
     FROM MESSSTELLE \
-    WHERE GEWAESSER_NR = :GEWAESSER_NR AND STATIONIERUNG BETWEEN :START_KM AND :END_KM
+    WHERE GEWAESSER_NR = :GEWAESSER_NR
 select.abflusstafel = \
     SELECT ABFLUSSTAFEL_NR, \
            ABFLUSSTAFEL_BEZ, \
@@ -12,6 +13,7 @@
            BFG_ID \
     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
+select.tafelwert = \
+    SELECT TAFELWERT_NR AS id, WASSERSTAND AS w, ABFLUSS AS q FROM TAFELWERT \
+    WHERE ABFLUSSTAFEL_NR = :number
 

http://dive4elements.wald.intevation.org