[PATCH 3 of 3] (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type

Wald Commits scm-commit at wald.intevation.org
Fri Apr 17 19:32:43 CEST 2015


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1429275856 -7200
# Node ID 67e53dbe05d2c43203e91a5c6fc0be04816fb329
# Parent  bfca77cbf3536b248344469891b94082b7269516
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.

diff -r bfca77cbf353 -r 67e53dbe05d2 backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java	Fri Apr 17 14:55:42 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java	Fri Apr 17 15:04:16 2015 +0200
@@ -39,8 +39,6 @@
     }
 
     public void storeDependencies() {
-        log.info("store dependencies");
-
         SQRelation peer = getPeer();
 
         if (peer != null) {
@@ -64,8 +62,6 @@
     }
 
     public SQRelation getPeer() {
-        log.debug("getPeer()");
-
         if (peer == null) {
             TimeInterval timeInter = timeInterval.getPeer();
 
diff -r bfca77cbf353 -r 67e53dbe05d2 backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java	Fri Apr 17 14:55:42 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java	Fri Apr 17 15:04:16 2015 +0200
@@ -206,6 +206,28 @@
         return range;
     }
 
+    public MeasurementStation getMeasurementStation(
+        River river,
+        double station,
+        String measurementType
+    ) {
+        List<MeasurementStation> stations = getMeasurementStations(
+            river, station);
+
+        if (stations != null) {
+            /* Assume there is only one MeasurementStation per type at
+               any station. Should be enforced in database schema. */
+            for (MeasurementStation m: stations) {
+                if (m.getMeasurementType().equals(measurementType)) {
+                    return m;
+                }
+                continue;
+            }
+        }
+
+        return null;
+    }
+
     public List<MeasurementStation> getMeasurementStations(
         River river,
         double station
diff -r bfca77cbf353 -r 67e53dbe05d2 backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Fri Apr 17 14:55:42 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Fri Apr 17 15:04:16 2015 +0200
@@ -146,24 +146,32 @@
             return;
         }
 
-        List<MeasurementStation> ms =
-            ImporterSession.getInstance().getMeasurementStations(
-                river, km);
+        MeasurementStation mStation = ImporterSession.getInstance()
+            .getMeasurementStation(
+                river,
+                km,
+                parameter.equals("A") || parameter.equals("B")
+                ? MeasurementStation.MEASUREMENT_TYPE_SUSP
+                : MeasurementStation.MEASUREMENT_TYPE_BEDLOAD);
 
-        if (ms != null && !ms.isEmpty()) {
-            current.addValue(new ImportSQRelationValue(
-                    cols[1],
-                    ms.get(0),
-                    a,
-                    b,
-                    qMax,
-                    rSq,
-                    nTot,
-                    nOutlier,
-                    cFer,
-                    cDuan
-                ));
+        if (mStation == null) {
+            log.warn("No measurement station fitting parameter " +
+                parameter + " at km " + km + ". Line ignored.");
+            return;
         }
+
+        current.addValue(new ImportSQRelationValue(
+                parameter,
+                mStation,
+                a,
+                b,
+                qMax,
+                rSq,
+                nTot,
+                nOutlier,
+                cFer,
+                cDuan
+            ));
     }
 
     private Double parseDouble(String[] values, int idx) {


More information about the Dive4Elements-commits mailing list