comparison 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
comparison
equal deleted inserted replaced
4079:42094f01afa6 4080:fd6d0bc84117
1 package de.intevation.aft; 1 package de.intevation.aft;
2 2
3 import org.w3c.dom.Element; 3 import org.w3c.dom.Element;
4 import org.w3c.dom.NodeList;
5
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.Date;
9 import java.util.Calendar;
10 import java.util.Collections;
11 import java.util.Comparator;
12
13 import java.util.regex.Pattern;
14 import java.util.regex.Matcher;
15
16 import org.apache.log4j.Logger;
4 17
5 public class DIPSGauge 18 public class DIPSGauge
6 { 19 {
20 private static Logger log = Logger.getLogger(DIPSGauge.class);
21
22 public static final Pattern DATE_PATTERN = Pattern.compile(
23 "(\\d{4})-(\\d{2})-(\\d{2})\\s+(\\d{2}):(\\d{2}):(\\d{2})");
24
25 public static final Comparator<Datum> DATE_CMP = new Comparator<Datum>() {
26 public int compare(Datum a, Datum b) {
27 return a.date.compareTo(b.date);
28 }
29 };
30
31 public static class Datum {
32
33 protected double value;
34 protected Date date;
35
36 public Datum() {
37 }
38
39 public Datum(Element element) {
40 value = Double.parseDouble(element.getAttribute("WERT"));
41 String dateString = element.getAttribute("GUELTIGAB");
42 if (dateString.length() == 0) {
43 throw
44 new IllegalArgumentException("missing GUELTIGAB attribute");
45 }
46 Matcher m = DATE_PATTERN.matcher(dateString);
47 if (!m.matches()) {
48 throw
49 new IllegalArgumentException("GUELTIGAB does not match");
50 }
51
52 int year = Integer.parseInt(m.group(1));
53 int month = Integer.parseInt(m.group(2));
54 int day = Integer.parseInt(m.group(3));
55 int hours = Integer.parseInt(m.group(4));
56 int mins = Integer.parseInt(m.group(5));
57 int secs = Integer.parseInt(m.group(6));
58
59 Calendar cal = Calendar.getInstance();
60 cal.set(year, month, day, hours, mins, secs);
61
62 date = cal.getTime();
63 }
64 } // class datum
65
7 protected double aeo; 66 protected double aeo;
67
68 protected List<Datum> datums;
8 69
9 public DIPSGauge() { 70 public DIPSGauge() {
10 } 71 }
11 72
12 public DIPSGauge(Element element) { 73 public DIPSGauge(Element element) {
13 aeo = Double.parseDouble(element.getAttribute("EINZUGSGEBIET_AEO")); 74 String aeoString = element.getAttribute("EINZUGSGEBIET_AEO");
75 if (aeoString.length() == 0) {
76 log.warn("WARN: setting AEO to zero");
77 aeoString = "0";
78 }
79 aeo = Double.parseDouble(aeoString);
80
81 datums = new ArrayList<Datum>();
82 NodeList nodes = element.getElementsByTagName("PNP");
83 for (int i = 0, N = nodes.getLength(); i < N; ++i) {
84 Element e = (Element)nodes.item(i);
85 Datum datum = new Datum(e);
86 datums.add(datum);
87 }
88 Collections.sort(datums, DATE_CMP);
89 }
90
91 public List<Datum> getDatums() {
92 return datums;
14 } 93 }
15 } 94 }
16 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org