Mercurial > dive4elements > river
changeset 3958:64b73dc1571c
fix issue863: Handle missing data points for epoch bed height data.
flys-backend/trunk@5617 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 27 Sep 2012 12:55:26 +0000 |
parents | 3825aad9fb41 |
children | 6b1ca6ec4e3c |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java |
diffstat | 2 files changed, 38 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Thu Sep 27 12:53:09 2012 +0000 +++ b/flys-backend/ChangeLog Thu Sep 27 12:55:26 2012 +0000 @@ -1,3 +1,10 @@ +2012-09-27 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Backend-part for fix of issue863. + + * src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java: + Handle missing data points. + 2012-09-27 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java Thu Sep 27 12:53:09 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java Thu Sep 27 12:55:26 2012 +0000 @@ -1,12 +1,9 @@ package de.intevation.flys.importer.parsers; - import java.math.BigDecimal; import java.text.ParseException; - - import org.apache.log4j.Logger; import de.intevation.flys.importer.ImportBedHeight; @@ -14,32 +11,59 @@ import de.intevation.flys.importer.ImportBedHeightEpochValue; +/** Parses BedHeightEpochs from csv file. */ public class BedHeightEpochParser extends BedHeightParser { + /** Our own logger. */ private static final Logger log = Logger.getLogger(BedHeightEpochParser.class); - @Override protected ImportBedHeight newImportBedHeight(String description) { return new ImportBedHeightEpoch(description); } + /** + * Handle a non-comment, none-Metadata line of csv file, adding + * ImportBedHeightEpochValues to the given ImportBedHeight object. + */ @Override protected void handleDataLine(ImportBedHeight obj, String line) { - // TODO issue863: find gaps in data, analogous to 'single' case. String[] values = line.split(SEPERATOR_CHAR); - if (values == null || values.length < 2 || values[0].length() == 0 || values[1].length() == 0) { + if (values == null || values.length == 0 || values[0].length() == 0) { + // There might be quite some ";" found. //log.warn("Skip invalid data line: " + line); return; } + BigDecimal km; + + try { + km = new BigDecimal(nf.parse(values[0]).doubleValue()); + } + catch (ParseException e) { + log.warn("Error while parsing number from data row: " + line); + return; + } + + + // Handle "gap" lines like '255,0;' + if (values.length < 2) { + ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( + km, + null + ); + + obj.addValue(value); + return; + } + try { ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( - new BigDecimal(nf.parse(values[0]).doubleValue()), + km, new BigDecimal(nf.parse(values[1]).doubleValue()) );