[Dive4elements-commits] [PATCH] Bedheight single parser: do not reject lines with missing values

Wald Commits scm-commit at wald.intevation.org
Wed Jun 12 14:26:02 CEST 2013


# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1371039958 -7200
# Branch double-precision
# Node ID f095b58c95d936494ac59ff089415e763eff9aae
# Parent  3d8f9e3bbf2e294f78360518fcc0a758dbeb0267
Bedheight single parser: do not reject lines with missing values

diff -r 3d8f9e3bbf2e -r f095b58c95d9 backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java
--- 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;
diff -r 3d8f9e3bbf2e -r f095b58c95d9 backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java
--- 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 :
diff -r 3d8f9e3bbf2e -r f095b58c95d9 backend/src/main/java/org/dive4elements/river/model/BedHeightSingleValue.java
--- 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;
     }
 


More information about the Dive4elements-commits mailing list