Mercurial > gemma
changeset 3036:7f12a87c56ff
Fairway availability: Set boundaries of segments correctly.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 12 Apr 2019 15:49:00 +0200 |
parents | 5d7db2ea16c8 |
children | 72451510d417 d47d289d6e68 |
files | pkg/controllers/bottlenecks.go |
diffstat | 1 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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