diff artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java @ 9451:fd6621f47a72

Bundu bzws density calculation completed
author mschaefer
date Thu, 23 Aug 2018 10:57:40 +0200
parents 7e1fb8d0cb0d
children be9bd06a1e3f
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java	Wed Aug 22 19:12:51 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java	Thu Aug 23 10:57:40 2018 +0200
@@ -38,6 +38,7 @@
 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder;
 import org.dive4elements.river.model.BedHeightValueType;
 import org.dive4elements.river.model.River;
+import org.dive4elements.river.utils.DoubleUtil;
 import org.dive4elements.river.utils.Formatter;
 
 class BezugswstCalculation {
@@ -120,14 +121,8 @@
         // Compute the missing volumes
         if (access.isCalculateMissingValue()) {
             computeMissingVolumes(problems);
-            final BedQualityCalculator bqCalculator = new BedQualityCalculator(this.context, bunduartifact);
-            final double[] kms = new double[] { this.missKmFrom.doubleValue(), this.missKmTo.doubleValue() };
-            final Calendar endDay = Calendar.getInstance();
-            endDay.set(access.getBezugsJahr().intValue(), 11, 31);
-            final Calendar startDay = Calendar.getInstance();
-            startDay.set(endDay.get(Calendar.YEAR) - 20, 0, 1);
-            // TODO final double[][] kmDensities = bqCalculator.execute(problems, river, kms, startDay.getTime(), endDay.getTime());
-            computeMissingMasses(problems);
+            final BedQualityCalculator bqCalculator = computeDensities(problems, bunduartifact, access, river);
+            computeMissingMasses(problems, bqCalculator);
         }
 
         // Add the result to the results collection
@@ -388,15 +383,33 @@
     }
 
     /**
+     * Create a density calculator and compute the densities of the missing volume km range and time period according to the
+     * reference year
+     */
+    private BedQualityCalculator computeDensities(final Calculation problems, final BUNDUArtifact bunduartifact, final BunduAccess access, final River river) {
+        final BedQualityCalculator bqCalculator = new BedQualityCalculator(this.context, bunduartifact);
+        // REMARK 10km tolerance at start and end to enable interpolation there
+        final double[] kms = DoubleUtil.explode(access.getMissingVolFrom().doubleValue() - 10.0, access.getMissingVolTo().doubleValue() + 10.0,
+                access.getStep().doubleValue() / 1000);
+        final Calendar endDay = Calendar.getInstance();
+        endDay.set(access.getBezugsJahr().intValue(), 11, 31);
+        final Calendar startDay = Calendar.getInstance();
+        // TODO Spezialregelung für den Rhein (bis 1999, 2000 bis 2009, ab 2010)
+        startDay.set(endDay.get(Calendar.YEAR) - 20, 0, 1);
+        bqCalculator.execute(problems, river, kms, startDay.getTime(), endDay.getTime());
+        return bqCalculator;
+    }
+
+    /**
      * Computes the missing masses
      */
-    private void computeMissingMasses(final Calculation problems) {
+    private void computeMissingMasses(final Calculation problems, final BedQualityCalculator densityFinder) {
         for (final ResultRow row : this.rows) {
             @SuppressWarnings("unchecked")
             final List<Double> volumes = (List<Double>) row.getValue(BunduResultType.missVolumeFields);
             if ((volumes == null) || Double.isNaN(volumes.get(0)))
                 continue;
-            final double density = getDensity(row.getDoubleValue(GeneralResultType.station));
+            final double density = getDensity(row.getDoubleValue(GeneralResultType.station), densityFinder);
             final List<Double> masses = new ArrayList<>();
             double kmTotal = 0.0;
             for (int j = BedHeightValueType.FIELD_FIRST_INDEX; j <= BedHeightValueType.FIELD_LAST_INDEX; j++) {
@@ -470,8 +483,11 @@
         return missRows;
     }
 
-    private double getDensity(final double km) {
-        return 1.73; // TODO
+    /**
+     * Gets the density of a km from the densities calculation
+     */
+    private double getDensity(final double km, final BedQualityCalculator densityFinder) {
+        return densityFinder.getDensity(km);
     }
 
     /**

http://dive4elements.wald.intevation.org