Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java @ 2828:ac13e466a55e
Added a parser for flow velocity model data and adjusted the db relation schema (missing q column).
flys-backend/trunk@4245 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 17 Apr 2012 09:37:52 +0000 |
parents | |
children | 5b54a648f702 |
comparison
equal
deleted
inserted
replaced
2827:85b25e74594f | 2828:ac13e466a55e |
---|---|
1 package de.intevation.flys.importer.parsers; | |
2 | |
3 import java.math.BigDecimal; | |
4 import java.text.NumberFormat; | |
5 import java.text.ParseException; | |
6 import java.util.ArrayList; | |
7 import java.util.List; | |
8 import java.util.regex.Matcher; | |
9 import java.util.regex.Pattern; | |
10 | |
11 import java.text.ParseException; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 import de.intevation.flys.importer.ImportFlowVelocityModel; | |
16 import de.intevation.flys.importer.ImportFlowVelocityModelValue; | |
17 | |
18 | |
19 public class FlowVelocityModelParser extends LineParser { | |
20 | |
21 private static final Logger log = | |
22 Logger.getLogger(FlowVelocityModelParser.class); | |
23 | |
24 private static final Pattern META_REGEX = | |
25 Pattern.compile(".*Rechnung (.*) \\(Pegel (.*)\\).*"); | |
26 | |
27 private static final NumberFormat nf = | |
28 NumberFormat.getInstance(DEFAULT_LOCALE); | |
29 | |
30 | |
31 private List<ImportFlowVelocityModel> models; | |
32 | |
33 private ImportFlowVelocityModel current; | |
34 | |
35 | |
36 public FlowVelocityModelParser() { | |
37 models = new ArrayList<ImportFlowVelocityModel>(); | |
38 } | |
39 | |
40 | |
41 public List<ImportFlowVelocityModel> getModels() { | |
42 return models; | |
43 } | |
44 | |
45 @Override | |
46 protected void reset() { | |
47 current = new ImportFlowVelocityModel(); | |
48 } | |
49 | |
50 | |
51 @Override | |
52 protected void finish() { | |
53 models.add(current); | |
54 } | |
55 | |
56 | |
57 @Override | |
58 protected void handleLine(String line) { | |
59 if (line.startsWith(START_META_CHAR)) { | |
60 handleMetaLine(stripMetaLine(line)); | |
61 } | |
62 else { | |
63 handleDataLine(line); | |
64 } | |
65 } | |
66 | |
67 | |
68 public void handleMetaLine(String line) { | |
69 Matcher m = META_REGEX.matcher(line); | |
70 | |
71 if (m.matches()) { | |
72 String zoneStr = m.group(1); | |
73 String gaugeStr = m.group(2); | |
74 | |
75 log.debug("Found zone string: '" + zoneStr + "'"); | |
76 log.debug("Found gauge string: '" + gaugeStr + "'"); | |
77 | |
78 // TODO Do something with these information | |
79 } | |
80 } | |
81 | |
82 | |
83 public void handleDataLine(String line) { | |
84 String[] cols = line.split(SEPERATOR_CHAR); | |
85 | |
86 if (cols.length < 5) { | |
87 log.warn("skip invalid data line: '" + line + "'"); | |
88 return; | |
89 } | |
90 | |
91 try { | |
92 double km = nf.parse(cols[0]).doubleValue(); | |
93 double q = nf.parse(cols[1]).doubleValue(); | |
94 double total = nf.parse(cols[2]).doubleValue(); | |
95 double main = nf.parse(cols[3]).doubleValue(); | |
96 double stress = nf.parse(cols[4]).doubleValue(); | |
97 | |
98 current.addValue(new ImportFlowVelocityModelValue( | |
99 new BigDecimal(km), | |
100 new BigDecimal(q), | |
101 new BigDecimal(total), | |
102 new BigDecimal(main), | |
103 new BigDecimal(stress) | |
104 )); | |
105 } | |
106 catch (ParseException pe) { | |
107 log.warn("Error while parsing flow velocity values.", pe); | |
108 } | |
109 } | |
110 } | |
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |