annotate artifacts/src/main/java/org/dive4elements/river/exports/process/FlowVelocityProcessor.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
13 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
14 import org.apache.logging.log4j.LogManager;
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 import org.dive4elements.artifacts.CallContext;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.FacetTypes;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 import org.dive4elements.river.exports.DiagramGenerator;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 import org.dive4elements.river.exports.StyledSeriesBuilder;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 import org.dive4elements.river.jfree.StyledXYSeries;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 import org.dive4elements.river.themes.ThemeDocument;
7164
440c55b9634e Cosmetics
Andre Heinecke <aheinecke@intevation.de>
parents: 7162
diff changeset
23
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
24 import org.dive4elements.river.model.FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue;
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 import org.dive4elements.river.artifacts.model.FlowVelocityData;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 public class FlowVelocityProcessor extends DefaultProcessor {
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8078
diff changeset
29 private final static Logger log =
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
30 LogManager.getLogger(FlowVelocityProcessor.class);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 public static final String I18N_AXIS_LABEL =
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 "chart.flow_velocity.section.yaxis.label";
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 public static final String I18N_AXIS_LABEL_DEFAULT =
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 "Geschwindigkeit v [m/s]";
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
36
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
37 protected String yAxisLabel;
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
38
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 @Override
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 public void doOut(
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 DiagramGenerator generator,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 ArtifactAndFacet bundle,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 ThemeDocument theme,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 boolean visible) {
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 CallContext context = generator.getCallContext();
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
46 Map<String, String> metaData = bundle.getFacet().getMetaData();
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
47 StyledXYSeries series = new StyledXYSeries(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
48 bundle.getFacetDescription(),
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
49 theme);
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
50 series.putMetaData(metaData, bundle.getArtifact(), context);
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
51 yAxisLabel = metaData.get("Y");
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
52 String facetName = bundle.getFacetName();
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
53 Object data = bundle.getData(context);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 if (data == null) {
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
55 // 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
56 // this should never happen though.
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8078
diff changeset
57 log.error("Data is null for facet: " + facetName);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 return;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 double [][] points;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) ||
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
63 facetName.equals(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
64 FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
65 ) {
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
66 FlowVelocityData fData = (FlowVelocityData) data;
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
67 points = fData.getTotalChannelPoints();
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) ||
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
69 facetName.equals(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
70 FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
71 ) {
7162
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
72 FlowVelocityData fData = (FlowVelocityData) data;
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
73 points = fData.getMainChannelPoints(); // I hate facets!
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
74 } 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
75 FastFlowVelocityMeasurementValue fData =
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
76 (FastFlowVelocityMeasurementValue) data;
4683bdf77ff9 Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents: 7159
diff changeset
77 points = new double[][] {{fData.getStation()},{fData.getV()}};
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 } else {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8078
diff changeset
79 log.error("Unknown facet name: " + facetName);
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 return;
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 StyledSeriesBuilder.addPoints(series, points, true);
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 generator.addAxisSeries(series, axisName, visible);
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
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 @Override
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 public boolean canHandle(String facettype) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
88 return facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
89 || facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
90 || facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
91 || facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8733
diff changeset
92 || facettype.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT);
7155
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
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95 @Override
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96 public String getAxisLabel(DiagramGenerator generator) {
7892
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
97 if (yAxisLabel != null && !yAxisLabel.isEmpty()) {
e844be34a606 Add metadata to chart series and datasets.
Raimund Renkert <rrenkert@intevation.de>
parents: 7164
diff changeset
98 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
99 }
7155
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
100 return generator.msg(
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
101 I18N_AXIS_LABEL,
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
102 I18N_AXIS_LABEL_DEFAULT);
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
103 }
34b5e7ef2a36 Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104 }

http://dive4elements.wald.intevation.org