# HG changeset patch # User Sascha L. Teichmann # Date 1555076940 -7200 # Node ID 7f12a87c56ff274c7760985235329f0237b14538 # Parent 5d7db2ea16c8b5c31d151fc516432b4ddca2980e Fairway availability: Set boundaries of segments correctly. diff -r 5d7db2ea16c8 -r 7f12a87c56ff pkg/controllers/bottlenecks.go --- a/pkg/controllers/bottlenecks.go Fri Apr 12 14:51:23 2019 +0200 +++ b/pkg/controllers/bottlenecks.go Fri Apr 12 15:49:00 2019 +0200 @@ -128,7 +128,7 @@ } } - valInt := func(p1, p2 *availMeasurement) func(time.Time) (float64, common.ValueRangeKind) { + vbt := func(p1, p2 *availMeasurement) func(time.Time) (float64, common.ValueRangeKind) { return common.InterpolateValueByTime( p1.when, float64(p1.value), p2.when, float64(p2.value), @@ -140,6 +140,8 @@ p1 := &measurements[i] p2 := &measurements[i+1] + var start, end time.Time + switch { case !p2.when.After(p2.when): // Segment invalid @@ -153,28 +155,31 @@ // (from-to) is complete inside segment. invalid += p1.when.Sub(from) invalid += to.Sub(p2.when) - v := valInt(p1, p2) + v := vbt(p1, p2) f, _ := v(from) t, _ := v(to) classify(common.InterpolateTimeByValue(from, f, to, t)) + start, end = from, to case p1.when.After(from): // from is inside segment invalid += p1.when.Sub(from) - f, _ := valInt(p1, p2)(from) + f, _ := vbt(p1, p2)(from) classify(common.InterpolateTimeByValue( from, f, p2.when, float64(p2.value), )) + start, end = from, p2.when case p2.when.Before(to): // to is inside segment invalid += to.Sub(p2.when) - t, _ := valInt(p1, p2)(to) + t, _ := vbt(p1, p2)(to) classify(common.InterpolateTimeByValue( p1.when, float64(p1.value), to, t, )) + start, end = p1.when, to case !p1.when.Before(from) && !to.After(p2.when): // Segment complete inside. @@ -182,8 +187,13 @@ p1.when, float64(p1.value), p2.when, float64(p2.value), )) + start, end = p1.when, p2.when + default: + log.Println("warn: unexpected case. That should not happen.") + continue pairs } // TODO: Distribute to classes. + _, _ = start, end } return nil