Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java @ 769:321b9e480f72
Added a method to river to find the gauge with the max overlap with a given interval.
flys-backend/trunk@2235 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 26 Jun 2011 16:13:08 +0000 |
parents | 23fe9ac1c3b4 |
children | 6dc847194625 |
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 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
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 de.intevation.flys.importer.ImportDischargeTable; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.flys.importer.ImportDischargeTableValue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
15 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
|
16 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
|
17 |
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.Date; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
19 import java.util.Calendar; |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 public class AtFileParser { |
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 static final String ENCODING = "ISO-8859-1"; |
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 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
|
26 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
28 // 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
|
29 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
|
30 "^\\*\\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
|
31 "(\\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
|
32 "(?:(\\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
|
33 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public AtFileParser() { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
38 public ImportDischargeTable parse(File file) throws IOException { |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
39 return parse(file, "", 0); |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
40 } |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
42 public ImportDischargeTable parse( |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
43 File file, |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
44 String prefix, |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
45 int kind |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
46 ) |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
47 throws IOException { |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 logger.info("parsing AT file: " + file); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 BufferedReader br = null; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 String line = null; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 boolean beginning = true; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
57 ImportDischargeTable dischargeTable = |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
58 new ImportDischargeTable(kind, prefix + file.getName()); |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
60 Date from = null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
61 Date to = null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
62 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 try { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 br = new BufferedReader( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 new InputStreamReader( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 new FileInputStream(file), ENCODING)); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 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
|
69 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 String tmp = line.trim(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 if (tmp.length() == 0) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
76 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
|
77 if (m.matches()) { |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
78 from = guessDate(m.group(2), m.group(3), m.group(4)); |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
79 to = guessDate(m.group(5), m.group(6), m.group(7)); |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
80 if (from == null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
81 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
|
82 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
83 continue; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
84 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
85 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 if (tmp.startsWith("#! name=")) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 // 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
|
88 // it at the moment |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 //String name = tmp.substring(8); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 if (tmp.startsWith("#") || tmp.startsWith("*")) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 } |
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 String[] splits = tmp.replace(',', '.').split("\\s+"); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 if ((splits.length < 2) || (splits.length > 11)) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 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
|
102 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 String strW = splits[0].trim(); |
504
ee693b8fbb55
Fixed flys/issue11 and flys51.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
106 double W = Double.parseDouble(strW); |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 /* 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
|
109 * 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
|
110 * 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
|
111 */ |
762
23fe9ac1c3b4
Fix for flys/issue110: Start index was shifted by one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
504
diff
changeset
|
112 int shift = -1; |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 if (splits.length != 11 && beginning) { |
762
23fe9ac1c3b4
Fix for flys/issue110: Start index was shifted by one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
504
diff
changeset
|
115 shift = 10 - splits.length; |
198
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 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 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
|
120 double iW = W + shift + i; |
504
ee693b8fbb55
Fixed flys/issue11 and flys51.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
121 double iQ = Double.parseDouble(splits[i].trim()); |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 dischargeTable.addDischargeTableValue( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 new ImportDischargeTableValue( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 new BigDecimal(iQ/100.0), |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 new BigDecimal(iW/100.0))); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 } |
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 beginning = false; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 } |
504
ee693b8fbb55
Fixed flys/issue11 and flys51.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
132 catch (NumberFormatException pe) { |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 logger.warn(pe.getMessage()); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 finally { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 if (br != null) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 br.close(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 |
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 if (from != null) { |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
142 if (to != null && from.compareTo(to) > 0) { |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
143 Date t = from; from = to; to = t; |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
144 } |
492
14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 } |
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
|
149 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 logger.info("Finished parsing AT file: " + file); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 return dischargeTable; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 } |
485
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 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
|
156 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
|
157 return null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
158 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
159 |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
160 logger.debug("day: " + day + " month: " + month + " year: " + year); |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
161 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
162 int dayI = 15; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
163 if (day != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
164 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
165 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
|
166 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
167 catch (NumberFormatException nfe) { |
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 } |
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 int monthI = 6; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
172 if (month != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
173 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
174 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
|
175 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
176 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
177 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
178 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
179 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
180 int yearI = 1900; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
181 if (year != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
182 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
183 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
|
184 if (yearI < 100) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
185 if (yearI < 20) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
186 yearI += 2000; |
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 else { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
189 yearI += 1900; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
190 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
191 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
192 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
193 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
194 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
195 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
196 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
197 Calendar cal = Calendar.getInstance(); |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
198 cal.set(yearI, monthI-1, dayI, 12, 0, 0); |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
199 long ms = cal.getTimeInMillis(); |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
492
diff
changeset
|
200 cal.setTimeInMillis(ms - ms%1000); |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
201 return cal.getTime(); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
202 } |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
203 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
204 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |