comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java @ 8884:7a8c12706834

Work on SINFO-FlowDepth
author gernotbelger
date Tue, 13 Feb 2018 14:53:23 +0100
parents 7bbfb24e6eec
children cc86b0f9b3c3
comparison
equal deleted inserted replaced
8883:a536e1aacf0f 8884:7a8c12706834
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by 2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH 3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt 4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 * 5 *
6 * This file is Free Software under the GNU AGPL (>=v3) 6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 10
11 package org.dive4elements.river.artifacts.sinfo.flowdepth; 11 package org.dive4elements.river.artifacts.sinfo.flowdepth;
12 12
13 import java.util.Map; 13 import java.util.HashSet;
14 import java.util.Set;
14 15
15 import org.apache.log4j.Logger; 16 public final class FlowDepthProcessor extends AbstractSInfoProcessor {
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
17 import org.dive4elements.artifacts.CallContext;
18 import org.dive4elements.river.exports.DiagramGenerator;
19 import org.dive4elements.river.exports.StyledSeriesBuilder;
20 import org.dive4elements.river.exports.process.DefaultProcessor;
21 import org.dive4elements.river.jfree.StyledXYSeries;
22 import org.dive4elements.river.themes.ThemeDocument;
23 17
24 public final class FlowDepthProcessor extends DefaultProcessor { 18 /* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */
25 19 // REMARK: these mustend with 'filtered' so extra handling happens in chart: point are always recalculated, because data
26 /* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */ 20 // changes depending on zoom state
27 static String FACET_FLOW_DEPTH_FILTERED = "sinfo_flow_depth.filtered"; 21 static String FACET_FLOW_DEPTH_FILTERED = "sinfo_flow_depth.filtered";
28 22
29 private final static Logger log = Logger.getLogger(FlowDepthProcessor.class); 23 static String FACET_FLOW_DEPTH_TKH_FILTERED = "sinfo_flow_depth.tkh.filtered";
24
25 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
26
27 static {
28 HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_FILTERED);
29 HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_TKH_FILTERED);
30 }
30 31
31 private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label"; 32 private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label";
32 private String yAxisLabel;
33 33
34 @Override 34 public FlowDepthProcessor() {
35 public void doOut( 35 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
36 final DiagramGenerator generator,
37 final ArtifactAndFacet bundle,
38 final ThemeDocument theme,
39 final boolean visible) {
40
41 final CallContext context = generator.getCallContext();
42 final Map<String, String> metaData = bundle.getFacet().getMetaData();
43
44 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
45 series.putMetaData(metaData, bundle.getArtifact(), context);
46
47 yAxisLabel = metaData.get("Y");
48
49 final String facetName = bundle.getFacetName();
50 final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context);
51 if (data == null) {
52 // Check has been here before so we keep it for security reasons
53 // this should never happen though.
54 log.error("Data is null for facet: " + facetName);
55 return;
56 }
57
58 final double [][] points = generatePoints(data);
59
60 StyledSeriesBuilder.addPoints(series, points, true);
61 generator.addAxisSeries(series, axisName, visible);
62 } 36 }
63 37
64 private static double[][] generatePoints(final FlowDepthCalculationResult data) { 38 // FIXME: do filtering
39 @Override
40 protected double[][] generatePoints(final FlowDepthCalculationResult data, final String facetName) {
65 41
66 // FIXME 42 if (FACET_FLOW_DEPTH_FILTERED.contentEquals(facetName))
67 return data.getFlowDepthPoints(); 43 return data.getFlowDepthPoints();
68 44
69 // if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || 45 if (FACET_FLOW_DEPTH_TKH_FILTERED.contentEquals(facetName))
70 // facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { 46 return data.getFlowDepthTkhPoints();
71 // FlowVelocityData fData = (FlowVelocityData) data;
72 // points = fData.getTotalChannelPoints();
73 // } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) ||
74 // facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)) {
75 // FlowVelocityData fData = (FlowVelocityData) data;
76 // points = fData.getMainChannelPoints(); // I hate facets!
77 // } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) {
78 // FastFlowVelocityMeasurementValue fData =
79 // (FastFlowVelocityMeasurementValue) data;
80 // points = new double[][] {{fData.getStation()},{fData.getV()}};
81 // } else {
82 // log.error("Unknown facet name: " + facetName);
83 // return;
84 // }
85 }
86 47
87 @Override 48 return super.generatePoints(data, facetName);
88 public boolean canHandle(String facettype) {
89 return FACET_FLOW_DEPTH_FILTERED.equals(facettype);
90 }
91
92 @Override
93 public String getAxisLabel(DiagramGenerator generator) {
94 if (yAxisLabel != null && !yAxisLabel.isEmpty()) {
95 // REMARK/UNINTENDED: yAxisLabel may also be a resolved message (side-effect of StyledXYSeries#putMetadata),
96 // and cannot be resolved, so we need to give the resolved value as default
97 // In other implementations (i.e. FlowVelocityProcessor), an explicit (German) default label is given here, probably
98 // the English version will also show German (CHECK)
99 return generator.msg(yAxisLabel, yAxisLabel);
100 }
101 return generator.msg(
102 I18N_AXIS_LABEL,
103 "MISSING");
104 } 49 }
105 } 50 }

http://dive4elements.wald.intevation.org