forked from smartcontractkit/wasp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.go
63 lines (56 loc) · 1.27 KB
/
schedule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package wasp
import (
"math"
"time"
)
/* Different load profile schedules definitions */
const (
// DefaultStepChangePrecision is default amount of steps in which we split a schedule
DefaultStepChangePrecision = 10
)
func Plain(from int64, duration time.Duration) []*Segment {
return []*Segment{
{
From: from,
Steps: DefaultStepChangePrecision,
StepDuration: duration / DefaultStepChangePrecision,
},
}
}
func Line(from, to int64, duration time.Duration) []*Segment {
var inc int64
stepDur := duration / DefaultStepChangePrecision
incFloat := (float64(to) - float64(from)) / DefaultStepChangePrecision
if math.Signbit(incFloat) {
inc = int64(math.Floor(incFloat))
} else {
inc = int64(math.Ceil(incFloat))
}
return []*Segment{
{
From: from,
Steps: DefaultStepChangePrecision,
Increase: inc,
StepDuration: stepDur,
},
}
}
func Combine(segs ...[]*Segment) []*Segment {
acc := make([]*Segment, 0)
for _, ss := range segs {
acc = append(acc, ss...)
}
return acc
}
func CombineAndRepeat(times int, segs ...[]*Segment) []*Segment {
if len(segs) == 0 {
panic(ErrNoSched)
}
acc := make([]*Segment, 0)
for i := 0; i < times; i++ {
for _, ss := range segs {
acc = append(acc, ss...)
}
}
return acc
}