changeset 3428:075757ca8fce

fairway availabilty: A more constistent result format.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 May 2019 16:40:15 +0200
parents 489e583498e3
children 7bbab09cdf71
files pkg/controllers/bottlenecks.go
diffstat 1 files changed, 16 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go	Thu May 23 16:34:41 2019 +0200
+++ b/pkg/controllers/bottlenecks.go	Thu May 23 16:40:15 2019 +0200
@@ -460,9 +460,6 @@
 	lnwlPercents := durationsToPercentage(from, to, lnwl)
 	afdPercents := durationsToPercentage(from, to, afd)
 
-	log.Printf("%v\n", lnwlPercents)
-	log.Printf("%v\n", afdPercents)
-
 	type ldcOutput struct {
 		Value float64 `json:"value"`
 		Below float64 `json:"below"`
@@ -470,9 +467,9 @@
 	}
 
 	type intervalOutput struct {
-		Type    string  `json:"type"`
-		Value   float64 `json:"value"`
-		Percent float64 `json:"percent"`
+		From    *float64 `json:"from,omitempty"`
+		To      *float64 `json:"to,omitempty"`
+		Percent float64  `json:"percent"`
 	}
 
 	type output struct {
@@ -482,24 +479,25 @@
 
 	out := output{
 		LDC: []intervalOutput{
-			{Type: "below", Value: ldcRefs[0], Percent: lnwlPercents[0]},
-			{Type: "above", Value: ldcRefs[0], Percent: lnwlPercents[1]},
+			{To: &ldcRefs[0], Percent: lnwlPercents[0]},
+			{From: &ldcRefs[0], Percent: lnwlPercents[1]},
 		},
 	}
 
 	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]
+		var from, to *float64
+		switch {
+		case i == 0:
+			to = &breaks[i]
+		case i == len(afdPercents)-1:
+			from = &breaks[len(breaks)-1]
+		default:
+			from = &breaks[i-1]
+			to = &breaks[i]
 		}
 		out.AFD = append(out.AFD, intervalOutput{
-			Type:    typ,
-			Value:   value,
+			From:    from,
+			To:      to,
 			Percent: percent,
 		})
 	}