Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoLineProcessor.java @ 8940:82998242ba84
Preparing for additional outputs of SINFO-Tkh
author | gernotbelger |
---|---|
date | Tue, 06 Mar 2018 18:51:18 +0100 |
parents | |
children | 5d5d482da3e9 |
comparison
equal
deleted
inserted
replaced
8939:2970368ae1e3 | 8940:82998242ba84 |
---|---|
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 | |
29 abstract class AbstractSInfoLineProcessor extends AbstractSInfoProcessor { | |
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(); | |
47 final AbstractSInfoCalculationResult<?> data = (AbstractSInfoCalculationResult<?>) bundle.getData(context); | |
48 if (data == null) { | |
49 // Check has been here before so we keep it for security reasons | |
50 // this should never happen though. | |
51 throw new IllegalStateException("Data is null for facet: " + facetName); | |
52 } | |
53 | |
54 final double[][] points = generatePoints(context, artifact, data, facetName); | |
55 | |
56 StyledSeriesBuilder.addPoints(series, points, true); | |
57 generator.addAxisSeries(series, getAxisName(), visible); | |
58 | |
59 return metaData.get("Y"); | |
60 } | |
61 | |
62 private Double findRadius(final CallContext context, final Artifact artifact) { | |
63 final Double start = (Double) context.getContextValue("startkm"); | |
64 final Double end = (Double) context.getContextValue("endkm"); | |
65 | |
66 if (start == null || end == null) | |
67 return null; | |
68 | |
69 final RiverContext fc = (RiverContext) context.globalContext(); | |
70 final ZoomScale scales = (ZoomScale) fc.get("zoomscale"); | |
71 final RiverAccess access = new RiverAccess((D4EArtifact) artifact); | |
72 final String river = access.getRiverName(); | |
73 | |
74 return scales.getRadius(river, start, end); | |
75 } | |
76 | |
77 private double[][] generatePoints(final CallContext context, final Artifact artifact, final AbstractSInfoCalculationResult<?> data, | |
78 final String facetName) { | |
79 | |
80 final double[][] points = doGetPoints(data, facetName); | |
81 if( facetName.endsWith(".filtered")) | |
82 { | |
83 final Double radius = findRadius(context, artifact); | |
84 return movingAverage(radius, points); | |
85 } | |
86 | |
87 return points; | |
88 } | |
89 | |
90 protected abstract double[][] doGetPoints(AbstractSInfoCalculationResult<?> data, String facetName); | |
91 | |
92 private double[][] movingAverage(final Double radius, final double[][] points) { | |
93 | |
94 if (radius == null) | |
95 return points; | |
96 | |
97 return MovingAverage.weighted(points, radius); | |
98 } | |
99 } |