Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java @ 2832:ac5bd90697c1
Added new parser for flow velocity measurements and fixed some smaller bugs while importing flow velocity data.
flys-backend/trunk@4250 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 17 Apr 2012 13:00:04 +0000 |
parents | |
children | ed13816047b3 |
comparison
equal
deleted
inserted
replaced
2831:8fe9c6584b93 | 2832:ac5bd90697c1 |
---|---|
1 package de.intevation.flys.importer.parsers; | |
2 | |
3 import java.math.BigDecimal; | |
4 import java.text.DateFormat; | |
5 import java.text.NumberFormat; | |
6 import java.text.ParseException; | |
7 import java.text.SimpleDateFormat; | |
8 import java.util.ArrayList; | |
9 import java.util.List; | |
10 | |
11 import java.text.ParseException; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 import de.intevation.flys.importer.ImportFlowVelocityMeasurement; | |
16 import de.intevation.flys.importer.ImportFlowVelocityMeasurementValue; | |
17 | |
18 | |
19 public class FlowVelocityMeasurementParser extends LineParser { | |
20 | |
21 private static final Logger log = | |
22 Logger.getLogger(FlowVelocityMeasurementParser.class); | |
23 | |
24 private static final NumberFormat nf = | |
25 NumberFormat.getInstance(DEFAULT_LOCALE); | |
26 | |
27 private static final DateFormat df = | |
28 new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); | |
29 | |
30 | |
31 private List<ImportFlowVelocityMeasurement> measurements; | |
32 | |
33 private ImportFlowVelocityMeasurement current; | |
34 | |
35 | |
36 public FlowVelocityMeasurementParser() { | |
37 measurements = new ArrayList<ImportFlowVelocityMeasurement>(); | |
38 } | |
39 | |
40 | |
41 public List<ImportFlowVelocityMeasurement> getMeasurements() { | |
42 return measurements; | |
43 } | |
44 | |
45 @Override | |
46 protected void reset() { | |
47 current = new ImportFlowVelocityMeasurement(); | |
48 } | |
49 | |
50 | |
51 @Override | |
52 protected void finish() { | |
53 measurements.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 line = line.replace(";", ""); | |
70 current.setDescription(line); | |
71 } | |
72 | |
73 | |
74 public void handleDataLine(String line) { | |
75 String[] cols = line.split(SEPERATOR_CHAR); | |
76 | |
77 if (cols.length < 8) { | |
78 log.warn("skip invalid data line: '" + line + "'"); | |
79 return; | |
80 } | |
81 | |
82 try { | |
83 double km = nf.parse(cols[1]).doubleValue(); | |
84 double w = nf.parse(cols[5]).doubleValue(); | |
85 double q = nf.parse(cols[6]).doubleValue(); | |
86 double v = nf.parse(cols[7]).doubleValue(); | |
87 | |
88 String timestr = cols[3] + " " + cols[4]; | |
89 String description = cols.length > 8 ? cols[8] : null; | |
90 | |
91 current.addValue(new ImportFlowVelocityMeasurementValue( | |
92 df.parse(timestr), | |
93 new BigDecimal(km), | |
94 new BigDecimal(w), | |
95 new BigDecimal(q), | |
96 new BigDecimal(v), | |
97 description | |
98 )); | |
99 } | |
100 catch (ParseException pe) { | |
101 log.warn("Error while parsing flow velocity values.", pe); | |
102 } | |
103 } | |
104 } | |
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |