Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoLineProcessor.java @ 8956:ee5ce13016ed
Work on SINFO-Fließtiefenentwicklung
author | gernotbelger |
---|---|
date | Tue, 20 Mar 2018 13:30:07 +0100 |
parents | a4f1ac81f26d |
children | 1cc7653ca84f |
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; | |
8956 | 17 import org.dive4elements.artifactdatabase.state.Facet; |
8940 | 18 import org.dive4elements.artifacts.Artifact; |
19 import org.dive4elements.artifacts.CallContext; | |
20 import org.dive4elements.river.artifacts.D4EArtifact; | |
21 import org.dive4elements.river.artifacts.access.RiverAccess; | |
22 import org.dive4elements.river.artifacts.context.RiverContext; | |
23 import org.dive4elements.river.artifacts.math.MovingAverage; | |
24 import org.dive4elements.river.artifacts.model.ZoomScale; | |
8956 | 25 import org.dive4elements.river.artifacts.resources.Resources; |
26 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
8940 | 27 import org.dive4elements.river.exports.DiagramGenerator; |
28 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
29 import org.dive4elements.river.jfree.StyledXYSeries; | |
30 import org.dive4elements.river.themes.ThemeDocument; | |
31 | |
8948 | 32 abstract class AbstractSInfoLineProcessor<RESULT extends AbstractSInfoCalculationResult> extends AbstractSInfoProcessor { |
8940 | 33 |
34 public AbstractSInfoLineProcessor(final String i18nAxisLabel, final Set<String> handledFacetType) { | |
35 super(i18nAxisLabel, handledFacetType); | |
36 } | |
37 | |
38 @Override | |
39 protected final String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
40 | |
41 final CallContext context = generator.getCallContext(); | |
42 final Map<String, String> metaData = bundle.getFacet().getMetaData(); | |
43 | |
44 final Artifact artifact = bundle.getArtifact(); | |
45 | |
46 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); | |
47 series.putMetaData(metaData, artifact, context); | |
48 | |
49 final String facetName = bundle.getFacetName(); | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
50 @SuppressWarnings("unchecked") |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
51 final RESULT data = (RESULT) bundle.getData(context); |
8940 | 52 if (data == null) { |
53 // Check has been here before so we keep it for security reasons | |
54 // this should never happen though. | |
55 throw new IllegalStateException("Data is null for facet: " + facetName); | |
56 } | |
57 | |
58 final double[][] points = generatePoints(context, artifact, data, facetName); | |
59 | |
60 StyledSeriesBuilder.addPoints(series, points, true); | |
61 generator.addAxisSeries(series, getAxisName(), visible); | |
62 | |
63 return metaData.get("Y"); | |
64 } | |
65 | |
66 private Double findRadius(final CallContext context, final Artifact artifact) { | |
67 final Double start = (Double) context.getContextValue("startkm"); | |
68 final Double end = (Double) context.getContextValue("endkm"); | |
69 | |
70 if (start == null || end == null) | |
71 return null; | |
72 | |
73 final RiverContext fc = (RiverContext) context.globalContext(); | |
74 final ZoomScale scales = (ZoomScale) fc.get("zoomscale"); | |
75 final RiverAccess access = new RiverAccess((D4EArtifact) artifact); | |
76 final String river = access.getRiverName(); | |
77 | |
78 return scales.getRadius(river, start, end); | |
79 } | |
80 | |
8956 | 81 private double[][] generatePoints(final CallContext context, final Artifact artifact, final RESULT data, final String facetName) { |
8940 | 82 |
83 final double[][] points = doGetPoints(data, facetName); | |
8956 | 84 if (facetName.endsWith(".filtered")) { |
8940 | 85 final Double radius = findRadius(context, artifact); |
86 return movingAverage(radius, points); | |
87 } | |
88 | |
89 return points; | |
90 } | |
91 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
92 protected abstract double[][] doGetPoints(RESULT data, String facetName); |
8940 | 93 |
94 private double[][] movingAverage(final Double radius, final double[][] points) { | |
95 | |
96 if (radius == null) | |
97 return points; | |
98 | |
99 return MovingAverage.weighted(points, radius); | |
100 } | |
8956 | 101 |
102 protected static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result, | |
103 final int index, final String axisLabel, final String facetId, final String description) { | |
104 final String facetFlowDepthFilteredDescription = Resources.getMsg(context.getMeta(), description, description, result.getLabel()); | |
105 return new SInfoResultFacet(index, facetId, facetFlowDepthFilteredDescription, axisLabel, ComputeType.ADVANCE, id, hash); | |
106 } | |
8940 | 107 } |