Mercurial > gemma
changeset 3040:a661e9b8f3b6
Fairway availability: 'virtualized' the field to classify.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 12 Apr 2019 17:27:21 +0200 |
parents | 130da3cf5c8a |
children | ccda334eed92 |
files | pkg/controllers/bottlenecks.go |
diffstat | 1 files changed, 17 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go Fri Apr 12 17:01:13 2019 +0200 +++ b/pkg/controllers/bottlenecks.go Fri Apr 12 17:27:21 2019 +0200 @@ -83,7 +83,7 @@ type ( availReferenceValue struct { level int - value int + value float64 } availMeasurement struct { @@ -97,6 +97,7 @@ from, to time.Time, measurements []availMeasurement, classes []availReferenceValue, + access func(*availMeasurement) float64, ) []time.Duration { type classValues struct { @@ -111,15 +112,12 @@ classify := func(v func(float64) (time.Time, common.ValueRangeKind)) { for i := range classes { - cvs[i].when, cvs[i].kind = v(float64(classes[i].value)) + cvs[i].when, cvs[i].kind = v(classes[i].value) } } vbt := func(p1, p2 *availMeasurement) func(time.Time) (float64, common.ValueRangeKind) { - return common.InterpolateValueByTime( - p1.when, float64(p1.value), - p2.when, float64(p2.value), - ) + return common.InterpolateValueByTime(p1.when, access(p1), p2.when, access(p2)) } pairs: @@ -154,7 +152,7 @@ f, _ := vbt(p1, p2)(from) classify(common.InterpolateTimeByValue( from, f, - p2.when, float64(p2.value), + p2.when, access(p2), )) start, end = from, p2.when @@ -163,7 +161,7 @@ // invalid += to.Sub(p2.when) t, _ := vbt(p1, p2)(to) classify(common.InterpolateTimeByValue( - p1.when, float64(p1.value), + p1.when, access(p1), to, t, )) start, end = p1.when, to @@ -171,8 +169,8 @@ case !p1.when.Before(from) && !to.After(p2.when): // Segment complete inside. classify(common.InterpolateTimeByValue( - p1.when, float64(p1.value), - p2.when, float64(p2.value), + p1.when, access(p1), + p2.when, access(p2), )) start, end = p1.when, p2.when default: @@ -188,7 +186,7 @@ case common.ValueInside: // -> split - if p1.value < classes[i].value { + if access(p1) < classes[i].value { // started below -> second part above result[i+1] = end.Sub(cvs[i].when) end = cvs[i].when @@ -251,11 +249,14 @@ } for i := range levels { if levels[i].level == level { - levels[i].value = value + levels[i].value = float64(value) continue loop } } - levels = append(levels, availReferenceValue{level: level, value: value}) + levels = append(levels, availReferenceValue{ + level: level, + value: float64(value), + }) } if err := rows.Err(); err != nil { @@ -371,6 +372,7 @@ from, to, ms, refVals, + func(m *availMeasurement) float64 { return float64(m.value) }, ) classes := make([]float64, len(results)) @@ -380,8 +382,8 @@ } type outputLevel struct { - Level string `json:"level"` - Value int `json:"value"` + Level string `json:"level"` + Value float64 `json:"value"` } type output struct {