# HG changeset patch # User Sascha L. Teichmann # Date 1558622415 -7200 # Node ID 075757ca8fce8199ddf5f4254207b9112ec16945 # Parent 489e583498e3f7521e55289f65fb4aca0a95f2cf fairway availabilty: A more constistent result format. diff -r 489e583498e3 -r 075757ca8fce pkg/controllers/bottlenecks.go --- 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, }) }