[PATCH 3 of 5] Fixed porosity importer. Find existing db entries and parse values from string, not via double
Wald Commits
scm-commit at wald.intevation.org
Thu May 8 13:52:56 CEST 2014
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1399549725 -7200
# Node ID cdef048c4ac5b38645e1f8a198e98c9f59d155b2
# Parent c288309a5dcbb24d9b641ea6953e3f13081c07b4
Fixed porosity importer. Find existing db entries and parse values from string, not via double.
diff -r c288309a5dcb -r cdef048c4ac5 backend/src/main/java/org/dive4elements/river/importer/ImportPorosity.java
--- 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();
diff -r c288309a5dcb -r cdef048c4ac5 backend/src/main/java/org/dive4elements/river/importer/ImportPorosityValue.java
--- 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();
diff -r c288309a5dcb -r cdef048c4ac5 backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java
--- 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) {
More information about the Dive4Elements-commits
mailing list