annotate artifacts/src/main/java/org/dive4elements/river/artifacts/services/FixingsKMChartService.java @ 9312:740d65e4aa14

Q [m³/s] one message
author gernotbelger
date Thu, 26 Jul 2018 15:54:20 +0200
parents fe7e9da6312a
children 9744ce3c3853
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5373
diff changeset
9 package org.dive4elements.river.artifacts.services;
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
10
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
11 import java.awt.BasicStroke;
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
12 import java.awt.Color;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
13 import java.awt.Dimension;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
14 import java.awt.Transparency;
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
15 import java.awt.geom.Rectangle2D;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
16 import java.awt.image.BufferedImage;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
17 import java.io.ByteArrayOutputStream;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
18 import java.io.IOException;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
19 import java.util.ArrayList;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
20 import java.util.List;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
21
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
22 import javax.imageio.ImageIO;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
23
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 import org.apache.log4j.Logger;
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
25 import org.dive4elements.artifactdatabase.DefaultService;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
26 import org.dive4elements.artifacts.CallMeta;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
27 import org.dive4elements.artifacts.GlobalContext;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
28 import org.dive4elements.artifacts.Service;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
29 import org.dive4elements.river.artifacts.model.FixingsColumn;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
30 import org.dive4elements.river.artifacts.model.FixingsColumnFactory;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
31 import org.dive4elements.river.artifacts.model.FixingsFilterBuilder;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
32 import org.dive4elements.river.artifacts.model.FixingsOverview;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
33 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
34 import org.dive4elements.river.artifacts.model.FixingsOverviewFactory;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
35 import org.dive4elements.river.artifacts.model.GaugeFinder;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
36 import org.dive4elements.river.artifacts.model.GaugeFinderFactory;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
37 import org.dive4elements.river.artifacts.model.GaugeRange;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
38 import org.dive4elements.river.artifacts.model.fixings.QWI;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
39 import org.dive4elements.river.artifacts.resources.Resources;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
40 import org.dive4elements.river.backend.SessionHolder;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
41 import org.dive4elements.river.jfree.ShapeRenderer;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
42 import org.dive4elements.river.utils.Formatter;
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
43 import org.dive4elements.river.utils.Pair;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
44 import org.jfree.chart.ChartFactory;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
45 import org.jfree.chart.JFreeChart;
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
46 import org.jfree.chart.LegendItemCollection;
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
47 import org.jfree.chart.axis.NumberAxis;
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
48 import org.jfree.chart.plot.Marker;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
49 import org.jfree.chart.plot.PlotOrientation;
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
50 import org.jfree.chart.plot.ValueMarker;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
51 import org.jfree.chart.plot.XYPlot;
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
52 import org.jfree.data.Range;
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
53 import org.jfree.ui.RectangleAnchor;
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
54 import org.jfree.ui.TextAnchor;
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 import org.w3c.dom.Document;
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
56 import org.w3c.dom.Element;
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
57 import org.w3c.dom.NodeList;
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
3571
64a59cca1887 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3174
diff changeset
59 /** Serve chart of Fixings at certain km. */
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
60 public class FixingsKMChartService extends DefaultService {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
61 private static final Logger log = Logger.getLogger(FixingsKMChartService.class);
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
63 public static final int DEFAULT_WIDTH = 240;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
64 public static final int DEFAULT_HEIGHT = 180;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
65
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
66 public static final String[] I18N_Q_SECTOR_BOARDERS = { "fix.km.chart.q.sector.border0", "fix.km.chart.q.sector.border1", "fix.km.chart.q.sector.border2" };
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
67
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
68 public static final String[] DEFAULT_Q_SECTOR_BORDERS = { "(MNQ + MQ)/2", "(MQ + MHQ)/2", "HQ5" };
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
69
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
70 public static final String I18N_CHART_LABEL_DATE = "fix.km.chart.label.date";
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
71
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
72 public static final String DEFAULT_CHART_LABEL_DATE = "yyyy/MM/dd";
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
73
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
74 public static final String I18N_CHART_TITLE = "fix.km.chart.title";
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
75
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
76 public static final String DEFAULT_CHART_TITLE = "Fixings {0} km {1,number,#.###}";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
77
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
78 public static final String I18N_Q_AXIS = "common.export.csv.header.q";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
79
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
80 public static final String DEFAULT_Q_AXIS = "Q [m\u00b3/s]";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
81
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
82 public static final String I18N_W_AXIS = "fix.km.chart.w.axis";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
83
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
84 public static final String DEFAULT_W_AXIS = "W [NN + m]";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
85
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
86 public static final String I18N_MEASURED = "fix.km.chart.measured";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
87
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
88 public static final String DEFAULT_MEASURED = "measured";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
89
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
90 public static final String I18N_INTERPOLATED = "fix.km.chart.interpolated";
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
91
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
92 public static final String DEFAULT_INTERPOLATED = "interpolated";
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
93
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
94 public static final String DEFAULT_FORMAT = "png";
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
95
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
96 // TODO: Load fancy image from resources.
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
97 public static final byte[] EMPTY = { (byte) 0x89, (byte) 0x50, (byte) 0x4e, (byte) 0x47, (byte) 0x0d, (byte) 0x0a, (byte) 0x1a, (byte) 0x0a, (byte) 0x00,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
98 (byte) 0x00, (byte) 0x00, (byte) 0x0d, (byte) 0x49, (byte) 0x48, (byte) 0x44, (byte) 0x52, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
99 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x3a, (byte) 0x7e,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
100 (byte) 0x9b, (byte) 0x55, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x73, (byte) 0x52, (byte) 0x47, (byte) 0x42, (byte) 0x00,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
101 (byte) 0xae, (byte) 0xce, (byte) 0x1c, (byte) 0xe9, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x09, (byte) 0x70, (byte) 0x48, (byte) 0x59,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
102 (byte) 0x73, (byte) 0x00, (byte) 0x00, (byte) 0x0b, (byte) 0x13, (byte) 0x00, (byte) 0x00, (byte) 0x0b, (byte) 0x13, (byte) 0x01, (byte) 0x00,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
103 (byte) 0x9a, (byte) 0x9c, (byte) 0x18, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x74, (byte) 0x49, (byte) 0x4d, (byte) 0x45,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
104 (byte) 0x07, (byte) 0xdc, (byte) 0x04, (byte) 0x04, (byte) 0x10, (byte) 0x30, (byte) 0x15, (byte) 0x7d, (byte) 0x77, (byte) 0x36, (byte) 0x0b,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
105 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x74, (byte) 0x45, (byte) 0x58, (byte) 0x74, (byte) 0x43, (byte) 0x6f, (byte) 0x6d,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
106 (byte) 0x6d, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x00, (byte) 0xf6, (byte) 0xcc, (byte) 0x96, (byte) 0xbf, (byte) 0x00, (byte) 0x00,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
107 (byte) 0x00, (byte) 0x0a, (byte) 0x49, (byte) 0x44, (byte) 0x41, (byte) 0x54, (byte) 0x08, (byte) 0xd7, (byte) 0x63, (byte) 0xf8, (byte) 0x0f,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
108 (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1b, (byte) 0xb6, (byte) 0xee, (byte) 0x56, (byte) 0x00, (byte) 0x00,
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
109 (byte) 0x00, (byte) 0x00, (byte) 0x49, (byte) 0x45, (byte) 0x4e, (byte) 0x44, (byte) 0xae, (byte) 0x42, (byte) 0x60, (byte) 0x82 };
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
110
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
111 private static final Output empty() {
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
112 return new Output(EMPTY, "image/png");
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
113 }
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 @Override
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
116 public Service.Output process(final Document data, final GlobalContext globalContext, final CallMeta callMeta) {
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 log.debug("FixingsKMChartService.process");
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
118
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
119 SessionHolder.acquire();
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
120 try {
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
121 return doProcess(data, globalContext, callMeta);
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
122 } finally {
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
123 SessionHolder.release();
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
124 }
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
125 }
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
126
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
127 protected Service.Output doProcess(final Document input, final GlobalContext globalContext, final CallMeta callMeta) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
128 final String river = getRiverName(input);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
129 final Double km = getKM(input);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
130 final Dimension extent = getExtent(input);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
131 final String format = getFormat(input);
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
132
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
133 if (river == null || km == null) {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
134 log.warn("River and/or km invalid.");
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
135 return empty();
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
136 }
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
137
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
138 final FixingsOverview overview = FixingsOverviewFactory.getOverview(river);
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
139
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
140 if (overview == null) {
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
141 log.warn("No overview found for river '" + river + "'");
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
142 return empty();
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
143 }
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
144
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
145 final FixingsFilterBuilder ffb = new FixingsFilterBuilder(input);
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
146
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
147 final List<Fixing.Column> columns = overview.filter(ffb.getRange(), ffb.getFilter());
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
148
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
149 final List<Pair<Fixing.Column, FixingsColumn>> cols = new ArrayList<>();
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
150
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
151 for (final Fixing.Column col : columns) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
152 final FixingsColumn data = FixingsColumnFactory.INSTANCE.getColumnData(col);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
153 if (data != null) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
154 cols.add(new Pair<>(col, data));
2615
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
155 }
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
156 }
b0597a63fe70 More code for the fixings km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2614
diff changeset
157
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
158 final JFreeChart chart = createChart(cols, river, km, callMeta);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
159
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
160 return encode(chart, extent, format);
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
161 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
162
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
163 protected static Output encode(final JFreeChart chart, final Dimension extent, final String format) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
164 final BufferedImage image = chart.createBufferedImage(extent.width, extent.height, Transparency.BITMASK, null);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
165
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
166 final ByteArrayOutputStream out = new ByteArrayOutputStream();
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
167
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
168 try {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
169 ImageIO.write(image, format, out);
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
170 }
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
171 catch (final IOException ioe) {
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
172 log.warn("writing image failed", ioe);
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
173 return empty();
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
174 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
175
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
176 return new Output(out.toByteArray(), "image/" + format);
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
177 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
178
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
179 protected static JFreeChart createChart(final List<Pair<Fixing.Column, FixingsColumn>> cols, final String river, final double km, final CallMeta callMeta) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
180 final String labelFormat = Resources.getMsg(callMeta, I18N_CHART_LABEL_DATE, DEFAULT_CHART_LABEL_DATE);
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
181
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
182 final QWSeriesCollection.LabelGenerator lg = new QWSeriesCollection.DateFormatLabelGenerator(labelFormat);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
183
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
184 final QWSeriesCollection dataset = new QWSeriesCollection(lg);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
185
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
186 final double[] w = new double[1];
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
187 for (final Pair<Fixing.Column, FixingsColumn> col : cols) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
188 final boolean interpolated = !col.getB().getW(km, w);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
189 final double q = col.getB().getQ(km);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
190 if (!Double.isNaN(w[0]) && !Double.isNaN(q)) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
191 final QWI qw = new QWI(q, w[0], col.getA().getDescription(), col.getA().getStartTime(), interpolated, 0);
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
192 dataset.add(qw);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
193 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
194 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
195
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
196 final String title = Resources.format(callMeta, I18N_CHART_TITLE, DEFAULT_CHART_TITLE, river, km);
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
197
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
198 final String qAxis = Resources.getMsg(callMeta, I18N_Q_AXIS, DEFAULT_Q_AXIS);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
199
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
200 final String wAxis = Resources.getMsg(callMeta, I18N_W_AXIS, DEFAULT_W_AXIS);
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
201
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
202 final JFreeChart chart = ChartFactory.createXYLineChart(title, qAxis, wAxis, null, PlotOrientation.VERTICAL, true, true, false);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
203
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
204 final XYPlot plot = (XYPlot) chart.getPlot();
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
205
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
206 final NumberAxis qA = (NumberAxis) plot.getDomainAxis();
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
207 qA.setNumberFormatOverride(Formatter.getWaterlevelQ(callMeta));
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
208
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
209 final NumberAxis wA = (NumberAxis) plot.getRangeAxis();
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
210 wA.setNumberFormatOverride(Formatter.getWaterlevelW(callMeta));
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
211
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
212 plot.setRenderer(0, dataset.createRenderer());
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
213 plot.setDataset(0, dataset);
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
214
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
215 final Rectangle2D area = dataset.getArea();
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
216
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
217 if (area != null) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
218 final double height = area.getHeight();
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
219 final double wInset = Math.max(height, 0.01) * 0.25d;
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
220
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
221 wA.setAutoRangeIncludesZero(false);
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
222 wA.setRange(new Range(area.getMinY() - wInset, area.getMaxY() + wInset));
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
223 }
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
224
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
225 final String measuredS = Resources.getMsg(callMeta, I18N_MEASURED, DEFAULT_MEASURED);
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
226
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
227 final String interpolatedS = Resources.getMsg(callMeta, I18N_INTERPOLATED, DEFAULT_INTERPOLATED);
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
228
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
229 final LegendItemCollection lic = plot.getLegendItems();
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
230 dataset.addLegendItems(lic, new ShapeRenderer.LabelGenerator() {
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
231 @Override
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
232 public String createLabel(final ShapeRenderer.Entry entry) {
3173
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
233 return entry.getFilled() ? measuredS : interpolatedS;
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
234 }
0cf647fe2a96 FixA: Finished I18N for km chart service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3170
diff changeset
235 });
3162
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
236 plot.setFixedLegendItems(lic);
0d8146989012 Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3152
diff changeset
237
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
238 applyQSectorMarkers(plot, river, km, callMeta);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
239
3164
6d0567a8387d Label more points in FixingsKMChartService
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3162
diff changeset
240 chart.setBackgroundPaint(Color.white);
6d0567a8387d Label more points in FixingsKMChartService
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3162
diff changeset
241 plot.setBackgroundPaint(Color.white);
6d0567a8387d Label more points in FixingsKMChartService
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3162
diff changeset
242 plot.setDomainGridlinePaint(Color.gray);
6d0567a8387d Label more points in FixingsKMChartService
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3162
diff changeset
243 plot.setRangeGridlinePaint(Color.gray);
6d0567a8387d Label more points in FixingsKMChartService
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3162
diff changeset
244 plot.setDomainGridlinesVisible(true);
6d0567a8387d Label more points in FixingsKMChartService
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3162
diff changeset
245 plot.setRangeGridlinesVisible(true);
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
246
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
247 return chart;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
248 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
249
3577
25cce741d03c Rudimentary Themeing for qsector lines.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3571
diff changeset
250 /** Add domain markers to plot that indicate Q-sectors. */
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
251 protected static void applyQSectorMarkers(final XYPlot plot, final String river, final double km, final CallMeta meta) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
252 final GaugeFinderFactory ggf = GaugeFinderFactory.getInstance();
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
253 final GaugeFinder gf = ggf.getGaugeFinder(river);
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
254
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
255 if (gf == null) {
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
256 log.warn("No gauge finder found for river '" + river + "'");
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
257 return;
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
258 }
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
259
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
260 final GaugeRange gr = gf.find(km);
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
261 if (gr == null) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
262 log.debug("No gauge range found for km " + km + " on river " + river + ".");
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
263 return;
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
264 }
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
265
3151
08230c76cd92 FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3146
diff changeset
266 if (log.isDebugEnabled()) {
08230c76cd92 FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3146
diff changeset
267 log.debug(gr);
08230c76cd92 FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3146
diff changeset
268 }
08230c76cd92 FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3146
diff changeset
269
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
270 for (int i = 0; i < I18N_Q_SECTOR_BOARDERS.length; ++i) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
271 final String key = I18N_Q_SECTOR_BOARDERS[i];
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
272 final String def = DEFAULT_Q_SECTOR_BORDERS[i];
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
273 final String label = Resources.getMsg(meta, key, def);
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
274
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
275 final Marker m = createQSectorMarker(gr.getSectorBorder(i), label);
3170
79e7bba0f593 FixA: I18N for chart km service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3166
diff changeset
276
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
277 if (m != null) {
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
278 plot.addDomainMarker(m);
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
279 }
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
280 }
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
281 }
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
282
5373
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3729
diff changeset
283 /** Create Marker at value with label. */
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
284 protected static Marker createQSectorMarker(final double value, final String label) {
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
285 if (Double.isNaN(value)) {
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
286 return null;
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
287 }
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
288 final Marker m = new ValueMarker(value);
3146
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
289 m.setPaint(Color.black);
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
290 m.setStroke(new BasicStroke());
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
291 m.setLabel(label);
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
292 m.setLabelAnchor(RectangleAnchor.TOP_LEFT);
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
293 m.setLabelTextAnchor(TextAnchor.TOP_LEFT);
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
294 return m;
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
295 }
1edc17b0d79d FixA: Draw domain markers for borders of Q sectors in helper diagram.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3076
diff changeset
296
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
297 protected static String getRiverName(final Document input) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
298 final NodeList rivers = input.getElementsByTagName("river");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
299
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
300 if (rivers.getLength() == 0) {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
301 return null;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
302 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
303
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
304 final String river = ((Element) rivers.item(0)).getAttribute("name");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
305
2621
f0cc556eda29 FixingsKMChartService.java: Small fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2620
diff changeset
306 return river.length() > 0 ? river : null;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
307 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
308
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
309 protected static Double getKM(final Document input) {
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
310 final NodeList kms = input.getElementsByTagName("km");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
311
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
312 if (kms.getLength() == 0) {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
313 return null;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
314 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
315
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
316 final String km = ((Element) kms.item(0)).getAttribute("value");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
317
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
318 try {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
319 return Double.valueOf(km);
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
320 }
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
321 catch (final NumberFormatException nfe) {
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
322 log.warn("Km '" + km + " is not a valid number.");
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
323 return null;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
324 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
325 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
326
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
327 protected static Dimension getExtent(final Document input) {
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
328
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
329 int width = DEFAULT_WIDTH;
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
330 int height = DEFAULT_HEIGHT;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
331
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
332 final NodeList extents = input.getElementsByTagName("extent");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
333
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
334 if (extents.getLength() > 0) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
335 final Element element = (Element) extents.item(0);
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
336 final String w = element.getAttribute("width");
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
337 final String h = element.getAttribute("height");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
338
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
339 try {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
340 width = Math.max(1, Integer.parseInt(w));
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
341 }
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
342 catch (final NumberFormatException nfe) {
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
343 log.warn("width '" + w + "' is not a valid.");
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
344 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
345
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
346 try {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
347 height = Math.max(1, Integer.parseInt(h));
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
348 }
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
349 catch (final NumberFormatException nfe) {
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
350 log.warn("height '" + h + "' is not a valid");
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
351 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
352 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
353
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
354 return new Dimension(width, height);
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
355 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
356
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
357 protected static String getFormat(final Document input) {
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
358 String format = DEFAULT_FORMAT;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
359
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
360 final NodeList formats = input.getElementsByTagName("format");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
361
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
362 if (formats.getLength() > 0) {
9312
740d65e4aa14 Q [m³/s] one message
gernotbelger
parents: 8566
diff changeset
363 final String type = ((Element) formats.item(0)).getAttribute("type");
2620
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
364 if (type.length() > 0) {
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
365 format = type;
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
366 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
367 }
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
368
cc0fa1798a3c FixingsKMChartService: Generate chart and deliver the image as the response of the service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2615
diff changeset
369 return format;
2614
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
370 }
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
371 }
036e234c2385 Added service to generate a chart of fixings for given river and km applied
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
372 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org