[PATCH] Sediment load: transform units for official epochs, too

Wald Commits scm-commit at wald.intevation.org
Thu Jul 31 18:14:26 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1406823262 -7200
# Node ID 9ecd6267323be18c67621bbd43fc4682905a873a
# Parent  6d24ba2ac96409cc2eb0310dc2141bf6d1abd7b9
Sediment load: transform units for official epochs, too.

diff -r 6d24ba2ac964 -r 9ecd6267323b 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	Thu Jul 31 17:04:41 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Thu Jul 31 18:14:22 2014 +0200
@@ -249,8 +249,7 @@
         SedimentDensity sd = getSedimentDensity();
 
         for (int year: years) {
-            Value.Filter filter = new And()
-                .add(notEpochs)
+            Value.Filter filter = new And(notEpochs)
                 .add(new TimeRangeIntersects(year));
 
             for (GrainFraction gf: GRAIN_FRACTIONS) {
@@ -303,8 +302,7 @@
             int max = Math.max(epoch[0], epoch[1]);
 
             for (int year = min; year <= max; ++year) {
-                Value.Filter filter = new And()
-                    .add(notEpochs)
+                Value.Filter filter = new And(notEpochs)
                     .add(new TimeRangeIntersects(year));
 
                 Sum sum = new Sum();
@@ -346,14 +344,17 @@
 
         SedimentLoadDataResult sldr = new SedimentLoadDataResult();
 
+        SedimentDensity sd = getSedimentDensity();
+
         boolean isKmUp = isKmUp();
         Set<Integer> missingFractions = new TreeSet<Integer>();
 
         for (int [] epoch: epochs) {
-            Value.Filter filter = new And()
-                .add(IsOfficial.INSTANCE)
+            Value.Filter filter = new And(IsOfficial.INSTANCE)
                 .add(new TimeRangeIntersects(epoch[0], epoch[1]));
 
+            int year = Math.min(epoch[0], epoch[1]);
+
             Sum sum = new Sum();
 
             for (GrainFraction gf: GRAIN_FRACTIONS) {
@@ -367,7 +368,7 @@
                         gf.getDescription());
                     continue;
                 }
-                // TODO: Optionally transform units.
+                transformT2M3(sd, year, result);
                 SedimentLoadDataResult.Fraction sldrf =
                     new SedimentLoadDataResult.Fraction(gf.getDescription(), result);
                 sldr.addFraction(sldrf);
@@ -378,7 +379,7 @@
     }
 
     /** Figure out flow direction of river. */
-    private boolean isKmUp() {
+    private final boolean isKmUp() {
         River r = RiverFactory.getRiver(river);
         if (r == null) {
             addProblem("minfo.missing.river");
diff -r 6d24ba2ac964 -r 9ecd6267323b 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	Thu Jul 31 17:04:41 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java	Thu Jul 31 18:14:22 2014 +0200
@@ -41,6 +41,11 @@
             filters = new ArrayList<Filter>();
         }
 
+        public Composite(Filter filter) {
+            this();
+            add(filter);
+        }
+
         public Composite add(Filter filter) {
             filters.add(filter);
             return this;
@@ -52,6 +57,10 @@
         public And() {
         }
 
+        public And(Filter filter) {
+            super(filter);
+        }
+
         @Override
         public boolean accept(Value value) {
             for (Filter filter: filters) {
@@ -68,6 +77,10 @@
         public Or() {
         }
 
+        public Or(Composite filter) {
+            super(filter);
+        }
+
         @Override
         public boolean accept(Value value) {
             for (Filter filter: filters) {


More information about the Dive4Elements-commits mailing list