annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeTablesOverview.java @ 5346:615e25b6440e

Fix HWSKind column name for the name of the kind
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 20 Mar 2013 16:32:07 +0100
parents f987d25627aa
children 02f6741f80d4
rev   line source
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.awt.Color;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.text.DateFormat;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.text.ParseException;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import java.util.ArrayList;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import java.util.Collections;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import java.util.Date;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import java.util.List;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import java.util.Locale;
5344
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
11 import java.util.Map;
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.hibernate.Session;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.jfree.chart.ChartFactory;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.jfree.chart.JFreeChart;
5344
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
17 import org.jfree.chart.plot.Marker;
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import org.jfree.chart.plot.PlotOrientation;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.jfree.chart.plot.XYPlot;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import org.jfree.data.xy.XYSeries;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import org.jfree.data.xy.XYSeriesCollection;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.Document;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 import org.w3c.dom.Element;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import org.w3c.dom.NodeList;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import de.intevation.artifacts.CallMeta;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 import de.intevation.artifacts.GlobalContext;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 import de.intevation.flys.artifacts.model.DischargeTables;
5344
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
29 import de.intevation.flys.artifacts.model.GaugeFinder;
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
30 import de.intevation.flys.artifacts.model.GaugeFinderFactory;
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
31 import de.intevation.flys.artifacts.model.GaugeRange;
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 import de.intevation.flys.artifacts.model.GaugesFactory;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 import de.intevation.flys.artifacts.resources.Resources;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 import de.intevation.flys.backend.SessionHolder;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 import de.intevation.flys.model.DischargeTable;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 import de.intevation.flys.model.Gauge;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 import de.intevation.flys.model.TimeInterval;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
5342
7b119fa1e29f Doc and vim-magiv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4230
diff changeset
40 /** Generate Discharge Table chart. */
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public class DischargeTablesOverview extends AbstractChartService {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 private static final Logger log = Logger
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 .getLogger(DischargeTablesOverview.class);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 private static final long serialVersionUID = 1L;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 public static final String I18N_CHART_TITLE = "gauge.discharge.service.chart.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 public static final String DEFAULT_CHART_TITLE = "Pegel: XXX";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 public static final String I18N_CHART_X_AXIS_TITLE = "gauge.discharge.service.chart.x.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 public static final String DEFAULT_X_AXIS_TITLE = "Q [m^3/s]";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public static final String I18N_CHART_Y_AXIS_TITLE = "gauge.discharge.service.chart.y.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public static final String DEFAULT_Y_AXIS_TITLE = "W [cm]";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public static final String I18N_CHART_SERIES_TITLE = "gauge.discharge.service.chart.series.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 public static final String DEFAULT_CHART_SERIES_TITLE = "Abflusskurve";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 public static final String I18N_CHART_SERIES_TITLE_MASTER = "gauge.discharge.service.chart.series.title.master";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 public static final String DEFAULT_CHART_SERIES_TITLE_MASTER = "Aktuelle Abflusskurve";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 DateFormat.SHORT, Locale.GERMANY);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 private Session session;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 @Override
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 protected void init() {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 session = SessionHolder.acquire();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 @Override
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 protected void finish() {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 if (session != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 session.close();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 SessionHolder.release();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 protected JFreeChart createChart(Document data,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 GlobalContext globalContext, CallMeta callMeta) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 Gauge gauge = extractGauge(data);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 if (gauge == null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 log.warn("Could not determine Gauge from request!");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 return null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 log.info("create discharge chart for gauge '" + gauge.getName() + "'");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 TimeInterval timerange = extractTimeInterval(data);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 List<DischargeTable> dts = getDischargeTables(gauge, timerange);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 XYSeriesCollection dataset = new XYSeriesCollection();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 for (DischargeTable dt : dts) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 try {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 XYSeries series = createSeries(callMeta, dt);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 if (series != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 dataset.addSeries(series);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 catch (IllegalArgumentException iae) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 log.warn("unable to create discharge curve: "
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 + iae.getMessage());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 String title = Resources.format(callMeta, I18N_CHART_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 DEFAULT_CHART_TITLE, gauge.getName());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 String xAxis = Resources.getMsg(callMeta, I18N_CHART_X_AXIS_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 DEFAULT_X_AXIS_TITLE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 String yAxis = Resources.format(callMeta, I18N_CHART_Y_AXIS_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 DEFAULT_Y_AXIS_TITLE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 JFreeChart chart = ChartFactory.createXYLineChart(title, xAxis, yAxis,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 null, PlotOrientation.VERTICAL, true, true, false);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 chart.setBackgroundPaint(Color.white);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 XYPlot plot = (XYPlot) chart.getPlot();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 plot.setDataset(0, dataset);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 plot.setBackgroundPaint(Color.white);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 plot.setDomainGridlinePaint(Color.gray);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 plot.setRangeGridlinePaint(Color.gray);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 plot.setDomainGridlinesVisible(true);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 plot.setRangeGridlinesVisible(true);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131
5344
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
132 applyMainValueMarkers(
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
133 plot,
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
134 gauge.getRiver().getName(),
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
135 gauge.getStation().doubleValue(),
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
136 callMeta);
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
137
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 return chart;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 protected XYSeries createSeries(CallMeta callMeta, DischargeTable dt)
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 throws IllegalArgumentException {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 double[][] xy = null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 if (dt.getKind() == DischargeTables.MASTER) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 xy = DischargeTables.loadDischargeTableValues(dt,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 DischargeTables.MASTER_SCALE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 else {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 xy = DischargeTables.loadDischargeTableValues(dt,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 DischargeTables.HISTORICAL_SCALE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 XYSeries series = new XYSeries(createSeriesTitle(callMeta, dt), false);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 for (int i = 0, n = xy[0].length; i < n; i++) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 series.add(xy[0][i], xy[1][i]);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 return series;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162
5344
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
163
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
164 /** Add domain markers to plot that indicate (only some Q) mainvalues. */
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
165 protected static void applyMainValueMarkers(
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
166 XYPlot plot,
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
167 String river,
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
168 double km,
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
169 CallMeta meta
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
170 ) {
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
171 GaugeFinderFactory ggf = GaugeFinderFactory.getInstance();
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
172 GaugeFinder gf = ggf.getGaugeFinder(river);
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
173
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
174 if (gf == null) {
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
175 log.warn("No gauge finder found for river '" + river + "'");
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
176 return;
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
177 }
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
178
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
179 GaugeRange gr = gf.find(km);
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
180 if (gr == null) {
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
181 log.debug("No gauge range found for km "
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
182 + km + " on river " + river + ".");
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
183 return;
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
184 }
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
185
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
186 if (log.isDebugEnabled()) {
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
187 log.debug(gr);
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
188 }
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
189
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
190 for (Map.Entry<String, Double> entry: gr.getMainValues().entrySet()) {
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
191 Marker m = FixingsKMChartService.createQSectorMarker(
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
192 entry.getValue(),
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
193 entry.getKey());
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
194
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
195 if (m != null) {
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
196 plot.addDomainMarker(m);
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
197 }
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
198 }
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
199 }
f987d25627aa Show some Q mainvalues in DischargeTablesOverview.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5342
diff changeset
200
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 protected String createSeriesTitle(CallMeta callMeta, DischargeTable dt)
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 throws IllegalArgumentException {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 TimeInterval timeInterval = dt.getTimeInterval();
4227
8138a90a674a Be more tolerant with empty time intervals in discharge tables while comparing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4217
diff changeset
204
8138a90a674a Be more tolerant with empty time intervals in discharge tables while comparing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4217
diff changeset
205 if (timeInterval == null) {
8138a90a674a Be more tolerant with empty time intervals in discharge tables while comparing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4217
diff changeset
206 return Resources.format(callMeta, DEFAULT_CHART_SERIES_TITLE);
8138a90a674a Be more tolerant with empty time intervals in discharge tables while comparing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4217
diff changeset
207 }
8138a90a674a Be more tolerant with empty time intervals in discharge tables while comparing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4217
diff changeset
208
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 Date start = timeInterval.getStartTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 Date end = timeInterval.getStopTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 if (start != null && end != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 return Resources.format(callMeta, I18N_CHART_SERIES_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 DEFAULT_CHART_SERIES_TITLE, start, end);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 else if (start != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 return Resources.format(callMeta, I18N_CHART_SERIES_TITLE_MASTER,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 DEFAULT_CHART_SERIES_TITLE, start);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 else {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 throw new IllegalArgumentException(
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 "Missing start date of DischargeTable " + dt.getId());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 protected Gauge extractGauge(Document data) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 NodeList gauges = data.getElementsByTagName("gauge");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 if (gauges.getLength() > 0) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 String name = ((Element) gauges.item(0)).getAttribute("name");
4217
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
231
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
232 try {
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
233 long officialNumber = Long.valueOf(name);
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
234 return Gauge.getGaugeByOfficialNumber(officialNumber);
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
235 }
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
236 catch (NumberFormatException nfe) {
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
237 // it seems, that the client uses the name of the gauge instead
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
238 // of its official number
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
239 }
08b6458909a9 The service 'DischargeTablesOverview' now accepts the official number of a gauge, too.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4213
diff changeset
240
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
241 if (name != null && name.length() > 0) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 return GaugesFactory.getGauge(name);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
243 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246 return null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249 protected TimeInterval extractTimeInterval(Document data) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
250 NodeList timeranges = data.getElementsByTagName("timerange");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
251
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
252 if (timeranges != null && timeranges.getLength() > 0) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253 Element timerange = (Element) timeranges.item(0);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
255 String lower = timerange.getAttribute("lower");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
256 String upper = timerange.getAttribute("upper");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
257
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
258 if (lower != null && upper != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
259 try {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
260 Date d1 = DATE_FORMAT.parse(lower);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
261 Date d2 = DATE_FORMAT.parse(upper);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
262
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
263 return new TimeInterval(d1, d2);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
264 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
265 catch (ParseException pe) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266 log.warn("Wrong time format: " + pe.getMessage());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
268 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
271 return null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
273
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
274 protected List<DischargeTable> getDischargeTables(Gauge gauge,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
275 TimeInterval timerange) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
276 List<DischargeTable> all = gauge.getDischargeTables();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277 Collections.sort(all);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
278
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
279 if (timerange == null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
280 return all;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
281 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
282
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
283 List<DischargeTable> dts = new ArrayList<DischargeTable>(all.size());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
284 long startDate = timerange.getStartTime().getTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
285 long stopDate = timerange.getStopTime().getTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
286
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
287 for (DischargeTable dt : all) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
288 TimeInterval tmp = dt.getTimeInterval();
4230
eab85cf85b10 Ignore discharge table without time interval set while discharge tables overview chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4227
diff changeset
289 if (tmp == null) {
eab85cf85b10 Ignore discharge table without time interval set while discharge tables overview chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4227
diff changeset
290 // this should never happen because all discharge tables should
eab85cf85b10 Ignore discharge table without time interval set while discharge tables overview chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4227
diff changeset
291 // have a time interval set!
eab85cf85b10 Ignore discharge table without time interval set while discharge tables overview chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4227
diff changeset
292 continue;
eab85cf85b10 Ignore discharge table without time interval set while discharge tables overview chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4227
diff changeset
293 }
eab85cf85b10 Ignore discharge table without time interval set while discharge tables overview chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4227
diff changeset
294
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
295 Date start = tmp.getStartTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
296 Date stop = tmp.getStartTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
297
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
298 if (start.getTime() > startDate && start.getTime() < stopDate) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
299 dts.add(dt);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
300 continue;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
301 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
302 else if (stop != null && stop.getTime() < stopDate
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
303 && stop.getTime() > startDate) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
304 dts.add(dt);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
305 continue;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
306 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
307 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
308
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
309 return dts;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
310 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
311 }
5342
7b119fa1e29f Doc and vim-magiv.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4230
diff changeset
312 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org