annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/SQOverview.java @ 4761:ab87408bb0d3

W80Parser: Added field to store a date.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 04 Jan 2013 11:11:52 +0100
parents 35a6c9a49a76
children
rev   line source
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import java.text.SimpleDateFormat;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import java.util.ArrayList;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import java.util.Date;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import java.util.List;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import org.apache.log4j.Logger;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import org.hibernate.SQLQuery;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import org.hibernate.Session;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import org.hibernate.type.StandardBasicTypes;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import org.w3c.dom.Document;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import org.w3c.dom.Element;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.utils.KMIndex;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 public class SQOverview
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 implements Serializable
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 {
3778
35a6c9a49a76 Fixed wrong assigned loggers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3389
diff changeset
26 private static Logger log = Logger.getLogger(SQOverview.class);
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 /**
3276
4903e491992e Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3275
diff changeset
29 * Serial version UId.
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 */
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 private static final long serialVersionUID = -8934372438968398508L;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 public interface Filter {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 boolean accept(KMIndex<List<Date>> entry);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 } // interface Filter
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 public static final Filter ACCEPT = new Filter() {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 @Override
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 public boolean accept(KMIndex<List<Date>> entry) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 return true;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 };
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 public static class KmFilter implements Filter {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 protected double km;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 public KmFilter (double km) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 this.km = km;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 @Override
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 public boolean accept(KMIndex<List<Date>> list) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 for (KMIndex.Entry<List<Date>> e: list){
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 if (e.getKm() == km) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 return true;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 return false;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 };
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 public static class DateFilter implements Filter {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 protected Date date;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 public DateFilter (Date date) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 this.date = date;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 @Override
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 public boolean accept(KMIndex<List<Date>> list) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 for (KMIndex.Entry<List<Date>> e: list){
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 if (e.getValue().equals(this.date)) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 return true;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 return false;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 };
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
83 public static final double EPSILON = 1e-4;
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 public static final String DATE_FORMAT = "dd.MM.yyyy";
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 public static final String SQL_SQ =
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 "SELECT" +
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
89 " s.km AS km," +
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
90 " m.datum AS datum " +
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 "FROM messung m " +
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 " JOIN station s" +
3287
30f157c7e466 SQ: Filter out meassures which don't have a 'Siebsatz'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3276
diff changeset
93 " ON m.stationid = s.stationid " +
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 " JOIN gewaesser g " +
3287
30f157c7e466 SQ: Filter out meassures which don't have a 'Siebsatz'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3276
diff changeset
95 " ON s.gewaesserid = g.gewaesserid " +
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 "WHERE" +
3389
816ceb0418b9 Q is not taken from MESSUNG.Q but from MESSUNG.Q_BPEGEL
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3290
diff changeset
97 " m.q_bpegel IS NOT NULL AND" +
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 " g.name = :name " +
3287
30f157c7e466 SQ: Filter out meassures which don't have a 'Siebsatz'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3276
diff changeset
99 "ORDER by" +
30f157c7e466 SQ: Filter out meassures which don't have a 'Siebsatz'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3276
diff changeset
100 " s.km, m.datum";
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 protected String riverName;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 protected KMIndex<List<Date>> entries;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 public SQOverview() {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 entries = new KMIndex<List<Date>>();
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 public SQOverview(String riverName) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 this();
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 this.riverName = riverName;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
115 private static final boolean epsilonEquals(double a, double b) {
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
116 return Math.abs(a - b) < EPSILON;
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
117 }
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
118
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 protected void loadData(Session session) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120 SQLQuery query = session.createSQLQuery(SQL_SQ)
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3287
diff changeset
121 .addScalar("km", StandardBasicTypes.DOUBLE)
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3287
diff changeset
122 .addScalar("datum", StandardBasicTypes.DATE);
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 query.setString("name", riverName);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 List<Object []> list = query.list();
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 if (list.isEmpty()) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 log.warn("No river '" + riverName + "' found.");
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
132 Double prevKm = -Double.MAX_VALUE;
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 List<Date> dates = new ArrayList<Date>();
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
134
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
135 for (Object [] row: list) {
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
136 Double km = (Double)row[0];
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
137 if (!epsilonEquals(km, prevKm) && !dates.isEmpty()) {
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
138 entries.add(prevKm, dates);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 dates = new ArrayList<Date>();
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140 }
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
141 dates.add((Date)row[1]);
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 prevKm = km;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143 }
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
144
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
145 if (!dates.isEmpty()) {
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
146 entries.add(prevKm, dates);
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
147 }
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
148 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
149
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
150 public boolean load(Session session) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
151
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
152 loadData(session);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
153
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
154 return true;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
155 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
156
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
157
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
158 public void generateOverview(Document document) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
159 generateOverview(document, ACCEPT);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
160 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
161
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
162 public KMIndex<List<Date>> filter(Filter f) {
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
163 // TODO: Apply filter
3274
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
164 return entries;
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
165 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
166
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
167 public void generateOverview(
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
168 Document document,
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
169 Filter filter
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
170 ) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
171 KMIndex<List<Date>> filtered = filter(ACCEPT);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
172
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
173 Element sqElement = document.createElement("sq");
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
174
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
175 Element riverElement = document.createElement("river");
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
176
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177 riverElement.setAttribute("name", riverName);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
178
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
179 sqElement.appendChild(riverElement);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
180
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
181 SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
182
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
183 Element kmE = document.createElement("km");
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
184
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
185 for (KMIndex.Entry<List<Date>> e: filtered) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
186
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
187 List<Date> dates = e.getValue();
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
188
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
189 if (!dates.isEmpty()) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
190 Element dEs = document.createElement("dates");
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192 for (Date d: dates) {
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
193 Element dE = document.createElement("date");
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
194
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 dE.setAttribute("value", df.format(d));
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 dEs.appendChild(dE);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200 kmE.appendChild(dEs);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
203
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 sqElement.appendChild(kmE);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
205
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
206 document.appendChild(sqElement);
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
207 }
43e42315ce22 Added service for an overview chart of measuring points in sq relation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
208 }
3275
3570abdf7daa SQOverview: Made km separating of dates epsilon tolerant and avoid empty date lists.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3274
diff changeset
209 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org