comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/SQRelationParser.java @ 5429:13596605e81f

Added new columns to sq relation importer to import all values from csv and use measurement station instead of km.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 26 Mar 2013 14:02:58 +0100
parents f63b39799d2d
children 3bd786772798
comparison
equal deleted inserted replaced
5428:1cc82e328658 5429:13596605e81f
12 import org.apache.log4j.Logger; 12 import org.apache.log4j.Logger;
13 13
14 import de.intevation.flys.importer.ImportSQRelation; 14 import de.intevation.flys.importer.ImportSQRelation;
15 import de.intevation.flys.importer.ImportSQRelationValue; 15 import de.intevation.flys.importer.ImportSQRelationValue;
16 import de.intevation.flys.importer.ImportTimeInterval; 16 import de.intevation.flys.importer.ImportTimeInterval;
17 import de.intevation.flys.model.MeasurementStation;
17 18
18 19
19 public class SQRelationParser extends LineParser { 20 public class SQRelationParser extends LineParser {
20 21
21 private static final Logger log = 22 private static final Logger log =
103 104
104 105
105 protected void handleDataLine(String line) { 106 protected void handleDataLine(String line) {
106 String[] cols = line.split(SEPERATOR_CHAR); 107 String[] cols = line.split(SEPERATOR_CHAR);
107 108
108 if (cols.length < 8) { 109 if (cols.length < 14) {
109 log.warn("skip invalid data line: '" + line + "'"); 110 log.warn("skip invalid data line: '" + line + "'");
110 return; 111 return;
111 } 112 }
112 113
114 Double km = parseDouble(cols[3], line);
115 Double a = parseDouble(cols[6], line);
116 Double b = parseDouble(cols[7], line);
117 Double qMax = parseDouble(cols[8], line);
118 Double rSq = parseDouble(cols[9], line);
119 Integer nTot = parseInteger(cols[10], line);
120 Integer nOutlier = parseInteger(cols[11], line);
121 Double cFer = parseDouble(cols[12], line);
122 Double cDuan = parseDouble(cols[13], line);
123 if (km == null || a == null || b == null) {
124 log.error("Incomplete SQ-relation row (missing km, a or b): "
125 + line);
126 return;
127 }
128 current.addValue(new ImportSQRelationValue(
129 cols[1],
130 cols[2],
131 km,
132 a,
133 b,
134 qMax,
135 rSq,
136 nTot,
137 nOutlier,
138 cFer,
139 cDuan));
140 }
141
142 private Double parseDouble(String value, String line) {
143 Double result = null;
113 try { 144 try {
114 current.addValue(new ImportSQRelationValue( 145 result = Double.valueOf(value.replace(",", "."));
115 cols[1],
116 cols[2],
117 cols[4],
118 nf.parse(cols[3]).doubleValue(),
119 nf.parse(cols[6]).doubleValue(),
120 nf.parse(cols[7]).doubleValue()
121 ));
122 } 146 }
123 catch (ParseException pe) { 147 catch (NumberFormatException nfe) {
124 log.warn("Error while parsing sq relation row: '" + line + "'", pe); 148 log.warn("Error parsing " + value + " in sq relation row: " + line);
125 } 149 }
150 return result;
151 }
152
153 private Integer parseInteger(String value, String line) {
154 Integer result = null;
155 try {
156 result = Integer.valueOf(value);
157 }
158 catch (NumberFormatException nfe) {
159 log.warn("Error parsing " + value + " in sq relation row: " + line);
160 }
161 return result;
126 } 162 }
127 } 163 }
128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 164 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org