Mercurial > dive4elements > river
changeset 6298:f095b58c95d9 double-precision
Bedheight single parser: do not reject lines with missing values
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Wed, 12 Jun 2013 14:25:58 +0200 |
parents | 3d8f9e3bbf2e |
children | d518a42cdcd3 |
files | backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java backend/src/main/java/org/dive4elements/river/model/BedHeightSingleValue.java |
diffstat | 3 files changed, 100 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java Tue Jun 11 13:17:18 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java Wed Jun 12 14:25:58 2013 +0200 @@ -10,7 +10,7 @@ import java.util.List; -import java.math.BigDecimal; +//import java.math.BigDecimal; import org.apache.log4j.Logger; @@ -33,7 +33,8 @@ protected Double height; protected Double uncertainty; protected Double dataGap; - protected BigDecimal soundingWidth; + // protected BigDecimal soundingWidth; + protected Double soundingWidth; protected Double width; protected BedHeightSingleValue peer; @@ -45,7 +46,8 @@ Double height, Double uncertainty, Double dataGap, - BigDecimal soundingWidth, + // BigDecimal soundingWidth, + Double soundingWidth, Double width ) { this.bedHeight = bedHeight;
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java Tue Jun 11 13:17:18 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java Wed Jun 12 14:25:58 2013 +0200 @@ -39,6 +39,7 @@ */ @Override protected void handleDataLine(ImportBedHeight obj, String line) { + log.debug(line); String[] values = line.split(SEPERATOR_CHAR); if (values == null || (values.length != 1 && values.length < 6)) { @@ -76,44 +77,95 @@ // Because we cannot enforce consistency of values with complete data // via null constraints in the database (as there are "gap" values), // do this checks manually. - if (values[3].length() == 0 || values[4].length() == 0 - || values[5].length() == 0) { + // if (values[3].length() == 0 || values[4].length() == 0 + // || values[5].length() == 0) { //log.warn("BSP: Error while parsing data row (manual null constraint violated)."); - return; - } + // return; + //} - try { - ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( - (ImportBedHeightSingle) obj, - km, - new Double(nf.parse(values[1]).doubleValue()), - new Double(nf.parse(values[2]).doubleValue()), - new Double(nf.parse(values[3]).doubleValue()), - parseBigDecimal(values[4], line), - new Double(nf.parse(values[5]).doubleValue()) - ); + Double height = null; + if (values[1].length() > 0) { + try { + height = new Double(nf.parse(values[1]).doubleValue()); + } + catch (ParseException e) { + log.warn("BSP: unparseable height " + values[1]); + } + } - obj.addValue(value); - } - catch (ParseException e) { - log.warn("BSP: unparseable value in data row.", e); - } + Double uncertainty = null; + if (values[2].length() > 0) { + try { + uncertainty = new Double(nf.parse(values[2]).doubleValue()); + } + catch (ParseException e) { + log.warn("BSP: unparseable uncertainty value " + values[2]); + } + } + + Double dataGap = null; + if (values[3].length() > 0) { + try { + dataGap = new Double(nf.parse(values[3]).doubleValue()); + } + catch (ParseException e) { + log.warn("BSP: unparseable data gap " + values[3]); + } + } + + Double soundingWidth = null; + if (values[4].length() > 0) { + try { + soundingWidth = new Double(nf.parse(values[4]).doubleValue()); + } + catch (ParseException e) { + log.warn("BSP: unparseable sounding width " + values[4]); + } + } + + Double width = null; + if (values[5].length() > 0) { + try { + width = new Double(nf.parse(values[5]).doubleValue()); + } + catch (ParseException e) { + log.warn("BSP: unparseable width " + values[5]); + } + } + + // try { + ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( + (ImportBedHeightSingle) obj, + km, + height,//new Double(nf.parse(values[1]).doubleValue()), + uncertainty, + dataGap, + soundingWidth, + // parseBigDecimal(values[4], line), + width + ); + + obj.addValue(value); + // } +// catch (ParseException e) { +// log.warn("BSP: unparseable value in data row.", e); + //} } - private BigDecimal parseBigDecimal(String value, String line) { - BigDecimal result = null; - try { - Double dValue = Double.valueOf(value.replace(",", ".")); - result = new BigDecimal(dValue.doubleValue()); - } - catch (NumberFormatException nfe) { - log.warn( - "Could not parse " + - value + - " in bed heigt single row: " - + line); - } - return result; - } +// private BigDecimal parseBigDecimal(String value, String line) { +// BigDecimal result = null; +// try { +// Double dValue = Double.valueOf(value.replace(",", ".")); +// result = new BigDecimal(dValue.doubleValue()); +// } +// catch (NumberFormatException nfe) { +// log.warn( +// "Could not parse " + +// value + +// " in bed heigt single row: " +// + line); +// } +// return result; +// } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/model/BedHeightSingleValue.java Tue Jun 11 13:17:18 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/BedHeightSingleValue.java Wed Jun 12 14:25:58 2013 +0200 @@ -11,7 +11,7 @@ import java.util.List; import java.io.Serializable; -import java.math.BigDecimal; +//import java.math.BigDecimal; import javax.persistence.Entity; import javax.persistence.Id; @@ -47,7 +47,8 @@ private Double height; private Double uncertainty; private Double dataGap; - private BigDecimal soundingWidth; + // private BigDecimal soundingWidth; + private Double soundingWidth; private Double width; @@ -60,7 +61,8 @@ Double height, Double uncertainty, Double dataGap, - BigDecimal soundingWidth, + // BigDecimal soundingWidth, + Double soundingWidth, Double width ) { this.bedHeight = bedHeight; @@ -136,11 +138,13 @@ } @Column(name="sounding_width") - public BigDecimal getSoundingWidth() { + // public BigDecimal getSoundingWidth() { + public Double getSoundingWidth() { return soundingWidth; } - public void setSoundingWidth(BigDecimal soundingWidth) { + //public void setSoundingWidth(BigDecimal soundingWidth) { + public void setSoundingWidth(Double soundingWidth) { this.soundingWidth = soundingWidth; }