changeset 4004:3b79e8afca7e

S(Q) calculate effective width
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 01 Oct 2012 15:51:55 +0200
parents 4d74a579c5c5
children 22abdc45869c
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java
diffstat 2 files changed, 98 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java	Mon Oct 01 14:51:25 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java	Mon Oct 01 15:51:55 2012 +0200
@@ -1,6 +1,7 @@
 package de.intevation.flys.artifacts.model.sq;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.TreeMap;
 
@@ -91,6 +92,7 @@
             "AND s.KM BETWEEN :location - 0.001 AND :location + 0.001 " +
             "AND m.DATUM BETWEEN :from AND :to " +
             "AND m.TGESCHIEBE IS NOT NULL " +
+            "AND m.DATUM IS NOT NULL " +
             "AND (" +
                 "COALESCE(gs.RSIEB01, 0) + COALESCE(gs.RSIEB02, 0) +" +
                 "COALESCE(gs.RSIEB03, 0) + COALESCE(gs.RSIEB04, 0) +" +
@@ -270,6 +272,78 @@
         return new Measurements(measuments, accumulated);
     }
 
+    protected static List<Measurement> separateByDate(List<Measurement> measurements) {
+
+        List<Measurement> result = new ArrayList<Measurement>();
+
+        List<Measurement> same = new ArrayList<Measurement>();
+
+        Date lastDate = null;
+
+        for (Measurement m: measurements) {
+            Date currentDate = (Date)m.getData("DATUM");
+            if ((lastDate == null
+            || !equalDate(currentDate, lastDate))
+            && !same.isEmpty()
+            ) {
+                result.add(processSameDate(same));
+                same.clear();
+            }
+            same.add(m);
+            lastDate = currentDate;
+        }
+
+        if (!same.isEmpty()) {
+            result.add(processSameDate(same));
+        }
+
+        return result;
+    }
+
+    protected static Measurement processSameDate(List<Measurement> measurements) {
+        int N = measurements.size();
+        if (N == 1) {
+            Measurement current = measurements.get(0);
+            double left = current.get("UFERABLINKS");
+            double right = current.get("UFERABST");
+            current.set("EFFWIDTH", left + right);
+        }
+        else {
+            for (int i = 0; i < N; ++i) {
+                Measurement current = measurements.get(i);
+
+                if (i == 0) {
+                    Measurement next = measurements.get(i+1);
+                    double distCurrent = current.get("UFERABST");
+                    double distNext = next.get("UFERABST");
+                    current.set("EFFWIDTH", distNext - distCurrent);
+                }
+                else if (i == N-1) {
+                    Measurement prev = measurements.get(i-1);
+                    double distCurrent = current.get("UFERABST");
+                    double distPrev = prev.get("UFERABST");
+                    current.set("EFFWIDTH", distCurrent - distPrev);
+                }
+                else {
+                    Measurement prev = measurements.get(i-1);
+                    Measurement next = measurements.get(i+1);
+                    double distPrev = prev.get("UFERABST");
+                    double distNext = next.get("UFERABST");
+                    current.set("EFFWIDTH", 0.5*(distNext - distPrev));
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    private static final boolean equalDate(Date a, Date b) {
+        // TODO: compare only year, month and day.
+        return a.equals(b);
+    }
+
+
     protected static Measurement accumulate(List<Measurement> measuments) {
 
         int N = measuments.size();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java	Mon Oct 01 14:51:25 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java	Mon Oct 01 15:51:55 2012 +0200
@@ -88,5 +88,29 @@
     public double getNormLoads(int index) {
         return this.normLoads[index];
     }
+
+    public double sandNormFraction() {
+        double sum = 0d;
+        for (int i = 8; i < normLoads.length; ++i) {
+            sum += normLoads[i];
+        }
+        return sum;
+    }
+
+    public double coarseNormFraction() {
+        double sum = 0d;
+        for (int i = 0; i < 4; ++i) {
+            sum += normLoads[i];
+        }
+        return sum;
+    }
+
+    public double gravelNormFraction() {
+        double sum = 0d;
+        for (int i = 4; i < 8; ++i) {
+            sum += normLoads[i];
+        }
+        return sum;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org