changeset 8057:555dc5a9b282

Sediment load: More on calculating epoch loads.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 16:05:21 +0200
parents d86cc6a17b7a
children fbe3ba5a480e
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java
diffstat 1 files changed, 41 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Fri Jul 18 15:37:26 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Fri Jul 18 16:05:21 2014 +0200
@@ -185,8 +185,8 @@
         int [] years  = null;
         int [][] epochs = null;
 
-        double from = access.getUpperKM();
-        double to   = access.getLowerKM();
+        double from = access.getLowerKM();
+        double to   = access.getUpperKM();
 
         if (yearEpoch.equals("year")) {
             years = access.getPeriod();
@@ -236,7 +236,6 @@
     }
 
     private CalculationResult calculateYears() {
-        boolean isKmUp = isKmUp();
         SedimentLoadData sld =
             SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
         if (sld == null) {
@@ -244,6 +243,7 @@
             return error("minfo.sediment.load.no.data");
         }
 
+        boolean isKmUp = isKmUp();
         Set<Integer> missingFractions = new TreeSet<Integer>();
 
         Not notEpochs = new Not(IsEpoch.INSTANCE);
@@ -267,15 +267,51 @@
                     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 calculateEpochs() {
-        // TODO: Implement me!
+        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(IsEpoch.INSTANCE)
+                .add(new TimeRangeIntersects(epoch[0], epoch[1]));
+
+            double scale = 1.0/(Math.max(epoch[0], epoch[1]) - Math.min(epoch[0], epoch[1]) + 1);
+
+            Sum sum = new Sum(scale);
+
+            for (GrainFraction gf: GRAIN_FRACTIONS) {
+                double [][] result = sum(
+                    sld, gf.getGrainFractions(), filter, sum, 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;
     }
 

http://dive4elements.wald.intevation.org