changeset 9105:ae3565385e6a

Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
author gernotbelger
date Tue, 29 May 2018 11:36:42 +0200
parents 07d51fd4864c
children ffd4e2b0381c
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java
diffstat 2 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java	Tue May 29 11:35:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java	Tue May 29 11:36:42 2018 +0200
@@ -18,6 +18,7 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.math.DoubleRange;
 import org.apache.commons.lang.math.NumberRange;
 import org.dive4elements.artifacts.CallContext;
@@ -67,12 +68,13 @@
         /* find relevant bed-heights */
         final List<BedHeight> defaultBedHeights = new DefaultBedHeights(river).getBedHeights(problems);
         final Collection<BedHeightsFinder> bedHeights = BedHeightsFinder.createTkhBedHeights(problems, calcRange, defaultBedHeights);
+        final double[] stations = extractStations(bedHeights);
 
         /* misuse winfo-artifact to calculate waterlevels in the same way */
         final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo);
 
         /* calculate waterlevels */
-        final WQKms[] kms = calculateWaterlevels(winfo, problems);
+        final WQKms[] kms = calculateWaterlevels(winfo, stations, problems);
 
         final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
 
@@ -97,6 +99,16 @@
         return new CalculationResult(results, problems);
     }
 
+    private double[] extractStations(final Collection<BedHeightsFinder> bedHeights) {
+
+        final Set<Double> allStations = new TreeSet<>();
+
+        for (final BedHeightsFinder bedHeight : bedHeights)
+            allStations.addAll(bedHeight.getStations());
+
+        return ArrayUtils.toPrimitive(allStations.toArray(new Double[allStations.size()]));
+    }
+
     /**
      * Calculation steps are simply the union of all stations of all involved bed-height datasets
      */
@@ -112,7 +124,10 @@
         return allStations;
     }
 
-    private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final Calculation problems) {
+    private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final double[] stations, final Calculation problems) {
+
+        // FIXME: we take kms from step, but instead we would like to take kms from bedheights
+        // FIXME: this will definitely break the serialization of the winfo artifact
 
         final CalculationResult waterlevelData = winfo.getWaterlevelData(this.context);
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java	Tue May 29 11:35:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java	Tue May 29 11:36:42 2018 +0200
@@ -53,8 +53,6 @@
 
         // "# Berechnungsgrundlage: Gleichung nach GILL (1971)"
         writeCSVMetaEntry(writer, CSV_META_CALCULATION_FORMULA);
-
-        writer.writeNext(new String[] { "" });
     }
 
     /**
@@ -85,15 +83,25 @@
     }
 
     @Override
-    // FIXME: rename
     protected void writeCSVResultMetadata(final CSVWriter writer, final TkhCalculationResults results, final TkhCalculationResult result) {
 
         final WstInfo wst = result.getWst();
         super.writeCSVWaterlevelMetadata(writer, wst);
-        writer.writeNext(new String[] { "" }); // break line
-        // FIXME:
+
+        // REAMRK:
         // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel)
         // "# Q (m³/s): " (nur bei Eingabe des Durchflusses)
+        // WaterlevelEXporter does this
+        // final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder((D4EArtifact) this.master,
+        // this.context);
+        // final String metadata = descBuilder.getMetadata();
+        // BUT:
+        // - the WINFO results do not contain this info per wst
+        // - the WaterlevelExporter prints this in the global header for all waterlevels, simply based on the input fields
+        // - instead we would want tis information per waterlevel
+        // - the metadata 'Bezeichnung WST' contains exactly the wanted data
+
+        writer.writeNext(new String[] { "" }); // break line
     }
 
     /**
@@ -166,5 +174,4 @@
             getLog().warn("Error generating PDF Report!", je);
         }
     }
-
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org