[PATCH 2 of 2] Calculating moving average of flow depth output

Wald Commits scm-commit at wald.intevation.org
Wed Feb 14 18:45:49 CET 2018


# HG changeset patch
# User gernotbelger
# Date 1518630342 -3600
# Node ID 90b7f45ff4aeb4a905b28dd3fd1bcbc0d33f9bec
# Parent  f87f435df856c2fe303480cc96cc30ab8ec77e6b
Calculating moving average of flow depth output

diff -r f87f435df856 -r 90b7f45ff4ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java	Wed Feb 14 18:45:01 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java	Wed Feb 14 18:45:42 2018 +0100
@@ -15,7 +15,13 @@
 import java.util.Set;
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RiverAccess;
+import org.dive4elements.river.artifacts.context.RiverContext;
+import org.dive4elements.river.artifacts.math.MovingAverage;
+import org.dive4elements.river.artifacts.model.ZoomScale;
 import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.exports.StyledSeriesBuilder;
 import org.dive4elements.river.jfree.StyledXYSeries;
@@ -49,8 +55,10 @@
         final CallContext context = generator.getCallContext();
         final Map<String, String> metaData = bundle.getFacet().getMetaData();
 
+        final Artifact artifact = bundle.getArtifact();
+
         final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
-        series.putMetaData(metaData, bundle.getArtifact(), context);
+        series.putMetaData(metaData, artifact, context);
 
         final String facetName = bundle.getFacetName();
         final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context);
@@ -60,7 +68,9 @@
             throw new IllegalStateException("Data is null for facet: " + facetName);
         }
 
-        final double[][] points = generatePoints(data, facetName);
+        final Double radius = findRadius(context, artifact);
+
+        final double[][] points = generatePoints(radius, data, facetName);
 
         StyledSeriesBuilder.addPoints(series, points, true);
         generator.addAxisSeries(series, getAxisName(), visible);
@@ -68,16 +78,38 @@
         return metaData.get("Y");
     }
 
-    // FIXME: do filtering
-    private double[][] generatePoints(final FlowDepthCalculationResult data, final String facetName) {
+    private Double findRadius(final CallContext context, final Artifact artifact) {
+        final Double start = (Double) context.getContextValue("startkm");
+        final Double end = (Double) context.getContextValue("endkm");
+
+        if (start == null || end == null)
+            return null;
+
+        final RiverContext fc = (RiverContext) context.globalContext();
+        final ZoomScale scales = (ZoomScale) fc.get("zoomscale");
+        final RiverAccess access = new RiverAccess((D4EArtifact) artifact);
+        final String river = access.getRiverName();
+
+        return scales.getRadius(river, start, end);
+    }
+
+    private double[][] generatePoints(final Double radius, final FlowDepthCalculationResult data, final String facetName) {
 
         if (FACET_FLOW_DEPTH_FILTERED.contentEquals(facetName))
-            return data.getFlowDepthPoints();
+            return movingAverage(radius, data.getFlowDepthPoints());
 
         if (FACET_FLOW_DEPTH_TKH_FILTERED.contentEquals(facetName))
-            return data.getFlowDepthTkhPoints();
+            return movingAverage(radius, data.getFlowDepthTkhPoints());
 
         final String error = String.format("Unknown facet name: %s", facetName);
         throw new UnsupportedOperationException(error);
     }
+
+    private double[][] movingAverage(final Double radius, final double[][] points) {
+
+        if (radius == null)
+            return points;
+
+        return MovingAverage.weighted(points, radius);
+    }
 }
\ No newline at end of file


More information about the Dive4Elements-commits mailing list