[PATCH] Let epochs be averages over their years

Wald Commits scm-commit at wald.intevation.org
Tue Sep 2 17:47:07 CEST 2014


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1409672823 -7200
# Node ID 7b0b3b1a2ee81a042398191260db80b810c8303a
# Parent  d2673ca68e70a229fc8015506c51e7f270de7c37
Let epochs be averages over their years.

diff -r d2673ca68e70 -r 7b0b3b1a2ee8 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	Tue Sep 02 17:10:22 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Tue Sep 02 17:47:03 2014 +0200
@@ -105,7 +105,6 @@
     } // class GrainFraction
 
     public static final GrainFraction [] GRAIN_FRACTIONS = {
-        // TODO: i18n for bfg parts
         // Grain fraction names are alignt to the grain_fractions table
         GrainFraction.make("total",              TOTAL_LOAD),
         GrainFraction.make("bed_load",           BED_LOAD),
@@ -285,26 +284,28 @@
         boolean isKmUp = isKmUp();
         Set<Integer> missingFractions = new TreeSet<Integer>();
 
+        Sum sum = new Sum();
+
         SedimentDensity sd = getSedimentDensity();
 
         // They are not epochs, they are single years!
         Not notEpochs = new Not(IsEpoch.INSTANCE);
 
         for (int [] epoch: epochs) {
-            List<double [][]> results = new ArrayList<double [][]>();
-
             int min = Math.min(epoch[0], epoch[1]);
             int max = Math.max(epoch[0], epoch[1]);
 
             String period = Integer.toString(epoch[0]) + " - " +
                 Integer.toString(epoch[1]);
-            for (int year = min; year <= max; ++year) {
-                Value.Filter filter = new And(notEpochs)
-                    .add(new TimeRangeIntersects(year));
 
-                Sum sum = new Sum();
+            for (GrainFraction gf: GRAIN_FRACTIONS) {
 
-                for (GrainFraction gf: GRAIN_FRACTIONS) {
+                List<double [][]> results = new ArrayList<double [][]>();
+
+                for (int year = min; year <= max; ++year) {
+                    Value.Filter filter = new And(notEpochs)
+                        .add(new TimeRangeIntersects(year));
+
                     double [][] result = sum(
                         sld, gf.getGrainFractions(), filter, sum, isKmUp,
                         missingFractions);
@@ -319,13 +320,15 @@
                     transformT2M3(sd, year, result);
                     results.add(result);
                 }
+
+                double [][] result = average(results);
+
+                SedimentLoadDataResult.Fraction sldrf =
+                    new SedimentLoadDataResult.Fraction(gf.getDescription(),
+                                                        result, period);
+                sldr.addFraction(sldrf);
             }
 
-            double [][] result = average(results);
-            // TODO: Optionally transform units.
-            SedimentLoadDataResult.Fraction sldrf =
-                new SedimentLoadDataResult.Fraction("TODO: nice description", result, period);
-            sldr.addFraction(sldrf);
         }
         // TODO: Generate messages for missing fractions.
         return new CalculationResult(sldr, this);
@@ -484,7 +487,7 @@
             for (int i = 0; i < kms.length; ++i) {
                 double km = kms[i];
                 double v = vs[i];
-                if (Double.isNaN(km) || Double.isNaN(v)) {
+                if (Double.isNaN(km)) {
                     continue;
                 }
                 XSum xsum = map.get(km);
@@ -498,12 +501,12 @@
         double [][] result = new double[2][map.size()];
         int i = 0;
         for (Map.Entry<Double, XSum> entry: map.entrySet()) {
-            result[i][0] = entry.getKey();
-            result[i][1] = entry.getValue().avg();
+            result[0][i] = entry.getKey();
+            result[1][i] = entry.getValue().avg();
             ++i;
         }
 
-        return null;
+        return result;
     }
 
 }


More information about the Dive4Elements-commits mailing list