changeset 6338:d518a42cdcd3 double-precision

merge changes from default into double-precision
author Tom Gottfried <tom.gottfried@intevation.de>
date Fri, 14 Jun 2013 16:46:33 +0200
parents f095b58c95d9 (diff) 1173e9f47b52 (current diff)
children d50348a1506b
files backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java
diffstat 5 files changed, 167 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/backend/doc/schema/oracle-minfo.sql	Wed Jun 12 11:43:34 2013 +0200
+++ b/backend/doc/schema/oracle-minfo.sql	Fri Jun 14 16:46:33 2013 +0200
@@ -85,12 +85,12 @@
 CREATE TABLE bed_height_single_values (
     id                      NUMBER(38,0) NOT NULL,
     bed_height_single_id    NUMBER(38,0) NOT NULL,
-    station                 NUMBER(38,2) NOT NULL,
-    height                  NUMBER(38,2),
-    uncertainty             NUMBER(38,2),
-    data_gap                NUMBER(38,2),
-    sounding_width          NUMBER(38,2),
-    width                   NUMBER(38,2),
+    station                 DOUBLE PRECISION NOT NULL,
+    height                  DOUBLE PRECISION,
+    uncertainty             DOUBLE PRECISION,
+    data_gap                DOUBLE PRECISION,
+    sounding_width          DOUBLE PRECISION,
+    width                   DOUBLE PRECISION,
     PRIMARY KEY(id),
     UNIQUE (station, bed_height_single_id),
     CONSTRAINT fk_bed_single_values_parent FOREIGN KEY (bed_height_single_id) REFERENCES bed_height_single(id) ON DELETE CASCADE
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java	Wed Jun 12 11:43:34 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java	Fri Jun 14 16:46:33 2013 +0200
@@ -10,7 +10,7 @@
 
 import java.util.List;
 
-import java.math.BigDecimal;
+//import java.math.BigDecimal;
 
 import org.apache.log4j.Logger;
 
@@ -29,24 +29,26 @@
 
     protected ImportBedHeightSingle bedHeight;
 
-    protected BigDecimal station;
-    protected BigDecimal height;
-    protected BigDecimal uncertainty;
-    protected BigDecimal dataGap;
-    protected BigDecimal soundingWidth;
-    protected BigDecimal width;
+    protected Double station;
+    protected Double height;
+    protected Double uncertainty;
+    protected Double dataGap;
+    //    protected BigDecimal soundingWidth;
+    protected Double soundingWidth;
+    protected Double width;
 
     protected BedHeightSingleValue peer;
 
 
     public ImportBedHeightSingleValue(
         ImportBedHeightSingle bedHeight,
-        BigDecimal station,
-        BigDecimal height,
-        BigDecimal uncertainty,
-        BigDecimal dataGap,
-        BigDecimal soundingWidth,
-        BigDecimal width
+        Double station,
+        Double height,
+        Double uncertainty,
+        Double dataGap,
+	//        BigDecimal soundingWidth,
+	Double soundingWidth,
+        Double width
     ) {
         this.bedHeight     = bedHeight;
         this.station       = station;
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Wed Jun 12 11:43:34 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Fri Jun 14 16:46:33 2013 +0200
@@ -19,6 +19,7 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.TreeSet;
 import java.util.Locale;
 
 import java.util.regex.Matcher;
@@ -40,6 +41,7 @@
 import org.dive4elements.river.importer.ImportUnit;
 import org.dive4elements.river.model.BedHeightType;
 import org.dive4elements.river.importer.ImporterSession;
+import org.dive4elements.river.utils.EpsilonComparator;
 import org.dive4elements.river.importer.parsers.LineParser;
 
 public abstract class BedHeightParser {
@@ -99,10 +101,12 @@
         String          line
     );
 
+    protected TreeSet<Double> kmExists;
 
 
     public BedHeightParser() {
-        this.bedHeights = new ArrayList<ImportBedHeight>();
+        bedHeights = new ArrayList<ImportBedHeight>();
+        kmExists = new TreeSet<Double>(EpsilonComparator.CMP);
     }
 
 
@@ -116,12 +120,15 @@
 
         ImportBedHeight obj = newImportBedHeight(file.getName().replaceAll("\\.csv", ""));
 
-        LineNumberReader in =
-            new LineNumberReader(
-            new InputStreamReader(
-            new FileInputStream(file), ENCODING));
+        kmExists.clear();
 
+        LineNumberReader in = null;
         try {
+            in =
+                new LineNumberReader(
+                new InputStreamReader(
+                new FileInputStream(file), ENCODING));
+
             String line = null;
             while ((line = in.readLine()) != null) {
                 if ((line = line.trim()).length() == 0) {
@@ -140,7 +147,9 @@
             bedHeights.add(obj);
         }
         finally {
-            in.close();
+            if (in != null) {
+                in.close();
+            }
         }
     }
 
@@ -330,7 +339,7 @@
             String tmp = m.group(1).replace(";", "").trim();
 
             BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(
-                tmp, ImporterSession.getInstance().getDatabaseSession());
+		tmp, ImporterSession.getInstance().getDatabaseSession());
 
             if (bht != null) {
                 obj.setType(new ImportBedHeightType(bht));
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java	Wed Jun 12 11:43:34 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java	Fri Jun 14 16:46:33 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)) {
@@ -46,11 +47,21 @@
             return;
         }
 
-        BigDecimal km;
+        Double km;
 
         try {
-            km = new BigDecimal(nf.parse(values[0]).doubleValue());
-        }
+            km = new Double(nf.parse(values[0]).doubleValue());
+	    
+            Double key = Double.valueOf(km);
+
+            if (kmExists.contains(key)) {
+                log.warn("duplicate station '" + km + "': -> ignored");
+                return;
+            }
+
+            kmExists.add(key);
+	}
+
         catch (ParseException e) {
             // We expect a lot of ";;;;;;" lines.
             //log.warn("BSP: Error while parsing km of data row.", e);
@@ -66,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 BigDecimal(nf.parse(values[1]).doubleValue()),
-                new BigDecimal(nf.parse(values[2]).doubleValue()),
-                new BigDecimal(nf.parse(values[3]).doubleValue()),
-                parseBigDecimal(values[4], line),
-                new BigDecimal(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	Wed Jun 12 11:43:34 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/BedHeightSingleValue.java	Fri Jun 14 16:46:33 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;
@@ -43,12 +43,13 @@
 
     private BedHeightSingle bedHeight;
 
-    private BigDecimal station;
-    private BigDecimal height;
-    private BigDecimal uncertainty;
-    private BigDecimal dataGap;
-    private BigDecimal soundingWidth;
-    private BigDecimal width;
+    private Double station;
+    private Double height;
+    private Double uncertainty;
+    private Double dataGap;
+    //    private BigDecimal soundingWidth;
+    private Double soundingWidth;
+    private Double width;
 
 
     public BedHeightSingleValue() {
@@ -56,12 +57,13 @@
 
     public BedHeightSingleValue(
         BedHeightSingle bedHeight,
-        BigDecimal station,
-        BigDecimal height,
-        BigDecimal uncertainty,
-        BigDecimal dataGap,
-        BigDecimal soundingWidth,
-        BigDecimal width
+        Double station,
+        Double height,
+        Double uncertainty,
+        Double dataGap,
+	//        BigDecimal soundingWidth,
+	Double soundingWidth,
+        Double width
     ) {
         this.bedHeight     = bedHeight;
         this.station       = station;
@@ -100,56 +102,58 @@
     }
 
     @Column(name = "station")
-    public BigDecimal getStation() {
+    public Double getStation() {
         return station;
     }
 
-    public void setStation(BigDecimal station) {
+    public void setStation(Double station) {
         this.station = station;
     }
 
     @Column(name = "height")
-    public BigDecimal getHeight() {
+    public Double getHeight() {
         return height;
     }
 
-    public void setHeight(BigDecimal height) {
+    public void setHeight(Double height) {
         this.height = height;
     }
 
     @Column(name="uncertainty")
-    public BigDecimal getUncertainty() {
+    public Double getUncertainty() {
         return uncertainty;
     }
 
-    public void setUncertainty(BigDecimal uncertainty) {
+    public void setUncertainty(Double uncertainty) {
         this.uncertainty = uncertainty;
     }
 
     @Column(name="data_gap")
-    public BigDecimal getDataGap() {
+    public Double getDataGap() {
         return dataGap;
     }
 
-    public void setDataGap(BigDecimal dataGap) {
+    public void setDataGap(Double dataGap) {
         this.dataGap = dataGap;
     }
 
     @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;
     }
 
     @Column(name="width")
-    public BigDecimal getWidth() {
+    public Double getWidth() {
         return width;
     }
 
-    public void setWidth(BigDecimal width) {
+    public void setWidth(Double width) {
         this.width = width;
     }
 
@@ -166,8 +170,8 @@
             "   and station >= :kmLo and station <= :kmHi");
 
         query.setParameter("single", single);
-        query.setParameter("kmLo", new BigDecimal(kmLo));
-        query.setParameter("kmHi", new BigDecimal(kmHi));
+        query.setParameter("kmLo", new Double(kmLo));
+        query.setParameter("kmHi", new Double(kmHi));
 
         return query.list();
     }

http://dive4elements.wald.intevation.org