changeset 8053:72760ca2fc2b

Sediment load: dispatch calculation modes.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 11:58:59 +0200
parents 1dae69eff79d
children db4e6bd367a6
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java
diffstat 3 files changed, 67 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Fri Jul 18 11:16:50 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java	Fri Jul 18 11:58:59 2014 +0200
@@ -13,10 +13,13 @@
 import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
 import org.dive4elements.river.artifacts.model.Calculation;
 import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.RiverFactory;
 import org.apache.log4j.Logger;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station;
+import org.dive4elements.river.model.River;
+import org.dive4elements.river.utils.DoubleUtil;
 
 public class SedimentLoadDataCalculation
 extends      Calculation
@@ -173,20 +176,43 @@
             return internalCalculate();
         }
 
-        return new CalculationResult();
+        return new CalculationResult(this);
     }
 
     private CalculationResult internalCalculate() {
+        if ("year".equals(yearEpoch))      return calculateYears();
+        if ("epoch".equals(yearEpoch))     return calculateEpochs();
+        if ("off_epoch".equals(yearEpoch)) return calculateOffEpochs();
+
+        // TODO: i18n
+        addProblem("minfo.sediment.load.unknown.calc.mode");
+
+        return new CalculationResult(this);
+    }
+
+    private CalculationResult calculateYears() {
         // TODO: Implement me!
         return null;
     }
 
-    private static final double sum(double [] values) {
-        double sum = 0.0;
-        for (double value: values) {
-            sum += value;
+    private CalculationResult calculateEpochs() {
+        // TODO: Implement me!
+        return null;
+    }
+
+    private CalculationResult calculateOffEpochs() {
+        // TODO: Implement me!
+        return null;
+    }
+
+    /** Figure out flow direction of river. */
+    private boolean isKmUp() {
+        River r = RiverFactory.getRiver(river);
+        if (r == null) {
+            addProblem("minfo.missing.river");
+            return true;
         }
-        return sum;
+        return r.getKmUp();
     }
 
     public double[][] sum(
@@ -228,7 +254,7 @@
                 }
             }
             result[0][j] = station.getStation();
-            result[1][j] = sum(values);
+            result[1][j] = DoubleUtil.sum(values);
         }
 
         // TODO: Handle 'virtual' measument stations 'from' and 'to'.
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java	Fri Jul 18 11:16:50 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataValueFilter.java	Fri Jul 18 11:58:59 2014 +0200
@@ -98,6 +98,23 @@
         private Date a;
         private Date b;
 
+        public TimeRangeIntersects(int startYear, int endYear) {
+            this(firstJan(Math.min(startYear, endYear)),
+                lastDec(Math.max(startYear, endYear)));
+        }
+
+        private static Date firstJan(int year) {
+            Calendar cal = Calendar.getInstance();
+            cal.set(year, 1, 1, 0, 0, 0);
+            return cal.getTime();
+        }
+
+        private static Date lastDec(int year) {
+            Calendar cal = Calendar.getInstance();
+            cal.set(year, 12, 31, 23, 59, 59);
+            return cal.getTime();
+        }
+
         public TimeRangeIntersects(Date a, Date b) {
             if (a.after(b)) {
                 this.b = a;
--- a/artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java	Fri Jul 18 11:16:50 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java	Fri Jul 18 11:58:59 2014 +0200
@@ -171,6 +171,14 @@
         return out;
     }
 
+    public static final double sum(double [] values) {
+        double sum = 0.0;
+        for (double value: values) {
+            sum += value;
+        }
+        return sum;
+    }
+
     public static final double [] fill(int N, double value) {
         double [] result = new double[N];
         Arrays.fill(result, value);
@@ -234,6 +242,15 @@
         return true;
     }
 
+    public static final boolean isNaN(double [] values) {
+        for (double value: values) {
+            if (!Double.isNaN(value)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     /** In an array of doubles, search and return the maximum value. */
     public static final double maxInArray(double[] values) {
         double max = - Double.MAX_VALUE;

http://dive4elements.wald.intevation.org