[PATCH] Sediment load: More of official epochs
Wald Commits
scm-commit at wald.intevation.org
Fri Jul 18 18:55:44 CEST 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1405702539 -7200
# Node ID 25feef564d094939d297b3e6adba5b4cd98b05e8
# Parent bde5f5ec7c72611dcee58864f43c65be796b0bcb
Sediment load: More of official epochs.
diff -r bde5f5ec7c72 -r 25feef564d09 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java Fri Jul 18 18:01:49 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java Fri Jul 18 18:55:39 2014 +0200
@@ -21,6 +21,7 @@
import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station;
import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.And;
import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsEpoch;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsOfficial;
import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.Not;
import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.TimeRangeIntersects;
import org.dive4elements.river.model.River;
@@ -125,31 +126,22 @@
GrainFraction.make("minfo.susp.sediment.flys", SUSP_SEDIMENT_FLYS),
};
- public static final class Sum implements Value.Visitor {
+ public static class Sum implements Value.Visitor {
- private int n;
- private double sum;
- private double scale;
+ protected int n;
+ protected double sum;
public Sum() {
}
- public Sum(double scale) {
- this.scale = scale;
- }
-
public double getSum() {
- return sum * scale;
+ return sum;
}
public int getN() {
return n;
}
- public double getScale() {
- return scale;
- }
-
public void reset() {
n = 0;
sum = 0.0;
@@ -160,7 +152,17 @@
sum += value.getValue();
++n;
}
- } // class Aggregate
+ } // class Sum
+
+ public static final class Avg extends Sum {
+ public Avg() {
+ }
+
+ @Override
+ public double getSum() {
+ return n == 0 ? 0.0 : sum/(double)n;
+ }
+ } // class Sum
private String river;
@@ -286,14 +288,53 @@
boolean isKmUp = isKmUp();
Set<Integer> missingFractions = new TreeSet<Integer>();
+ // They are not epochs, they are single years!
+ Not notEpochs = new Not(IsEpoch.INSTANCE);
+
for (int [] epoch: epochs) {
Value.Filter filter = new And()
- .add(IsEpoch.INSTANCE)
+ .add(notEpochs)
.add(new TimeRangeIntersects(epoch[0], epoch[1]));
- double scale = 1.0/(Math.max(epoch[0], epoch[1]) - Math.min(epoch[0], epoch[1]) + 1);
+ Avg avg = new Avg();
- Sum sum = new Sum(scale);
+ for (GrainFraction gf: GRAIN_FRACTIONS) {
+ double [][] result = sum(
+ sld, gf.getGrainFractions(), filter, avg, isKmUp,
+ missingFractions);
+
+ if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) {
+ // TODO: resolve i18n
+ addProblem("minfo.sediment.load.no.fractions",
+ gf.getDescription());
+ continue;
+ }
+ // TODO: Generate result data set for calculation.
+ // TODO: Optionally transform units.
+ }
+ }
+ // TODO: Generate messages for missing fractions.
+ // TODO: Bundle sub results.
+ return null;
+ }
+
+ private CalculationResult calculateOffEpochs() {
+ SedimentLoadData sld =
+ SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
+ if (sld == null) {
+ // TODO: i18n
+ return error("minfo.sediment.load.no.data");
+ }
+
+ boolean isKmUp = isKmUp();
+ Set<Integer> missingFractions = new TreeSet<Integer>();
+
+ for (int [] epoch: epochs) {
+ Value.Filter filter = new And()
+ .add(IsOfficial.INSTANCE)
+ .add(new TimeRangeIntersects(epoch[0], epoch[1]));
+
+ Sum sum = new Sum();
for (GrainFraction gf: GRAIN_FRACTIONS) {
double [][] result = sum(
@@ -312,10 +353,6 @@
}
// TODO: Generate messages for missing fractions.
// TODO: Bundle sub results.
- return null;
- }
-
- private CalculationResult calculateOffEpochs() {
// TODO: Implement me!
return null;
}
diff -r bde5f5ec7c72 -r 25feef564d09 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java Fri Jul 18 18:01:49 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java Fri Jul 18 18:55:39 2014 +0200
@@ -143,6 +143,7 @@
this.b = b;
}
}
+
@Override
public boolean accept(Value value) {
Date c = value.getLoad().getStartTime();
@@ -152,6 +153,19 @@
: !(a.after(d) || c.after(b));
}
} // class TimeRangeIntersects
+
+ public static final class IsOfficial implements Filter {
+
+ public static final IsOfficial INSTANCE = new IsOfficial();
+
+ private IsOfficial() {
+ }
+
+ @Override
+ public boolean accept(Value value) {
+ return value.getLoad().getKind() == 1;
+ }
+ } // class IsOfficial
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4Elements-commits
mailing list