Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoLineProcessor.java @ 9123:1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
author | gernotbelger |
---|---|
date | Tue, 05 Jun 2018 19:21:16 +0200 |
parents | ee5ce13016ed |
children | 23945061daec |
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 |
9123
1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents:
8956
diff
changeset
|
34 private static final double GAP_DISTANCE = 0.101; |
1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents:
8956
diff
changeset
|
35 |
8940 | 36 public AbstractSInfoLineProcessor(final String i18nAxisLabel, final Set<String> handledFacetType) { |
37 super(i18nAxisLabel, handledFacetType); | |
38 } | |
39 | |
40 @Override | |
41 protected final String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
42 | |
9123
1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents:
8956
diff
changeset
|
43 final CallContext context = generator.getContext(); |
8940 | 44 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
45 | |
46 final Artifact artifact = bundle.getArtifact(); | |
47 | |
48 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); | |
49 series.putMetaData(metaData, artifact, context); | |
50 | |
51 final String facetName = bundle.getFacetName(); | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
52 @SuppressWarnings("unchecked") |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
53 final RESULT data = (RESULT) bundle.getData(context); |
8940 | 54 if (data == null) { |
55 // Check has been here before so we keep it for security reasons | |
56 // this should never happen though. | |
57 throw new IllegalStateException("Data is null for facet: " + facetName); | |
58 } | |
59 | |
60 final double[][] points = generatePoints(context, artifact, data, facetName); | |
61 | |
9123
1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents:
8956
diff
changeset
|
62 StyledSeriesBuilder.addPoints(series, points, true, GAP_DISTANCE); |
8940 | 63 generator.addAxisSeries(series, getAxisName(), visible); |
64 | |
65 return metaData.get("Y"); | |
66 } | |
67 | |
68 private Double findRadius(final CallContext context, final Artifact artifact) { | |
69 final Double start = (Double) context.getContextValue("startkm"); | |
70 final Double end = (Double) context.getContextValue("endkm"); | |
71 | |
72 if (start == null || end == null) | |
73 return null; | |
74 | |
75 final RiverContext fc = (RiverContext) context.globalContext(); | |
76 final ZoomScale scales = (ZoomScale) fc.get("zoomscale"); | |
77 final RiverAccess access = new RiverAccess((D4EArtifact) artifact); | |
78 final String river = access.getRiverName(); | |
79 | |
80 return scales.getRadius(river, start, end); | |
81 } | |
82 | |
8956 | 83 private double[][] generatePoints(final CallContext context, final Artifact artifact, final RESULT data, final String facetName) { |
8940 | 84 |
85 final double[][] points = doGetPoints(data, facetName); | |
8956 | 86 if (facetName.endsWith(".filtered")) { |
8940 | 87 final Double radius = findRadius(context, artifact); |
88 return movingAverage(radius, points); | |
89 } | |
90 | |
91 return points; | |
92 } | |
93 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8940
diff
changeset
|
94 protected abstract double[][] doGetPoints(RESULT data, String facetName); |
8940 | 95 |
96 private double[][] movingAverage(final Double radius, final double[][] points) { | |
97 | |
98 if (radius == null) | |
99 return points; | |
100 | |
101 return MovingAverage.weighted(points, radius); | |
102 } | |
8956 | 103 |
104 protected static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result, | |
105 final int index, final String axisLabel, final String facetId, final String description) { | |
106 final String facetFlowDepthFilteredDescription = Resources.getMsg(context.getMeta(), description, description, result.getLabel()); | |
107 return new SInfoResultFacet(index, facetId, facetFlowDepthFilteredDescription, axisLabel, ComputeType.ADVANCE, id, hash); | |
108 } | |
8940 | 109 } |