[PATCH] (issue1448) Fix info service for epoch / periods and off epoch

Wald Commits scm-commit at wald.intevation.org
Tue Sep 9 11:13:52 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1410254017 -7200
# Node ID f8ea1a7ecde67ae9c5b81f3a659960cf5bc88311
# Parent  a65afd85d516d485f127a99af7976accd7257183
(issue1448) Fix info service for epoch / periods and off epoch

    This also includes a bit cleanup to move the sqRelationTimeInterval check
    to the creation of the load list in SedimentLoadData allLoads.

diff -r a65afd85d516 -r f8ea1a7ecde6 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Tue Sep 09 10:53:50 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Tue Sep 09 11:13:37 2014 +0200
@@ -230,6 +230,36 @@
             }
         }
 
+        public void allOfficialLoads(Collection<Load> loads) {
+            for (List<Value> values: grainFractions) {
+                if (values != null) {
+                    for (Value value: values) {
+                        Load load = value.getLoad();
+                        if (load.getKind() == 1) {
+                            loads.add(value.getLoad());
+                        }
+                    }
+                }
+            }
+        }
+
+        public void allLoads(Collection<Load> loads, Integer sqRelationTimeInterval) {
+
+            for (List<Value> values: grainFractions) {
+                if (values == null) {
+                    continue;
+                }
+                for (Value value: values) {
+                    Load load = value.getLoad();
+                    Integer sqId = load.getSQRelationTimeIntervalId();
+                    if ((sqRelationTimeInterval == null)
+                        || sqId != null && sqId.equals(sqRelationTimeInterval)) {
+                        loads.add(load);
+                    }
+                }
+            }
+        }
+
         public double getStation() {
             return station;
         }
@@ -435,6 +465,25 @@
         }
     };
 
+    public static final Comparator<Load> LOAD_TI_CMP = new Comparator<Load>() {
+        @Override
+        public int compare(Load a, Load b) {
+            Date a_start = a.getStartTime();
+            Date a_stop = a.getStopTime();
+            Date b_start = b.getStartTime();
+            Date b_stop = b.getStopTime();
+            if (a_start == null && b_start == null) {
+                return 0;
+            } else if (a_start != null) {
+                return a_start.compareTo(b_start);
+            } else if (a_stop != null) {
+                return a_stop.compareTo(b_stop);
+            } else {
+                return 1;
+            }
+        }
+    };
+
     public static final Comparator<Load> LOAD_SQ_TI_CMP = new Comparator<Load>() {
         @Override
         public int compare(Load a, Load b) {
@@ -454,24 +503,29 @@
     };
 
     /** Find all loads in the range a/b with the according sq_time_interval */
-    public Collection<Load> findLoads(double a, double b, Integer sqRelationTimeInterval) {
+    public Collection<Load> findLoads(double a, double b, final Integer sqRelationTimeInterval) {
         final TreeSet<Load> loads = new TreeSet<Load>(LOAD_ID_CMP);
 
         findStations(a, b, new Visitor() {
             @Override
             public void visit(Station station) {
-                station.allLoads(loads);
+                station.allLoads(loads, sqRelationTimeInterval);
             }
         });
 
-        /* This may not be the most beautiful thing to do but well,.. */
-        for (Iterator<Load> it = loads.iterator(); it.hasNext();) {
-            Integer obj = it.next().getSQRelationTimeIntervalId();
-            if ((obj == null && sqRelationTimeInterval != null) ||
-                    (obj != null && !obj.equals(sqRelationTimeInterval))) {
-                it.remove();
+        return loads;
+    }
+
+    /** Find all official loads with a distinct time interval id */
+    public Collection<Load> findUniqueTiOfficialLoads(double a, double b) {
+        final TreeSet<Load> loads = new TreeSet<Load>(LOAD_TI_CMP);
+
+        findStations(a, b, new Visitor() {
+            @Override
+            public void visit(Station station) {
+                station.allOfficialLoads(loads);
             }
-        }
+        });
 
         return loads;
     }
diff -r a65afd85d516 -r f8ea1a7ecde6 artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java	Tue Sep 09 10:53:50 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java	Tue Sep 09 11:13:37 2014 +0200
@@ -85,8 +85,7 @@
         log.debug("Requested type: " + type + " with sq_ti_id: " + sq_ti_id);
         Collection <Load> loads;
         if (type.equals("off_epoch")) {
-            /* TODO */
-            loads = null;
+            loads = allLoadData.findUniqueTiOfficialLoads(fromD, toD);
         } else if (type.equals("sq_time_intervals")) {
             loads = allLoadData.findUniqueTimeIntervalLoads(fromD, toD);
 
@@ -99,12 +98,16 @@
         } else {
             if (!sq_ti_id.isEmpty()) {
                 Integer id = Integer.parseInt(sq_ti_id);
-                log.debug("Finding only items for id");
                 loads = allLoadData.findLoads(fromD, toD, id);
             } else {
-                log.debug("Finding everything.");
                 loads = allLoadData.findLoads(fromD, toD);
             }
+            for (Iterator<Load> it = loads.iterator(); it.hasNext();) {
+                /* Skip epochs . */
+                if (it.next().isEpoch()) {
+                    it.remove();
+                }
+            }
         }
 
         return buildDocument(loads);


More information about the Dive4Elements-commits mailing list