Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java @ 4080:fd6d0bc84117
Parse PNP from DIPS, too.
flys-aft/trunk@3455 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 18:51:26 +0000 |
parents | 42094f01afa6 |
children | d13011e53022 |
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 |
4080
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
68 protected List<Datum> datums; |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
69 |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 public DIPSGauge() { |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 public DIPSGauge(Element element) { |
4080
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
74 String aeoString = element.getAttribute("EINZUGSGEBIET_AEO"); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
75 if (aeoString.length() == 0) { |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
76 log.warn("WARN: setting AEO to zero"); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
77 aeoString = "0"; |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
78 } |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
79 aeo = Double.parseDouble(aeoString); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
80 |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
81 datums = new ArrayList<Datum>(); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
82 NodeList nodes = element.getElementsByTagName("PNP"); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
83 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
|
84 Element e = (Element)nodes.item(i); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
85 Datum datum = new Datum(e); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
86 datums.add(datum); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
87 } |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
88 Collections.sort(datums, DATE_CMP); |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
89 } |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
90 |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
91 public List<Datum> getDatums() { |
fd6d0bc84117
Parse PNP from DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
92 return datums; |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |