changeset 7862:cdef048c4ac5

Fixed porosity importer. Find existing db entries and parse values from string, not via double.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 08 May 2014 13:48:45 +0200
parents c288309a5dcb
children 082284c4e0ad
files backend/src/main/java/org/dive4elements/river/importer/ImportPorosity.java backend/src/main/java/org/dive4elements/river/importer/ImportPorosityValue.java backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java
diffstat 3 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportPorosity.java	Thu May 08 13:46:32 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportPorosity.java	Thu May 08 13:48:45 2014 +0200
@@ -86,10 +86,13 @@
                 .getDatabaseSession();
 
             Query query = session.createQuery("from Porosity where "
-                + "   river=:river and " + "   depth=:depth");
+                + "   river=:river and "
+                + "   depth=:depth and "
+                + "   description=:description");
 
             query.setParameter("river", river);
             query.setParameter("depth", depth.getPeer());
+            query.setParameter("description", description);
 
             List<Porosity> porosity = query.list();
 
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportPorosityValue.java	Thu May 08 13:46:32 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportPorosityValue.java	Thu May 08 13:48:45 2014 +0200
@@ -67,15 +67,13 @@
             Query query = session.createQuery(
                 "from PorosityValue where " +
                 "   porosity=:porosity and " +
-                "   station=:station and " +
-                "   shoreOffset=:shoreOffset and " +
-                "   porosityValue=:poros and " +
+                "   station between :station - 0.0001f and :station + 0.0001f and" +
+                "   porosityValue between :poros -0.0001f and :poros + 0.0001f and" +
                 "   description=:description");
 
             query.setParameter("porosity", porosity);
-            query.setParameter("station", station);
-            query.setParameter("shoreOffset", shoreOffset);
-            query.setParameter("poros", this.porosity);
+            query.setParameter("station", station.floatValue());
+            query.setParameter("poros", this.porosity.floatValue());
             query.setParameter("description", description);
 
             List<PorosityValue> values = query.list();
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java	Thu May 08 13:46:32 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java	Thu May 08 13:48:45 2014 +0200
@@ -137,19 +137,22 @@
 
             log.info("Found porosity depth: " + lo + " - " + up + " cm");
 
+            ImportDepth depth = null;
             try {
-                ImportDepth depth = new ImportDepth(
-                    new BigDecimal(nf.parse(lo).doubleValue()),
-                    new BigDecimal(nf.parse(up).doubleValue())
+                depth = new ImportDepth(
+                    new BigDecimal(lo),
+                    new BigDecimal(up)
                 );
+            }
+            catch (NumberFormatException nfe) {
+                log.warn("Unparsable number for depth: " + line, nfe);
+            }
 
+            if (depth != null) {
                 current.setDepth(depth);
-
                 return true;
             }
-            catch (ParseException pe) {
-                log.warn("Unparseable numbers in: '" + line + "'");
-            }
+            return false;
         }
         else {
             log.debug("Meta line doesn't contain depth information: " + line);
@@ -170,15 +173,18 @@
         BigDecimal km = null;
         BigDecimal shoreOffset = null;
         BigDecimal porosity = null;
+        vals[0] = vals[0].replace(",", ".");
+        vals[2] = vals[2].replace(",", ".");
         try {
-            km          = new BigDecimal(nf.parse(vals[0]).doubleValue());
-            porosity     = new BigDecimal(nf.parse(vals[2]).doubleValue());
+            km          = new BigDecimal(vals[0]);
+            porosity     = new BigDecimal(vals[2]);
             if (!vals[1].isEmpty()) {
-                shoreOffset = new BigDecimal(nf.parse(vals[1]).doubleValue());
+                vals[1] = vals[1].replace(",", ".");
+                shoreOffset = new BigDecimal(vals[1]);
             }
         }
-        catch (ParseException pe) {
-            log.warn("Unparseable numbers in '" + line + "'");
+        catch(NumberFormatException nfe) {
+            log.warn("Unparsable number in line: " + line, nfe);
         }
 
         if (km == null || porosity == null) {

http://dive4elements.wald.intevation.org