Mercurial > dive4elements > river
changeset 4001:ab3a4ad82ae1
S(Q) accumulated same diameter meassurements per bank distance.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 01 Oct 2012 14:03:13 +0200 |
parents | 92719f122c77 |
children | fdc6b1e64d01 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java |
diffstat | 6 files changed, 113 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- 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 <sascha.teichmann@intevation.de> + + * 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 <bjoern.ricks@intevation.de> * src/main/java/de/intevation/flys/artifacts/states/StaticState.java: @@ -147,7 +162,7 @@ 2012-09-27 Sascha L. Teichmann <sascha.teichmann@intevation.de> - * 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:
--- 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<Sieve> sieves; - protected SieveArray sieveArray; - - protected Measurement prev; - protected Measurement next; - public Measurement() { } public Measurement(Map<String, Object> data, List<Sieve> 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<String, Object> 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.
--- 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<Measurement> measuments = (List<Measurement>)query.list(); + List<Measurement> same = new ArrayList<Measurement>(); + Integer lastLR = null; - for (int i = 0, N = measuments.size(); i < N; ++i) { - Measurement m = measuments.get(i); + List<Measurement> accumulated = new ArrayList<Measurement>(); + + 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<Measurement> measuments) { + + int N = measuments.size(); + if (N == 1) { + return measuments.get(0); + } + + TreeMap<Double, double []> diameters = + new TreeMap<Double, double []>(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<Sieve> accumulatedSieves = new ArrayList<Sieve>(diameters.size()); + for (Map.Entry<Double, double []> entry: diameters.entrySet()) { + accumulatedSieves.add( + new Sieve(entry.getKey(), + entry.getValue()[0]/N)); + } + + Map<String, Object> data = + new HashMap<String, Object>(measuments.get(0).getData()); + + return new Measurement(data, accumulatedSieves); } public static Measurements getMeasurements(
--- 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<Measurement> getAccumulated() { + return this.accumulated; + } + + /** + * Sets the accumulated for this instance. + * + * @param accumulated The accumulated. + */ + public void setAccumulated(List<Measurement> accumulated) { + this.accumulated = accumulated; + } + public interface SExtractor { double getS(Measurement measument); } // interface SExtractor @@ -56,12 +74,17 @@ }; protected List<Measurement> measuments; + protected List<Measurement> accumulated; public Measurements() { } - public Measurements(List<Measurement> measuments) { + public Measurements( + List<Measurement> measuments, + List<Measurement> accumulated + ) { this.measuments = measuments; + this.accumulated = accumulated; } public List<SQ> extractSQ(SExtractor extractor) {
--- 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<Double> DIAMETER_CMP = + new Comparator<Double>() { + @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;
--- 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;