Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoLineProcessor.java @ 8948:a4f1ac81f26d
Work on SINFO-FlowDepthMinMax.
Also rework of result row stuff, in order to reduce abstraction, using result type concept
author | gernotbelger |
---|---|
date | Wed, 14 Mar 2018 14:10:32 +0100 |
parents | 5d5d482da3e9 |
children | ee5ce13016ed |
rev | line source |
---|---|
8940 | 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 | |
11 package org.dive4elements.river.artifacts.sinfo.common; | |
12 | |
13 import java.util.Map; | |
14 import java.util.Set; | |
15 | |
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
17 import org.dive4elements.artifacts.Artifact; | |
18 import org.dive4elements.artifacts.CallContext; | |
19 import org.dive4elements.river.artifacts.D4EArtifact; | |
20 import org.dive4elements.river.artifacts.access.RiverAccess; | |
21 import org.dive4elements.river.artifacts.context.RiverContext; | |
22 import org.dive4elements.river.artifacts.math.MovingAverage; | |
23 import org.dive4elements.river.artifacts.model.ZoomScale; | |
24 import org.dive4elements.river.exports.DiagramGenerator; | |
25 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
26 import org.dive4elements.river.jfree.StyledXYSeries; | |
27 import org.dive4elements.river.themes.ThemeDocument; | |
28 | |
8948 | 29 abstract class AbstractSInfoLineProcessor<RESULT extends AbstractSInfoCalculationResult> extends AbstractSInfoProcessor { |
8940 | 30 |
31 public AbstractSInfoLineProcessor(final String i18nAxisLabel, final Set<String> handledFacetType) { | |
32 super(i18nAxisLabel, handledFacetType); | |
33 } | |
34 | |
35 @Override | |
36 protected final String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
37 | |
38 final CallContext context = generator.getCallContext(); | |
39 final Map<String, String> metaData = bundle.getFacet().getMetaData(); | |
40 | |
41 final Artifact artifact = bundle.getArtifact(); | |
42 | |
43 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); | |
44 series.putMetaData(metaData, artifact, context); | |
45 | |
46 final String facetName = bundle.getFacetName(); | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
47 @SuppressWarnings("unchecked") |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
48 final RESULT data = (RESULT) bundle.getData(context); |
8940 | 49 if (data == null) { |
50 // Check has been here before so we keep it for security reasons | |
51 // this should never happen though. | |
52 throw new IllegalStateException("Data is null for facet: " + facetName); | |
53 } | |
54 | |
55 final double[][] points = generatePoints(context, artifact, data, facetName); | |
56 | |
57 StyledSeriesBuilder.addPoints(series, points, true); | |
58 generator.addAxisSeries(series, getAxisName(), visible); | |
59 | |
60 return metaData.get("Y"); | |
61 } | |
62 | |
63 private Double findRadius(final CallContext context, final Artifact artifact) { | |
64 final Double start = (Double) context.getContextValue("startkm"); | |
65 final Double end = (Double) context.getContextValue("endkm"); | |
66 | |
67 if (start == null || end == null) | |
68 return null; | |
69 | |
70 final RiverContext fc = (RiverContext) context.globalContext(); | |
71 final ZoomScale scales = (ZoomScale) fc.get("zoomscale"); | |
72 final RiverAccess access = new RiverAccess((D4EArtifact) artifact); | |
73 final String river = access.getRiverName(); | |
74 | |
75 return scales.getRadius(river, start, end); | |
76 } | |
77 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
78 private double[][] generatePoints(final CallContext context, final Artifact artifact, final RESULT data, |
8940 | 79 final String facetName) { |
80 | |
81 final double[][] points = doGetPoints(data, facetName); | |
82 if( facetName.endsWith(".filtered")) | |
83 { | |
84 final Double radius = findRadius(context, artifact); | |
85 return movingAverage(radius, points); | |
86 } | |
87 | |
88 return points; | |
89 } | |
90 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
91 protected abstract double[][] doGetPoints(RESULT data, String facetName); |
8940 | 92 |
93 private double[][] movingAverage(final Double radius, final double[][] points) { | |
94 | |
95 if (radius == null) | |
96 return points; | |
97 | |
98 return MovingAverage.weighted(points, radius); | |
99 } | |
100 } |