# HG changeset patch # User Sascha L. Teichmann # Date 1349092993 -7200 # Node ID ab3a4ad82ae11b08ccb59c7a60ecb9e345dc4fea # Parent 92719f122c772e454ae171164fd2c7f4d4926304 S(Q) accumulated same diameter meassurements per bank distance. diff -r 92719f122c77 -r ab3a4ad82ae1 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Oct 01 10:42:53 2012 +0200 +++ b/flys-artifacts/ChangeLog Mon Oct 01 14:03:13 2012 +0200 @@ -1,3 +1,18 @@ +2012-10-01 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java, + src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java: + Generate a second list of accumulated meassurements, + + * src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java: + Do not calculate the adjusted and sieve array for all measurements. + + * src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java: + Added diameter comparator. + + * src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java: + Copy the data if total load is zero. + 2012-10-01 Björn Ricks * src/main/java/de/intevation/flys/artifacts/states/StaticState.java: @@ -147,7 +162,7 @@ 2012-09-27 Sascha L. Teichmann - * src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java, + * src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java: Added more data fields from SedDB to calculate the fraction parts. src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java: diff -r 92719f122c77 -r ab3a4ad82ae1 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java Mon Oct 01 10:42:53 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java Mon Oct 01 14:03:13 2012 +0200 @@ -21,27 +21,12 @@ protected List sieves; - protected SieveArray sieveArray; - - protected Measurement prev; - protected Measurement next; - public Measurement() { } public Measurement(Map data, List sieves) { this.data = data; this.sieves = sieves; - adjustOriginalSieves(); - this.sieveArray = calculateSieveArray(); - } - - public Measurement head() { - Measurement current = this; - while (current.prev != null) { - current = current.prev; - } - return current; } protected double get(String name) { @@ -53,10 +38,14 @@ data.put(name, Double.valueOf(value)); } - protected Object getData(String name) { + public Object getData(String name) { return data.get(name); } + public Map getData() { + return data; + } + protected void putData(String name, Object value) { data.put(name, value); } @@ -189,7 +178,7 @@ } } - protected void adjustOriginalSieves() { + public void adjustSieves() { // If we already have an 8mm diameter sieve // we dont need to 'invent' it. diff -r 92719f122c77 -r ab3a4ad82ae1 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 10:42:53 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java Mon Oct 01 14:03:13 2012 +0200 @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.TreeMap; import de.intevation.flys.artifacts.model.DateRange; @@ -102,7 +103,7 @@ "COALESCE(gs.RSIEB17, 0) + COALESCE(gs.RSIEB18, 0) +" + "COALESCE(gs.RSIEB19, 0) + COALESCE(gs.RSIEB20, 0) +" + "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) > 0 " + - "ORDER BY m.DATUM, gp.LFDNR, g.UFERABST"; + "ORDER BY m.DATUM, g.UFERABST, g.GLOTRECHTEID, gp.LFDNR"; public static final class MeasurementResultTransformer extends BasicTransformerAdapter @@ -237,29 +238,70 @@ @SuppressWarnings("unchecked") List measuments = (List)query.list(); + List same = new ArrayList(); + Integer lastLR = null; - for (int i = 0, N = measuments.size(); i < N; ++i) { - Measurement m = measuments.get(i); + List accumulated = new ArrayList(); + + for (Measurement m: measuments) { Integer currentLR = (Integer)m.getData("GLOTRECHTEID"); boolean newDS = lastLR == null || (currentLR != null && !lastLR.equals(currentLR)); - Measurement p = i > 0 ? measuments.get(i-1) : null; - Measurement n = i < N-1 ? measuments.get(i+1) : null; - m.setPrev(newDS ? null : p); - m.setNext(n); - - if (p != null && newDS) { - p.setNext(null); + if (newDS && !same.isEmpty()) { + accumulated.add(accumulate(same)); + same.clear(); } lastLR = currentLR; } - return new Measurements(measuments); + if (!same.isEmpty()) { + accumulated.add(accumulate(same)); + } + + for (Measurement m: accumulated) { + m.adjustSieves(); + } + + return new Measurements(measuments, accumulated); + } + + protected static Measurement accumulate(List measuments) { + + int N = measuments.size(); + if (N == 1) { + return measuments.get(0); + } + + TreeMap diameters = + new TreeMap(Sieve.DIAMETER_CMP); + + for (Measurement m: measuments) { + for (Sieve s: m.getSieves()) { + Double key = s.getDiameter(); + double [] sum = diameters.get(key); + if (sum == null) { + sum = new double[1]; + diameters.put(key, sum); + } + sum[0] += s.getLoad(); + } + } + List accumulatedSieves = new ArrayList(diameters.size()); + for (Map.Entry entry: diameters.entrySet()) { + accumulatedSieves.add( + new Sieve(entry.getKey(), + entry.getValue()[0]/N)); + } + + Map data = + new HashMap(measuments.get(0).getData()); + + return new Measurement(data, accumulatedSieves); } public static Measurements getMeasurements( diff -r 92719f122c77 -r ab3a4ad82ae1 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java Mon Oct 01 10:42:53 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java Mon Oct 01 14:03:13 2012 +0200 @@ -9,6 +9,24 @@ { private static final Logger log = Logger.getLogger(Measurements.class); + /** + * Gets the accumulated for this instance. + * + * @return The accumulated. + */ + public List getAccumulated() { + return this.accumulated; + } + + /** + * Sets the accumulated for this instance. + * + * @param accumulated The accumulated. + */ + public void setAccumulated(List accumulated) { + this.accumulated = accumulated; + } + public interface SExtractor { double getS(Measurement measument); } // interface SExtractor @@ -56,12 +74,17 @@ }; protected List measuments; + protected List accumulated; public Measurements() { } - public Measurements(List measuments) { + public Measurements( + List measuments, + List accumulated + ) { this.measuments = measuments; + this.accumulated = accumulated; } public List extractSQ(SExtractor extractor) { diff -r 92719f122c77 -r ab3a4ad82ae1 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java Mon Oct 01 10:42:53 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java Mon Oct 01 14:03:13 2012 +0200 @@ -1,9 +1,22 @@ package de.intevation.flys.artifacts.model.sq; +import java.util.Comparator; + public class Sieve { public static final double EPSILON = 1e-6; + public static final Comparator DIAMETER_CMP = + new Comparator() { + @Override + public int compare(Double a, Double b) { + double diff = a - b; + if (diff < -EPSILON) return -1; + if (diff > EPSILON) return +1; + return 0; + } + }; + protected double diameter; protected double load; diff -r 92719f122c77 -r ab3a4ad82ae1 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 10:42:53 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java Mon Oct 01 14:03:13 2012 +0200 @@ -42,6 +42,7 @@ public void calculateNormLoads() { double total = totalLoad(); if (Math.abs(total) < EPSILON) { + System.arraycopy(loads, 0, normLoads, 0, loads.length); return; } total = 1d/total;