changeset 5477:a3d46cee9f69

merge
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 17 Aug 2021 16:52:15 +0200
parents 453a33b0717d (current diff) 791a372553a0 (diff)
children 699048c86848
files
diffstat 4 files changed, 66 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/fairway/AvailableFairwayDepth.vue	Tue Aug 17 16:51:43 2021 +0200
+++ b/client/src/components/fairway/AvailableFairwayDepth.vue	Tue Aug 17 16:52:15 2021 +0200
@@ -197,12 +197,15 @@
       "widthlimit2"
     ]),
     legend() {
-      const d = [this.depthlimit1D, this.depthlimit2D].sort();
-      const w = [this.widthlimit1D, this.widthlimit2D].sort();
+      const d = [this.depthlimit1D, this.depthlimit2D].sort((a, b) => a - b);
+      const w = [this.widthlimit1D, this.widthlimit2D].sort((a, b) => a - b);
       const lowerBound = [d[0] / 100, w[0]].filter(x => x).join(", ");
       const upperBound = [d[1] / 100, w[1]].filter(x => x).join(", ");
       let result;
-      if (this.depthlimit1D !== this.depthlimit2D) {
+      if (
+        this.depthlimit1D !== this.depthlimit2D ||
+        this.widthlimit1 !== this.widthlimit2
+      ) {
         result = [
           `> LDC`,
           `>= ${upperBound} [m]`,
--- a/client/src/components/fairway/AvailableFairwayDepthDialogue.vue	Tue Aug 17 16:51:43 2021 +0200
+++ b/client/src/components/fairway/AvailableFairwayDepthDialogue.vue	Tue Aug 17 16:52:15 2021 +0200
@@ -623,6 +623,12 @@
         this.depthLimit2 = 2.5;
       }
     },
+    widthLimitVisible() {
+      if (this.widthLimitVisible) {
+        this.widthLimit1 = 80;
+        this.widthLimit2 = 150;
+      }
+    },
     selectedBottleneck() {
       this.type = this.$options.BOTTLENECK;
       this.setSelectedBottleneck();
@@ -757,8 +763,8 @@
           type: this.type,
           depthLimit1: this.depthlimit1,
           depthLimit2: this.depthlimit2,
-          widthLimit1: this.widthLimit1,
-          widthLimit2: this.widthLimit2,
+          widthLimit1: Math.round(this.widthLimit1 * 100),
+          widthLimit2: Math.round(this.widthLimit2 * 100),
           limitingFactor: this.limitingFactor
         })
         .then(() => {
@@ -805,8 +811,8 @@
           type: this.type,
           depthLimit1: this.depthlimit1,
           depthLimit2: this.depthlimit2,
-          widthLimit1: this.widthLimit1,
-          widthLimit2: this.widthLimit2,
+          widthLimit1: Math.round(this.widthLimit1 * 100),
+          widthLimit2: Math.round(this.widthLimit2 * 100),
           limitingFactor: this.limitingFactor
         })
         .then(() => {
--- a/client/src/store/fairwayavailability.js	Tue Aug 17 16:51:43 2021 +0200
+++ b/client/src/store/fairwayavailability.js	Tue Aug 17 16:52:15 2021 +0200
@@ -70,8 +70,8 @@
     limitingFactor: null,
     depthlimit1: 230,
     depthlimit2: 250,
-    widthlimit1: null,
-    widthlimit2: null,
+    widthlimit1: 80,
+    widthlimit2: 150,
     csv: null,
     fwData: null,
     fwLNWLData: null,
--- a/pkg/controllers/fwa.go	Tue Aug 17 16:51:43 2021 +0200
+++ b/pkg/controllers/fwa.go	Tue Aug 17 16:52:15 2021 +0200
@@ -252,18 +252,26 @@
 	}
 
 	// separate breaks for depth and width
-	var (
-		breaks       = parseBreaks(req.FormValue("breaks"), afdRefs)
-		depthBreaks  = parseBreaks(req.FormValue("depthbreaks"), breaks)
-		widthBreaks  = parseBreaks(req.FormValue("widthbreaks"), breaks)
-		chooseBreaks = [...][]float64{
-			limitingDepth: depthBreaks,
-			limitingWidth: widthBreaks,
-		}
+	breaks, ok := parseBreaks(rw, req, "breaks", afdRefs)
+	if !ok {
+		return
+	}
+	depthBreaks, ok := parseBreaks(rw, req, "depthbreaks", breaks)
+	if !ok {
+		return
+	}
+	widthBreaks, ok := parseBreaks(rw, req, "widthbreaks", breaks)
+	if !ok {
+		return
+	}
 
-		useDepth = bns.hasLimiting(limitingDepth, from, to)
-		useWidth = bns.hasLimiting(limitingWidth, from, to)
-	)
+	chooseBreaks := [...][]float64{
+		limitingDepth: depthBreaks,
+		limitingWidth: widthBreaks,
+	}
+
+	useDepth := bns.hasLimiting(limitingDepth, from, to)
+	useWidth := bns.hasLimiting(limitingWidth, from, to)
 
 	if useDepth && useWidth && len(widthBreaks) != len(depthBreaks) {
 		http.Error(
@@ -384,12 +392,12 @@
 				}
 			}
 
-			if min := minClass(bns[i].measurements.classify(
+			classes := bns[i].measurements.classify(
 				current, next,
 				chooseBreaks[vs.limiting],
-				limitingAccess[vs.limiting]),
-				12*time.Hour,
-			); min < lowest {
+				limitingAccess[vs.limiting])
+
+			if min := minClass(classes, 12*time.Hour); min < lowest {
 				lowest = min
 			}
 		}
@@ -488,25 +496,42 @@
 	}
 }
 
-func breaksToReferenceValue(breaks string) []float64 {
+func breaksToReferenceValue(breaks string) ([]float64, error) {
 	parts := strings.Split(breaks, ",")
 	var values []float64
 
 	for _, part := range parts {
 		part = strings.TrimSpace(part)
-		if v, err := strconv.ParseFloat(part, 64); err == nil {
-			values = append(values, v)
+		v, err := strconv.ParseFloat(part, 64)
+		if err != nil {
+			return nil, err
 		}
+		values = append(values, v)
 	}
 
-	return common.DedupFloat64s(values)
+	return common.DedupFloat64s(values), nil
 }
 
-func parseBreaks(breaks string, defaults []float64) []float64 {
-	if breaks != "" {
-		return breaksToReferenceValue(breaks)
+func parseBreaks(
+	rw http.ResponseWriter, req *http.Request,
+	parameter string,
+	defaults []float64,
+) ([]float64, bool) {
+
+	breaks := strings.TrimSpace(req.FormValue(parameter))
+	if breaks == "" {
+		return defaults, true
 	}
-	return defaults
+
+	defaults, err := breaksToReferenceValue(breaks)
+	if err != nil {
+		msg := fmt.Sprintf("Parameter '%s' is invalid: %s.", parameter, err)
+		log.Printf("error: %s\n", msg)
+		http.Error(rw, msg, http.StatusBadRequest)
+		return nil, false
+	}
+
+	return defaults, true
 }
 
 func (tr *timeRange) intersects(from, to time.Time) bool {