Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/process/FlowVelocityProcessor.java @ 7605:f51c943c707a
(issue1560) Fix off by one error in ATWriter causing the last value to be omitted.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 27 Nov 2013 17:17:54 +0100 |
parents | 440c55b9634e |
children | 43f18dc56c5a e844be34a606 |
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 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 import org.apache.log4j.Logger; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 import org.jfree.data.xy.XYSeries; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 import org.dive4elements.artifacts.CallContext; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 import org.dive4elements.river.artifacts.model.FacetTypes; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 import org.dive4elements.river.exports.DiagramGenerator; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 import org.dive4elements.river.exports.StyledSeriesBuilder; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 import org.dive4elements.river.jfree.StyledXYSeries; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 import org.dive4elements.river.themes.ThemeDocument; |
7164 | 21 |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
22 import org.dive4elements.river.model.FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue; |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 import org.dive4elements.river.artifacts.model.FlowVelocityData; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 public class FlowVelocityProcessor extends DefaultProcessor { |
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 private final static Logger logger = |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 Logger.getLogger(FlowVelocityProcessor.class); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 public static final String I18N_AXIS_LABEL = |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 "chart.flow_velocity.section.yaxis.label"; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 public static final String I18N_AXIS_LABEL_DEFAULT = |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 "Geschwindigkeit v [m/s]"; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 @Override |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 public void doOut( |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 DiagramGenerator generator, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 ArtifactAndFacet bundle, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 ThemeDocument theme, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 boolean visible) { |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 CallContext context = generator.getCallContext(); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 theme); |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
44 String facetName = bundle.getFacetName(); |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
45 Object data = bundle.getData(context); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 if (data == null) { |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
47 // 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
|
48 // this should never happen though. |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
49 logger.error("Data is null for facet: " + facetName); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 return; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
52 double [][] points; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
56 FlowVelocityData fData = (FlowVelocityData) data; |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
57 points = fData.getTotalChannelPoints(); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)) { |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
60 FlowVelocityData fData = (FlowVelocityData) data; |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
61 points = fData.getMainChannelPoints(); // I hate facets! |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
62 } 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
|
63 FastFlowVelocityMeasurementValue fData = |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
64 (FastFlowVelocityMeasurementValue) data; |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
65 points = new double[][] {{fData.getStation()},{fData.getV()}}; |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 } else { |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 logger.error("Unknown facet name: " + facetName); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
68 return; |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 StyledSeriesBuilder.addPoints(series, points, true); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 generator.addAxisSeries(series, axisName, visible); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
74 |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
75 @Override |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 public boolean canHandle(String facettype) { |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 return facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) || |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) || |
7162
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
80 facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || |
4683bdf77ff9
Handle flow velocity measurements in the FlowVelocity processor
Andre Heinecke <aheinecke@intevation.de>
parents:
7159
diff
changeset
|
81 facettype.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT); |
7155
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 } |
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 @Override |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 public String getAxisLabel(DiagramGenerator generator) { |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 return generator.msg( |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
87 I18N_AXIS_LABEL, |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
88 I18N_AXIS_LABEL_DEFAULT); |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 } |
34b5e7ef2a36
Add FlowVelocity Processor
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 } |