changeset 4702:ef21c1464843

FA: fix inconsistency in access to values of LDCs and limiting value. This fixes an issue with the water level being always over LDC in some diagrams. Also it presumably fixes a case, where width as a limiting factor was not used.
author Sascha Wilde <wilde@intevation.de>
date Wed, 16 Oct 2019 17:35:25 +0200
parents ef2cf9c413e9
children 6e179b338f1a
files pkg/controllers/bottlenecks.go pkg/controllers/stretches.go
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go	Wed Oct 16 16:51:09 2019 +0200
+++ b/pkg/controllers/bottlenecks.go	Wed Oct 16 17:35:25 2019 +0200
@@ -456,6 +456,23 @@
 	conn := middleware.GetDBConn(req)
 	ctx := req.Context()
 
+	var limiting string
+	err := conn.QueryRowContext(ctx, selectLimitingSQL, bn).Scan(&limiting)
+	switch {
+	case err == sql.ErrNoRows:
+		http.Error(
+			rw, fmt.Sprintf("Unknown limitation for %s.", bn),
+			http.StatusNotFound)
+		return
+	case err != nil:
+		http.Error(
+			rw, fmt.Sprintf("DB error: %v.", err),
+			http.StatusInternalServerError)
+		return
+	}
+
+	access := limitingFactor(limiting)
+
 	ldcRefs, err := loadLDCReferenceValue(ctx, conn, bn)
 	if err != nil {
 		http.Error(
@@ -537,7 +554,7 @@
 		afd := ms.classify(
 			pfrom, pto,
 			breaks,
-			(*availMeasurement).getDepth,
+			access,
 		)
 
 		duration := pto.Sub(pfrom)
@@ -693,7 +710,7 @@
 		ldc := ms.classify(
 			pfrom, pto,
 			ldcRefs,
-			access,
+			(*availMeasurement).getValue,
 		)
 
 		ranges := ms.classify(
--- a/pkg/controllers/stretches.go	Wed Oct 16 16:51:09 2019 +0200
+++ b/pkg/controllers/stretches.go	Wed Oct 16 17:35:25 2019 +0200
@@ -300,7 +300,7 @@
 					l := bn.measurements.classify(
 						res.from, res.to,
 						bn.ldc,
-						bn.access,
+						(*availMeasurement).getValue,
 					)
 					b := bn.measurements.classify(
 						res.from, res.to,