diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureFacet.java @ 9266:465347d12990

Station specific calculation of flood duration curve and infrastructure annotations
author mschaefer
date Wed, 18 Jul 2018 12:20:01 +0200
parents 66b003701546
children 83ebeb620b5a
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureFacet.java	Tue Jul 17 19:48:28 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureFacet.java	Wed Jul 18 12:20:01 2018 +0200
@@ -10,7 +10,8 @@
 
 package org.dive4elements.river.artifacts.sinfo.flood_duration;
 
-import java.util.ArrayList;
+import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM;
+
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -60,17 +61,42 @@
 
         final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
 
-        final List<StickyAxisAnnotation> annotations = new ArrayList<>();
-        annotations.add(data.getInfrastructureWAnnotation());
-        annotations.add(data.getInfrastructureQAnnotation());
-        if (annotations.get(0) != null) {
-            this.description = annotations.get(0).getText(); // TODO Diagramm-Aktualisierung auslösen
+        // final List<StickyAxisAnnotation> annotations = new ArrayList<>();
+        // annotations.add(data.getInfrastructureWAnnotation());
+        // annotations.add(data.getInfrastructureQAnnotation());
+
+        final double currentKm = getCurrentKm(context);
+
+        final List<StickyAxisAnnotation> annotations = new FloodDurationCalculation(context).calcInfrastructureAnnotations(currentKm,
+                data.getResults().get(this.index));
+        if (annotations != null) {
             return new RiverAnnotation(this.description, annotations);
         }
         else
             return null;
     }
 
+    /**
+     * Returns the current km from the context.
+     * If the context is null or doesn't contain a currentKm
+     * then a double value of -1 will be returned.
+     *
+     * @param context
+     *            The CallContext instance
+     * @return the current km as double
+     */
+    // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet
+    private double getCurrentKm(final CallContext context) {
+        if (context == null)
+            return Double.NaN;
+
+        final Double dkm = (Double) context.getContextValue(CURRENT_KM);
+        if (dkm == null)
+            return Double.NaN;
+
+        return dkm.doubleValue();
+    }
+
 
     /**
      * Create a deep copy of this Facet.

http://dive4elements.wald.intevation.org