comparison artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadLSGenerator.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadLSGenerator.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.exports.minfo;
2
3 import java.util.Arrays;
4
5 import org.apache.log4j.Logger;
6 import org.jfree.data.xy.XYSeries;
7 import org.w3c.dom.Document;
8
9 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
10 import org.dive4elements.artifactdatabase.state.Facet;
11 import org.dive4elements.river.artifacts.FLYSArtifact;
12 import org.dive4elements.river.artifacts.access.RangeAccess;
13 import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
14 import org.dive4elements.river.artifacts.model.FacetTypes;
15 import org.dive4elements.river.artifacts.model.FlowVelocityData;
16 import org.dive4elements.river.artifacts.model.WKms;
17 import org.dive4elements.river.artifacts.model.minfo.BedDiffEpochResult;
18 import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult;
19 import org.dive4elements.river.exports.StyledSeriesBuilder;
20 import org.dive4elements.river.exports.XYChartGenerator;
21 import org.dive4elements.river.jfree.Bounds;
22 import org.dive4elements.river.jfree.DoubleBounds;
23 import org.dive4elements.river.jfree.FLYSAnnotation;
24 import org.dive4elements.river.jfree.StyledXYSeries;
25 import org.dive4elements.river.utils.DataUtil;
26
27
28 public class SedimentLoadLSGenerator
29 extends XYChartGenerator
30 implements FacetTypes
31 {
32 public enum YAXIS {
33 L(0),
34 D(1),
35 DW(2),
36 V(3);
37
38 protected int idx;
39
40 private YAXIS(int c) {
41 idx = c;
42 }
43 }
44 /** The logger that is used in this generator. */
45 private static Logger logger = Logger.getLogger(SedimentLoadLSGenerator.class);
46
47 public static final String I18N_CHART_TITLE = "chart.sedimentload.ls.title";
48 public static final String I18N_XAXIS_LABEL = "chart.sedimentload.ls.xaxis.label";
49 public static final String I18N_YAXIS_LABEL_1 = "chart.sedimentload.ls.yaxis.label.tpera";
50 public static final String I18N_YAXIS_LABEL_2 = "chart.sedimentload.ls.yaxis.label.m3pera";
51 public static final String I18N_YAXIS_D_LABEL = "chart.beddifference.yaxis.label.diff";
52 public static final String I18N_YAXIS_V_LABEL =
53 "chart.flow_velocity.section.yaxis.label";
54 public final static String I18N_WDIFF_YAXIS_LABEL =
55 "chart.w_differences.yaxis.label";
56
57 public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m";
58 public static final String I18N_CHART_TITLE_DEFAULT = "Sedimentfracht";
59 public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km";
60 public static final String I18N_YAXIS_LABEL_DEFAULT_1 = "[t/a]";
61 public static final String I18N_YAXIS_LABEL_DEFAULT_2 = "[m\u00b3/a]";
62 public static final String I18N_YAXIS_D_LABEL_DEFAULT = "delta S [m]";
63 public static final String I18N_YAXIS_V_LABEL_DEFAULT = "Geschwindigkeit v [m/s]";
64
65 private FLYSArtifact artifact;
66
67 @Override
68 protected YAxisWalker getYAxisWalker() {
69 return new YAxisWalker() {
70
71 @Override
72 public int length() {
73 return YAXIS.values().length;
74 }
75
76 @Override
77 public String getId(int idx) {
78 YAXIS[] yaxes = YAXIS.values();
79 return yaxes[idx].toString();
80 }
81 };
82 }
83
84 @Override
85 public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) {
86 String name = bundle.getFacetName();
87
88 logger.debug("doOut: " + name);
89
90 if (name == null) {
91 logger.error("No facet name for doOut(). No output generated!");
92 return;
93 }
94
95 Facet facet = bundle.getFacet();
96 artifact = (FLYSArtifact)bundle.getArtifact();
97
98 if (facet == null) {
99 return;
100 }
101 if (getXBounds(0) != null && getDomainAxisRange() != null) {
102 logger.debug(Arrays.toString(getDomainAxisRangeFromRequest()));
103 Bounds bounds =
104 calculateZoom(getXBounds(0), getDomainAxisRange());
105 context.putContextValue("startkm", bounds.getLower());
106 context.putContextValue("endkm", bounds.getUpper());
107 }
108 else if (getXBounds(0) != null && getDomainAxisRange() == null) {
109 context.putContextValue("startkm", getXBounds(0).getLower());
110 context.putContextValue("endkm", getXBounds(0).getUpper());
111 }
112 else if (getXBounds(0) == null && getDomainAxisRange() == null) {
113 FLYSArtifact artifact = (FLYSArtifact)bundle.getArtifact();
114 RangeAccess access = new RangeAccess(artifact, context);
115 context.putContextValue("startkm", access.getFrom());
116 context.putContextValue("endkm", access.getTo());
117 }
118 else if (getXBounds(0) == null && getDomainAxisRange() != null){
119 FLYSArtifact artifact = (FLYSArtifact)bundle.getArtifact();
120 RangeAccess access = new RangeAccess(artifact, context);
121 Bounds b = new DoubleBounds(access.getFrom(), access.getTo());
122 Bounds bounds =
123 calculateZoom(b, getDomainAxisRange());
124 context.putContextValue("startkm", bounds.getLower());
125 context.putContextValue("endkm", bounds.getUpper());
126 }
127 if (FacetTypes.IS.SEDIMENT_LOAD(SEDIMENT_LOAD_COARSE)) {
128 doSedimentLoadOut(
129 (double[][]) bundle.getData(context),
130 bundle,
131 attr,
132 visible);
133 }
134 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL)) {
135 doFlowVelocityTotalOut(
136 (FlowVelocityData) bundle.getData(context),
137 bundle,
138 attr,
139 visible);
140 }
141 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) {
142 doFlowVelocityTotalOut(
143 (FlowVelocityData) bundle.getData(context),
144 bundle,
145 attr,
146 visible);
147 }
148 else if (name.equals(FLOW_VELOCITY_MAINCHANNEL)) {
149 doFlowVelocityMainOut(
150 (FlowVelocityData) bundle.getData(context),
151 bundle,
152 attr,
153 visible);
154 }
155 else if (name.equals(FLOW_VELOCITY_MAINCHANNEL_FILTERED)) {
156 doFlowVelocityMainOut(
157 (FlowVelocityData) bundle.getData(context),
158 bundle,
159 attr,
160 visible);
161 }
162 else if (name.equals(BED_DIFFERENCE_YEAR)) {
163 doBedDifferenceYearOut(
164 (BedDiffYearResult) bundle.getData(context),
165 bundle,
166 attr,
167 visible);
168 }
169 else if (name.equals(BED_DIFFERENCE_YEAR_FILTERED)) {
170 doBedDifferenceYearOut(
171 (BedDiffYearResult) bundle.getData(context),
172 bundle,
173 attr,
174 visible);
175 }
176 else if (name.equals(BED_DIFFERENCE_EPOCH)) {
177 doBedDifferenceEpochOut(
178 (BedDiffEpochResult) bundle.getData(context),
179 bundle,
180 attr,
181 visible);
182 }
183 else if (name.equals(W_DIFFERENCES)) {
184 doWDifferencesOut(
185 (WKms) bundle.getData(context),
186 bundle,
187 attr,
188 visible);
189 }
190 else if (name.equals(LONGITUDINAL_ANNOTATION)) {
191 doAnnotations(
192 (FLYSAnnotation) bundle.getData(context),
193 bundle,
194 attr,
195 visible);
196 }
197 else if (FacetTypes.IS.MANUALPOINTS(name)) {
198 doPoints(
199 bundle.getData(context),
200 bundle,
201 attr,
202 visible,
203 YAXIS.L.idx);
204 }
205 }
206
207 @Override
208 protected String getDefaultChartTitle() {
209 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
210 }
211
212 @Override
213 protected String getDefaultXAxisLabel() {
214 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
215 }
216
217 @Override
218 protected String getDefaultYAxisLabel(int pos) {
219 String label = "default";
220 if (pos == YAXIS.L.idx) {
221 SedimentLoadAccess access = new SedimentLoadAccess(artifact, context);
222 if (access.getUnit().equals("m3_per_a")) {
223 label = msg(I18N_YAXIS_LABEL_2, I18N_YAXIS_LABEL_DEFAULT_2);
224 }
225 else {
226 label = msg(I18N_YAXIS_LABEL_1, I18N_YAXIS_LABEL_DEFAULT_1);
227 }
228 }
229 else if (pos == YAXIS.V.idx) {
230 label = msg(I18N_YAXIS_V_LABEL, I18N_YAXIS_V_LABEL_DEFAULT);
231 }
232 else if (pos == YAXIS.D.idx) {
233 label = msg(I18N_YAXIS_D_LABEL, I18N_YAXIS_D_LABEL_DEFAULT);
234 }
235 else if (pos == YAXIS.DW.idx) {
236 label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
237 }
238
239 return label;
240 }
241
242 protected void doSedimentLoadOut(double[][] data,
243 ArtifactAndFacet aandf, Document theme, boolean visible) {
244
245 // Allow for gaps (NaNs).
246 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), false, theme);
247 StyledSeriesBuilder.addPoints(series, data, false);
248
249 addAxisSeries(series, YAXIS.L.idx, visible);
250 }
251
252 protected void doFlowVelocityMainOut(
253 FlowVelocityData data,
254 ArtifactAndFacet aandf,
255 Document theme,
256 boolean visible
257 ) {
258 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
259 StyledSeriesBuilder.addPoints(series, data.getMainChannelPoints(), true);
260
261 addAxisSeries(series, YAXIS.V.idx, visible);
262 }
263
264 protected void doFlowVelocityTotalOut(
265 FlowVelocityData data,
266 ArtifactAndFacet aandf,
267 Document theme,
268 boolean visible
269 ) {
270 if (data == null) {
271 logger.warn("No data to add to FlowVelocity chart.");
272 return;
273 }
274
275 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
276 StyledSeriesBuilder.addPoints(series, data.getTotalChannelPoints(), true);
277
278 addAxisSeries(series, YAXIS.V.idx, visible);
279 }
280
281 protected void doBedDifferenceYearOut(
282 BedDiffYearResult data,
283 ArtifactAndFacet aandf,
284 Document theme,
285 boolean visible
286 ) {
287 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
288 StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true);
289
290 addAxisSeries(series, YAXIS.D.idx, visible);
291 }
292
293 protected void doBedDifferenceEpochOut(
294 BedDiffEpochResult data,
295 ArtifactAndFacet aandf,
296 Document theme,
297 boolean visible
298 ) {
299 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
300 StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true);
301
302 addAxisSeries(series, YAXIS.D.idx, visible);
303 }
304
305 protected void doWDifferencesOut(
306 WKms wkms,
307 ArtifactAndFacet aandf,
308 Document theme,
309 boolean visible
310 ) {
311 if (wkms == null) {
312 logger.warn("No data to add to WDifferencesChart.");
313 return;
314 }
315
316 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
317
318 StyledSeriesBuilder.addPoints(series, wkms);
319
320 addAxisSeries(series, YAXIS.D.idx, visible);
321 if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
322 setInverted(true);
323 }
324 }
325 }

http://dive4elements.wald.intevation.org