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