changeset 8052:1dae69eff79d

Sediment load: take arguments from sediment access.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 11:16:50 +0200
parents 9dce39cffab3
children 72760ca2fc2b
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java
diffstat 1 files changed, 56 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Fri Jul 18 11:05:34 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Fri Jul 18 11:16:50 2014 +0200
@@ -82,7 +82,7 @@
 
     public static final class Sum implements Value.Visitor {
 
-        private int n;
+        private int    n;
         private double sum;
         private double scale;
 
@@ -118,17 +118,70 @@
     } // class Aggregate
 
 
+    private String   river;
+    private String   yearEpoch;
+    private String   unit;
+    private int [][] epoch;
+    private int []   period;
+    private double   from;
+    private double   to;
+
+
     public SedimentLoadDataCalculation() {
     }
 
     public CalculationResult calculate(SedimentLoadAccess access) {
         log.info("SedimentLoadDataCalculation.calculate");
+
+        String river     = access.getRiverName();
+        String yearEpoch = access.getYearEpoch();
+        String unit      = access.getUnit();
+
+        int [] period  = null;
+        int [][] epoch = null;
+
+        double from = access.getUpperKM();
+        double to   = access.getLowerKM();
+
+        if (yearEpoch.equals("year")) {
+            period = access.getPeriod();
+        }
+        else if (yearEpoch.equals("epoch") || yearEpoch.equals("off_epoch")) {
+            epoch = access.getEpochs();
+        }
+        else {
+            addProblem("minfo.missing.year_epoch");
+        }
+
+        if (river == null) {
+            // TODO: i18n
+            addProblem("minfo.missing.river");
+        }
+
+        if (period == null && epoch == null) {
+            addProblem("minfo.missing.time");
+        }
+
+        if (!hasProblems()) {
+            this.river     = river;
+            this.yearEpoch = yearEpoch;
+            this.unit      = unit;
+            this.period    = period;
+            this.epoch     = epoch;
+            this.from      = from;
+            this.to        = to;
+            return internalCalculate();
+        }
+
+        return new CalculationResult();
+    }
+
+    private CalculationResult internalCalculate() {
         // TODO: Implement me!
-
         return null;
     }
 
-    private static double sum(double [] values) {
+    private static final double sum(double [] values) {
         double sum = 0.0;
         for (double value: values) {
             sum += value;
@@ -138,8 +191,6 @@
 
     public double[][] sum(
         SedimentLoadData sld,
-        double           from,
-        double           to,
         int []           grainFractions,
         Value.Filter     filter,
         Sum              sum,

http://dive4elements.wald.intevation.org