[PATCH 3 of 3] Potential fix for flys/1453

Wald Commits scm-commit at wald.intevation.org
Wed Aug 21 16:15:59 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1377094537 -7200
# Node ID e5675e85ac3846dda9aafbb449bf5f6aa63647a9
# Parent  389bf6b7d37169887ef1f9fbff28f5767d169b47
Potential fix for flys/1453.

diff -r 389bf6b7d371 -r e5675e85ac38 etl/src/main/java/org/dive4elements/river/etl/aft/River.java
--- a/etl/src/main/java/org/dive4elements/river/etl/aft/River.java	Wed Aug 21 16:14:29 2013 +0200
+++ b/etl/src/main/java/org/dive4elements/river/etl/aft/River.java	Wed Aug 21 16:15:37 2013 +0200
@@ -15,9 +15,11 @@
 import java.sql.SQLException;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 import org.apache.log4j.Logger;
 
@@ -136,11 +138,25 @@
             .clearParameters()
             .setInt("river_id", id1).executeQuery();
 
+        TreeMap<Double, String> station2gaugeName = new TreeMap<Double, String>(
+            new Comparator<Double>() {
+                @Override
+                public int compare(Double a, Double b) {
+                    double diff = a - b;
+                    if (diff < -0.0001) return -1;
+                    if (diff >  0.0001) return +1;
+                    return 0;
+                }
+            });
+
         try {
             while (gaugesRs.next()) {
                 int gaugeId = gaugesRs.getInt("id");
                 String name = gaugesRs.getString("name");
                 long   number = gaugesRs.getLong("official_number");
+                double station = gaugesRs.getDouble("station");
+                station2gaugeName.put(station, name);
+
                 if (gaugesRs.wasNull()) {
                     log.warn("FLYS: Gauge '" + name +
                         "' has no official number. Ignored.");
@@ -163,7 +179,8 @@
             gaugesRs.close();
         }
 
-        boolean modified = createGauges(context, aftDIPSGauges);
+        boolean modified = createGauges(
+            context, aftDIPSGauges, station2gaugeName);
 
         modified |= updateGauges(context, updateGauges);
 
@@ -364,7 +381,8 @@
 
     protected boolean createGauges(
         SyncContext          context,
-        Map<Long, DIPSGauge> gauges
+        Map<Long, DIPSGauge> gauges,
+        Map<Double, String>  station2gaugeName
     )
     throws SQLException
     {
@@ -385,6 +403,14 @@
             log.info("Gauge '" + gauge.getAftName() +
                 "' not in FLYS but in AFT/DIPS. -> Create");
 
+            String flysGaugeName = station2gaugeName.get(gauge.getStation());
+            if (flysGaugeName != null) {
+                log.warn("FLYS: AFT gauge " + gauge.getName() +
+                    " has same station as FLYS gauge " + flysGaugeName +
+                    " -> ignored.");
+                continue;
+            }
+
             if (!gauge.hasDatums()) {
                 log.warn("DIPS: Gauge '" +
                     gauge.getAftName() + "' has no datum. Ignored.");
diff -r 389bf6b7d371 -r e5675e85ac38 etl/src/main/resources/sql/flys-common.properties
--- a/etl/src/main/resources/sql/flys-common.properties	Wed Aug 21 16:14:29 2013 +0200
+++ b/etl/src/main/resources/sql/flys-common.properties	Wed Aug 21 16:15:37 2013 +0200
@@ -7,7 +7,7 @@
     WHERE w.kind = 0 \
     GROUP BY r.id, r.name
 select.gauges = \
-    SELECT id, name, official_number \
+    SELECT id, name, official_number, station \
     FROM gauges \
     WHERE river_id = :river_id
 next.gauge.id = \


More information about the Dive4elements-commits mailing list