changeset 8890:90b7f45ff4ae

Calculating moving average of flow depth output
author gernotbelger
date Wed, 14 Feb 2018 18:45:42 +0100
parents f87f435df856
children f431aec10d2c
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java
diffstat 1 files changed, 38 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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

http://dive4elements.wald.intevation.org