[PATCH] Amtl. Linien: Fixed problem that only a random official line is detect

Wald Commits scm-commit at wald.intevation.org
Fri Jun 28 12:52:56 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1372416771 -7200
# Node ID 1e97d2e95410e7b8ed02150d8c06b5f69adc467f
# Parent  c740a4815bb28efaf1cfaa32ebd25f3443c96d19
Amtl. Linien: Fixed problem that only a random official line is detect.

diff -r c740a4815bb2 -r 1e97d2e95410 artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java	Fri Jun 28 11:25:41 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java	Fri Jun 28 12:52:51 2013 +0200
@@ -17,6 +17,7 @@
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
+import org.apache.log4j.Logger;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.cache.CacheFactory;
 import org.dive4elements.river.model.Gauge;
@@ -31,6 +32,8 @@
 {
     public static final String CACHE_NAME = "official-lines";
 
+    private static Logger log = Logger.getLogger(OfficialLineFinder.class);
+
     // We will only have one entry in this cache.
     public static final String CACHE_KEY = CACHE_NAME;
 
@@ -87,6 +90,14 @@
             ValueRange r = (ValueRange)o;
             return wstId == r.wstId && columnPos == r.columnPos;
         }
+
+        @Override
+        public String toString() {
+            return "[" + name +
+                " value: " + value +
+                " wstId: " + wstId +
+                " pos: " + columnPos + "]";
+        }
     }
 
     public OfficialLineFinder() {
@@ -115,14 +126,16 @@
 
     public static Map<String, List<ValueRange>> getAllUncached() {
 
+        boolean debug = log.isDebugEnabled();
+
         Map<String, List<ValueRange>> rivers2officialLines =
             new HashMap<String, List<ValueRange>>();
 
-
         for (OfficialLine line: OfficialLine.fetchAllOfficalLines()) {
-            String   name = line.getNamedMainValue().getName();
-            WstColumn wc  = line.getWstColumn();
-            Wst       wst = wc.getWst();
+            NamedMainValue nmv = line.getNamedMainValue();
+            Integer   mnvId    = nmv.getId();
+            WstColumn wc       = line.getWstColumn();
+            Wst       wst      = wc.getWst();
 
             List<ValueRange> ranges = new ArrayList<ValueRange>();
 
@@ -131,17 +144,24 @@
             for (Gauge gauge: gauges) {
                 List<MainValue> mainValues = gauge.getMainValues();
                 for (MainValue mainValue: mainValues) {
-                    NamedMainValue nmv = mainValue.getMainValue();
-                    if (nmv.getName().equalsIgnoreCase(name)) {
+                    NamedMainValue tnmv = mainValue.getMainValue();
+                    if (tnmv.getId().equals(mnvId)) {
                         // found gauge with this main value
 
-                        double from = gauge.getRange().getA().doubleValue();
-                        double to   = gauge.getRange().getA().doubleValue();
+                        double from  = gauge.getRange().getA().doubleValue();
+                        double to    = gauge.getRange().getA().doubleValue();
                         double value = mainValue.getValue().doubleValue();
                         int    wstId = wst.getId();
                         int    pos   = wc.getPosition();
-                        ValueRange range =
-                            new ValueRange(from, to, value, wstId, pos, name);
+                        ValueRange range = new ValueRange(
+                            from, to, value, wstId, pos, nmv.getName());
+
+                        if (debug) {
+                            log.debug(
+                                "river: " + river.getName() +
+                                " gauge: " + gauge.getName() +
+                                " ol: " + range);
+                        }
                         ranges.add(range);
                         break;
                     }
@@ -149,7 +169,14 @@
             }
 
             if (!ranges.isEmpty()) {
-                rivers2officialLines.put(river.getName(), ranges);
+                String rname = river.getName();
+                List<ValueRange> old = rivers2officialLines.get(rname);
+                if (old != null) {
+                    old.addAll(ranges);
+                }
+                else {
+                    rivers2officialLines.put(rname, ranges);
+                }
             }
         }
 
@@ -163,11 +190,19 @@
     }
 
     public static Range extractRange(D4EArtifact artifact) {
+
         String mode      = nn(artifact.getDataAsString("ld_mode"));
         String locations = nn(artifact.getDataAsString("ld_locations"));
         String from      = nn(artifact.getDataAsString("ld_from"));
         String to        = nn(artifact.getDataAsString("ld_to"));
 
+        if (log.isDebugEnabled()) {
+            log.debug("ld_mode: '" + mode + "'");
+            log.debug("ld_locations: '" + locations + "'");
+            log.debug("ld_from: '" + from + "'");
+            log.debug("ld_to: '" + to + "'");
+        }
+
         if (mode.equals("location")) {
             try {
                 String loc = locations.replace(" ", "");
@@ -309,9 +344,18 @@
         if (ranges == null) {
             return Collections.<ValueRange>emptyList();
         }
+        boolean debug = log.isDebugEnabled();
+
+        if (debug) {
+            log.debug("Before range filter:" + ranges);
+        }
 
         ranges = filterByRange(extractRange(artifact), ranges);
 
+        if (debug) {
+            log.debug("After range filter:" + ranges);
+        }
+
         if (ranges.isEmpty()) {
             return Collections.<ValueRange>emptyList();
         }
@@ -324,6 +368,16 @@
             qRange = tripleQRange(artifact);
         }
 
-        return filterByQRange(qRange, ranges);
+        if (debug) {
+            log.debug("Q range filter: " + qRange);
+        }
+
+        ranges = filterByQRange(qRange, ranges);
+
+        if (debug) {
+            log.debug("After q range filter: " + ranges);
+        }
+
+        return ranges;
     }
 }
diff -r c740a4815bb2 -r 1e97d2e95410 artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java	Fri Jun 28 11:25:41 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java	Fri Jun 28 12:52:51 2013 +0200
@@ -111,5 +111,9 @@
     public Object clone() {
         return new Range(this.start, this.end);
     }
+
+    public String toString() {
+        return "[Range: start=" + start + " end=" + end + "]";
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list