annotate flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java @ 4082:d13011e53022

Make DIPS check more verbose flys-aft/trunk@3496 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 20 Dec 2011 14:36:36 +0000
parents fd6d0bc84117
children 067341e86375
rev   line source
4079
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.aft;
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Element;
4080
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
4 import org.w3c.dom.NodeList;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
5
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
6 import java.util.ArrayList;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
7 import java.util.List;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
8 import java.util.Date;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
9 import java.util.Calendar;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
10 import java.util.Collections;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
11 import java.util.Comparator;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
12
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
13 import java.util.regex.Pattern;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
14 import java.util.regex.Matcher;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
15
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
16 import org.apache.log4j.Logger;
4079
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public class DIPSGauge
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 {
4080
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
20 private static Logger log = Logger.getLogger(DIPSGauge.class);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
21
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
22 public static final Pattern DATE_PATTERN = Pattern.compile(
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
23 "(\\d{4})-(\\d{2})-(\\d{2})\\s+(\\d{2}):(\\d{2}):(\\d{2})");
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
24
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
25 public static final Comparator<Datum> DATE_CMP = new Comparator<Datum>() {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
26 public int compare(Datum a, Datum b) {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
27 return a.date.compareTo(b.date);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
28 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
29 };
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
30
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
31 public static class Datum {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
32
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
33 protected double value;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
34 protected Date date;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
35
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
36 public Datum() {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
37 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
38
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
39 public Datum(Element element) {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
40 value = Double.parseDouble(element.getAttribute("WERT"));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
41 String dateString = element.getAttribute("GUELTIGAB");
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
42 if (dateString.length() == 0) {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
43 throw
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
44 new IllegalArgumentException("missing GUELTIGAB attribute");
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
45 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
46 Matcher m = DATE_PATTERN.matcher(dateString);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
47 if (!m.matches()) {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
48 throw
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
49 new IllegalArgumentException("GUELTIGAB does not match");
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
50 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
51
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
52 int year = Integer.parseInt(m.group(1));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
53 int month = Integer.parseInt(m.group(2));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
54 int day = Integer.parseInt(m.group(3));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
55 int hours = Integer.parseInt(m.group(4));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
56 int mins = Integer.parseInt(m.group(5));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
57 int secs = Integer.parseInt(m.group(6));
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
58
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
59 Calendar cal = Calendar.getInstance();
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
60 cal.set(year, month, day, hours, mins, secs);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
61
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
62 date = cal.getTime();
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
63 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
64 } // class datum
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
65
4079
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 protected double aeo;
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
4082
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
68 protected String name;
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
69
4080
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
70 protected List<Datum> datums;
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
71
4079
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 public DIPSGauge() {
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 }
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 public DIPSGauge(Element element) {
4082
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
76
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
77 name = element.getAttribute("NAME");
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
78
4080
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
79 String aeoString = element.getAttribute("EINZUGSGEBIET_AEO");
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
80 if (aeoString.length() == 0) {
4082
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
81 log.warn("DIPS: Setting AEO of gauge '" + name + "' to zero.");
4080
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
82 aeoString = "0";
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
83 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
84 aeo = Double.parseDouble(aeoString);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
85
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
86 datums = new ArrayList<Datum>();
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
87 NodeList nodes = element.getElementsByTagName("PNP");
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
88 for (int i = 0, N = nodes.getLength(); i < N; ++i) {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
89 Element e = (Element)nodes.item(i);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
90 Datum datum = new Datum(e);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
91 datums.add(datum);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
92 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
93 Collections.sort(datums, DATE_CMP);
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
94 }
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
95
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
96 public List<Datum> getDatums() {
fd6d0bc84117 Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4079
diff changeset
97 return datums;
4079
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 }
4082
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
99
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
100 public String getName() {
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
101 return name;
d13011e53022 Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4080
diff changeset
102 }
4079
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
42094f01afa6 Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org