# HG changeset patch # User Sascha L. Teichmann # Date 1349099515 -7200 # Node ID 3b79e8afca7e7b138d142dc6442bfed9cd684aa5 # Parent 4d74a579c5c5ab4776ff3628829f45091d8ca3de S(Q) calculate effective width diff -r 4d74a579c5c5 -r 3b79e8afca7e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java --- 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 separateByDate(List measurements) { + + List result = new ArrayList(); + + List same = new ArrayList(); + + 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 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 measuments) { int N = measuments.size(); diff -r 4d74a579c5c5 -r 3b79e8afca7e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java --- 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 :