Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java @ 492:14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
flys-backend/trunk@1840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 05 May 2011 15:25:16 +0000 |
parents | 8ea09ec7f0c8 |
children | b35c5dc0f8b7 |
rev | line source |
---|---|
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.io.BufferedReader; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.io.File; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.io.FileInputStream; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.io.InputStreamReader; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import java.io.IOException; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import java.math.BigDecimal; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import java.text.NumberFormat; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import java.text.ParseException; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import org.apache.log4j.Logger; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.importer.ImportDischargeTable; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.importer.ImportDischargeTableValue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
17 import java.util.regex.Pattern; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
18 import java.util.regex.Matcher; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
19 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
20 import java.util.Date; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
21 import java.util.Calendar; |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public class AtFileParser { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public static final String ENCODING = "ISO-8859-1"; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 private static Logger logger = Logger.getLogger(AtFileParser.class); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 private static NumberFormat nf = NumberFormat.getInstance(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
32 // regular expression from hell to find out time range |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
33 public static final Pattern DATE_LINE = Pattern.compile( |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
34 "^\\*\\s*Abflu[^t]+tafel?\\s*([^\\d]+)" + |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
35 "(\\d{1,2})?\\.?(\\d{1,2})?\\.?(\\d{2,4})\\s*(?:(?:bis)|-)?\\s*" + |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
36 "(?:(\\d{1,2})?\\.?(\\d{1,2})?\\.?(\\d{2,4}))?\\s*.*$"); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
37 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 public AtFileParser() { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
42 public ImportDischargeTable parse(File file) throws IOException { |
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
43 return parse(file, 0); |
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
44 } |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
46 public ImportDischargeTable parse(File file, int kind) throws IOException { |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 logger.info("parsing AT file: " + file); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 BufferedReader br = null; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 String line = null; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 boolean beginning = true; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
56 ImportDischargeTable dischargeTable = new ImportDischargeTable(kind); |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
58 Date from = null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
59 Date to = null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
60 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 try { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 br = new BufferedReader( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 new InputStreamReader( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 new FileInputStream(file), ENCODING)); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 while ((line = br.readLine()) != null) { |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
67 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 String tmp = line.trim(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 if (tmp.length() == 0) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
74 Matcher m = DATE_LINE.matcher(tmp); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
75 if (m.matches()) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
76 from = guessDate(m.group(1), m.group(2), m.group(3)); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
77 to = guessDate(m.group(4), m.group(5), m.group(6)); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
78 if (from == null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
79 Date t = from; from = to; to = t; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
80 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
81 continue; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
82 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
83 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 if (tmp.startsWith("#! name=")) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 // XXX Skip the name, because we don't know where to save |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 // it at the moment |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 //String name = tmp.substring(8); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 if (tmp.startsWith("#") || tmp.startsWith("*")) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 String[] splits = tmp.replace(',', '.').split("\\s+"); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 if ((splits.length < 2) || (splits.length > 11)) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 logger.warn("Found an invalid row in the AT file."); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 String strW = splits[0].trim(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 double W = nf.parse(strW).doubleValue(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 /* shift is used to differenciate between lines with |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 * exactly 10 Qs and lines with less than 10 Qs. The shift |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 * is only modified when it is the first line. |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 */ |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 int shift = 0; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 if (splits.length != 11 && beginning) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 shift = 11 - splits.length; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 for (int i = 1; i < splits.length; i++) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 double iW = W + shift + i; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 double iQ = nf.parse(splits[i].trim()).doubleValue(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 dischargeTable.addDischargeTableValue( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 new ImportDischargeTableValue( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 new BigDecimal(iQ/100.0), |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 new BigDecimal(iW/100.0))); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 beginning = false; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 catch (ParseException pe) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 logger.warn(pe.getMessage()); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 finally { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 if (br != null) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 br.close(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
485
diff
changeset
|
139 if (from != null) { |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
140 logger.info("from: " + from + " to: " + to); |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
485
diff
changeset
|
141 ImportTimeInterval interval = new ImportTimeInterval(from, to); |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
485
diff
changeset
|
142 dischargeTable.setTimeInterval(interval); |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
485
diff
changeset
|
143 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
485
diff
changeset
|
144 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 logger.info("Finished parsing AT file: " + file); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 return dischargeTable; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 } |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
149 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
150 public static Date guessDate(String day, String month, String year) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
151 if (day == null && month == null && year == null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
152 return null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
153 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
154 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
155 int dayI = 15; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
156 if (day != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
157 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
158 dayI = Integer.parseInt(day.trim()); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
159 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
160 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
161 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
162 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
163 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
164 int monthI = 6; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
165 if (month != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
166 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
167 monthI = Integer.parseInt(month.trim()); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
168 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
169 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
170 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
171 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
172 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
173 int yearI = 1900; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
174 if (year != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
175 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
176 yearI = Integer.parseInt(year.trim()); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
177 if (yearI < 100) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
178 if (yearI < 20) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
179 yearI += 2000; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
180 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
181 else { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
182 yearI += 1900; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
183 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
184 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
185 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
186 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
187 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
188 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
189 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
190 Calendar cal = Calendar.getInstance(); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
191 cal.set(yearI, monthI-1, dayI); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
192 return cal.getTime(); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
193 } |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |