Mercurial > dive4elements > river
changeset 4005:22abdc45869c
Calculate S(Q) fractions
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 01 Oct 2012 18:32:27 +0200 |
parents | 3b79e8afca7e |
children | d4e39cc5c10c |
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 |
diffstat | 4 files changed, 97 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Oct 01 15:51:55 2012 +0200 +++ b/flys-artifacts/ChangeLog Mon Oct 01 18:32:27 2012 +0200 @@ -1,3 +1,15 @@ +2012-10-01 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + Finally calculate the S(Q) fractions. TODO: Split SQL into two queries. + + * src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java: + Make the fractions accessible. + + * src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java: + Calculate the fraction. + * flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java: + Store new measurements for fractions in separate list. + 2012-10-01 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java: @@ -5,15 +17,15 @@ 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/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.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java Mon Oct 01 15:51:55 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java Mon Oct 01 18:32:27 2012 +0200 @@ -69,18 +69,15 @@ } public double BL_G() { - // TODO: Implement me! - return Double.NaN; + return get("BL_G"); } public double BL_C() { - // TODO: Implement me! - return Double.NaN; + return get("BL_C"); } public double BL_S() { - // TODO: Implement me! - return Double.NaN; + return get("BL_S"); } public double S_BL_S() { @@ -181,7 +178,7 @@ sieves.add(new Sieve(4d, newFourValue)); } - public SieveArray calculateSieveArray() { + protected SieveArray calculateSieveArray() { SieveArray sa = new SieveArray();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java Mon Oct 01 15:51:55 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java Mon Oct 01 18:32:27 2012 +0200 @@ -1,6 +1,8 @@ package de.intevation.flys.artifacts.model.sq; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.TreeMap; @@ -269,7 +271,7 @@ m.adjustSieves(); } - return new Measurements(measuments, accumulated); + return new Measurements(measuments, separateByDate(accumulated)); } protected static List<Measurement> separateByDate(List<Measurement> measurements) { @@ -300,6 +302,7 @@ return result; } + protected static Measurement processSameDate(List<Measurement> measurements) { int N = measurements.size(); if (N == 1) { @@ -334,13 +337,48 @@ } } - return null; + double sumSandF = 0d; + double sumCoarseF = 0d; + double sumGravelF = 0d; + double sumNorm = 0d; + + for (Measurement m: measurements) { + SieveArray sa = m.getSieveArray(); + double sandF = sa.sandNormFraction(); + double coarseF = sa.coarseNormFraction(); + double gravelF = sa.gravelNormFraction(); + double effWidth = m.get("EFFWIDTH"); + double gt = m.get("GTRIEB"); + double scale = effWidth*gt; + sumSandF += scale*sandF; + sumCoarseF += scale*coarseF; + sumGravelF += scale*gravelF; + sumNorm += scale; + } + + Map<String, Object> data = + new HashMap<String, Object>(measurements.get(0).getData()); + + Measurement m = new Measurement(data, Collections.<Sieve>emptyList()); + + sumNorm = 1d/sumNorm; + + m.set("BL_S", sumNorm*sumSandF); + m.set("BL_G", sumNorm*sumGravelF); + m.set("BL_C", sumNorm*sumCoarseF); + + return m; } private static final boolean equalDate(Date a, Date b) { - // TODO: compare only year, month and day. - return a.equals(b); + Calendar ca = Calendar.getInstance(); + Calendar cb = Calendar.getInstance(); + ca.setTime(a); + cb.setTime(b); + return ca.get(Calendar.YEAR) == cb.get(Calendar.YEAR) + && ca.get(Calendar.MONTH) == cb.get(Calendar.MONTH) + && ca.get(Calendar.DAY_OF_MONTH) == cb.get(Calendar.DAY_OF_MONTH); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java Mon Oct 01 15:51:55 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurements.java Mon Oct 01 18:32:27 2012 +0200 @@ -9,24 +9,6 @@ { 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 @@ -87,8 +69,11 @@ this.accumulated = accumulated; } - public List<SQ> extractSQ(SExtractor extractor) { - List<SQ> result = new ArrayList(measuments.size()); + public static List<SQ> extractSQ( + List<Measurement> measuments, + SExtractor extractor + ) { + List<SQ> result = new ArrayList<SQ>(measuments.size()); for (Measurement measument: measuments) { SQ sq = new SQ(extractor.getS(measument), measument.Q()); if (sq.isValid()) { @@ -99,27 +84,27 @@ } public List<SQ> S_SF() { - return extractSQ(S_SF_EXTRACTOR); + return extractSQ(measuments, S_SF_EXTRACTOR); } public List<SQ> S_SS() { - return extractSQ(S_SS_EXTRACTOR); + return extractSQ(measuments, S_SS_EXTRACTOR); } public List<SQ> S_BL_S() { - return extractSQ(S_BL_S_EXTRACTOR); + return extractSQ(accumulated, S_BL_S_EXTRACTOR); } public List<SQ> S_BL_FG() { - return extractSQ(S_BL_FG_EXTRACTOR); + return extractSQ(accumulated, S_BL_FG_EXTRACTOR); } public List<SQ> S_BL_CG() { - return extractSQ(S_BL_CG_EXTRACTOR); + return extractSQ(accumulated, S_BL_CG_EXTRACTOR); } public List<SQ> S_BL() { - return extractSQ(S_BL_EXTRACTOR); + return extractSQ(accumulated, S_BL_EXTRACTOR); } public List<SQ> getSQs(int index) { @@ -135,6 +120,25 @@ return new ArrayList<SQ>(0); } + /** + * 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; + } + + @Override public String toString() { StringBuilder sb = new StringBuilder("Measurements [");