Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/process/FlowVelocityProcessor.java @ 9556:9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
author | gernotbelger |
---|---|
date | Tue, 23 Oct 2018 16:26:58 +0200 |
parents | 1cc7653ca84f |
children |
rev | line source |
---|---|
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 * |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 package org.dive4elements.river.exports.process; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 |
7892
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
11 import java.util.Map; |
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
12 |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 import org.dive4elements.artifacts.CallContext; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 import org.dive4elements.river.artifacts.model.FacetTypes; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 import org.dive4elements.river.exports.DiagramGenerator; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 import org.dive4elements.river.exports.StyledSeriesBuilder; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 import org.dive4elements.river.jfree.StyledXYSeries; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 import org.dive4elements.river.themes.ThemeDocument; |
7164 | 22 |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
23 import org.dive4elements.river.model.FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue; |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 import org.dive4elements.river.artifacts.model.FlowVelocityData; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 public class FlowVelocityProcessor extends DefaultProcessor { |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8078
diff
changeset
|
28 private final static Logger log = |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 Logger.getLogger(FlowVelocityProcessor.class); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 public static final String I18N_AXIS_LABEL = |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 "chart.flow_velocity.section.yaxis.label"; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 public static final String I18N_AXIS_LABEL_DEFAULT = |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 "Geschwindigkeit v [m/s]"; |
7892
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
35 |
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
36 protected String yAxisLabel; |
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
37 |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 @Override |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 public void doOut( |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 DiagramGenerator generator, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 ArtifactAndFacet bundle, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 ThemeDocument theme, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 boolean visible) { |
9123
1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents:
8860
diff
changeset
|
44 CallContext context = generator.getContext(); |
7892
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
45 Map<String, String> metaData = bundle.getFacet().getMetaData(); |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9123
diff
changeset
|
46 StyledXYSeries series = new StyledXYSeries(bundle.getFacetName(), |
8856 | 47 bundle.getFacetDescription(), |
48 theme); | |
7892
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
49 series.putMetaData(metaData, bundle.getArtifact(), context); |
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
50 yAxisLabel = metaData.get("Y"); |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
51 String facetName = bundle.getFacetName(); |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
52 Object data = bundle.getData(context); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 if (data == null) { |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
54 // Check has been here before so we keep it for security reasons |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
55 // this should never happen though. |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8078
diff
changeset
|
56 log.error("Data is null for facet: " + facetName); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
57 return; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 double [][] points; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
60 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
61 if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || |
8856 | 62 facetName.equals( |
63 FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) | |
64 ) { | |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
65 FlowVelocityData fData = (FlowVelocityData) data; |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
66 points = fData.getTotalChannelPoints(); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || |
8856 | 68 facetName.equals( |
69 FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) | |
70 ) { | |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
71 FlowVelocityData fData = (FlowVelocityData) data; |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
72 points = fData.getMainChannelPoints(); // I hate facets! |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
73 } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) { |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
74 FastFlowVelocityMeasurementValue fData = |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
75 (FastFlowVelocityMeasurementValue) data; |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
76 points = new double[][] {{fData.getStation()},{fData.getV()}}; |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 } else { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8078
diff
changeset
|
78 log.error("Unknown facet name: " + facetName); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 return; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 StyledSeriesBuilder.addPoints(series, points, true); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 generator.addAxisSeries(series, axisName, visible); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 @Override |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 public boolean canHandle(String facettype) { |
8856 | 87 return facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) |
88 || facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) | |
89 || facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) | |
90 || facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) | |
91 || facettype.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT); | |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
92 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
94 @Override |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 public String getAxisLabel(DiagramGenerator generator) { |
7892
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
96 if (yAxisLabel != null && !yAxisLabel.isEmpty()) { |
8853 | 97 // FIXME/UNINTENDED: yAxisLabel is probably a resolved message (side-effect of StyledXYSeries#putMetadata), |
98 // and cannot be resolved again. | |
99 // An explicit (German) default label is therefore given here, probably the English version will also show German (CHECK) | |
7892
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
100 return generator.msg(yAxisLabel, I18N_AXIS_LABEL_DEFAULT); |
e844be34a606
Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents:
7164
diff
changeset
|
101 } |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 return generator.msg( |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 I18N_AXIS_LABEL, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 I18N_AXIS_LABEL_DEFAULT); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
105 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 } |