Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SQRelationParser.java Tue Mar 26 14:00:48 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SQRelationParser.java Tue Mar 26 14:02:58 2013 +0100 @@ -14,6 +14,7 @@ import de.intevation.flys.importer.ImportSQRelation; import de.intevation.flys.importer.ImportSQRelationValue; import de.intevation.flys.importer.ImportTimeInterval; +import de.intevation.flys.model.MeasurementStation; public class SQRelationParser extends LineParser { @@ -105,24 +106,59 @@ protected void handleDataLine(String line) { String[] cols = line.split(SEPERATOR_CHAR); - if (cols.length < 8) { + if (cols.length < 14) { log.warn("skip invalid data line: '" + line + "'"); return; } + Double km = parseDouble(cols[3], line); + Double a = parseDouble(cols[6], line); + Double b = parseDouble(cols[7], line); + Double qMax = parseDouble(cols[8], line); + Double rSq = parseDouble(cols[9], line); + Integer nTot = parseInteger(cols[10], line); + Integer nOutlier = parseInteger(cols[11], line); + Double cFer = parseDouble(cols[12], line); + Double cDuan = parseDouble(cols[13], line); + if (km == null || a == null || b == null) { + log.error("Incomplete SQ-relation row (missing km, a or b): " + + line); + return; + } + current.addValue(new ImportSQRelationValue( + cols[1], + cols[2], + km, + a, + b, + qMax, + rSq, + nTot, + nOutlier, + cFer, + cDuan)); + } + + private Double parseDouble(String value, String line) { + Double result = null; try { - current.addValue(new ImportSQRelationValue( - cols[1], - cols[2], - cols[4], - nf.parse(cols[3]).doubleValue(), - nf.parse(cols[6]).doubleValue(), - nf.parse(cols[7]).doubleValue() - )); + result = Double.valueOf(value.replace(",", ".")); } - catch (ParseException pe) { - log.warn("Error while parsing sq relation row: '" + line + "'", pe); + catch (NumberFormatException nfe) { + log.warn("Error parsing " + value + " in sq relation row: " + line); } + return result; + } + + private Integer parseInteger(String value, String line) { + Integer result = null; + try { + result = Integer.valueOf(value); + } + catch (NumberFormatException nfe) { + log.warn("Error parsing " + value + " in sq relation row: " + line); + } + return result; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :