changeset 3426:4b303c149db4

fairway availibilty: Changed result document to be more precise.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 May 2019 16:25:30 +0200
parents cb2f67a07400
children 489e583498e3
files pkg/controllers/bottlenecks.go
diffstat 1 files changed, 40 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go	Thu May 23 15:58:12 2019 +0200
+++ b/pkg/controllers/bottlenecks.go	Thu May 23 16:25:30 2019 +0200
@@ -460,36 +460,47 @@
 	lnwlPercents := durationsToPercentage(from, to, lnwl)
 	afdPercents := durationsToPercentage(from, to, afd)
 
-	type lnwlOutput struct {
-		Level   string  `json:"level"`
-		Value   float64 `json:"value"`
-		Percent float64 `json:"percent"`
+	log.Printf("%v\n", lnwlPercents)
+	log.Printf("%v\n", afdPercents)
+
+	type ldcOutput struct {
+		Value float64 `json:"value"`
+		Below float64 `json:"below"`
+		Above float64 `json:"above"`
 	}
 
-	type afdOutput struct {
+	type intervalOutput struct {
+		Type    string  `json:"type"`
 		Value   float64 `json:"value"`
 		Percent float64 `json:"percent"`
 	}
 
 	type output struct {
-		LNWL []lnwlOutput `json:"lnwl"`
-		AFD  []afdOutput  `json:"afd"`
+		LDC []intervalOutput `json:"ldc"`
+		AFD []intervalOutput `json:"afd"`
+	}
+
+	out := output{
+		LDC: []intervalOutput{
+			{Type: "below", Value: ldcRefs[0], Percent: lnwlPercents[0]},
+			{Type: "above", Value: ldcRefs[0], Percent: lnwlPercents[1]},
+		},
 	}
 
-	out := output{}
-
-	for i := range ldcRefs {
-		out.LNWL = append(out.LNWL, lnwlOutput{
-			Level:   "LDC",
-			Value:   ldcRefs[i],
-			Percent: lnwlPercents[i],
-		})
-	}
-
-	for i := range breaks {
-		out.AFD = append(out.AFD, afdOutput{
-			Value:   breaks[i],
-			Percent: afdPercents[i],
+	for i, percent := range afdPercents {
+		var typ string
+		var value float64
+		if i != len(afdPercents)-1 {
+			typ = "below"
+			value = breaks[i]
+		} else {
+			typ = "above"
+			value = breaks[len(breaks)-1]
+		}
+		out.AFD = append(out.AFD, intervalOutput{
+			Type:    typ,
+			Value:   value,
+			Percent: percent,
 		})
 	}
 
@@ -497,6 +508,14 @@
 	return
 }
 
+/*
+
+{ "type": "below", "value": 230, "percent": 0 },
+{ "below": 250, "value": 9 }
+{ "above": 250, "value": 8.1
+
+*/
+
 func intervalMode(mode string) int {
 	switch strings.ToLower(mode) {
 	case "monthly":