Codebase list golang-github-vbauerster-mpb / b698da2
examples upd Vladimir Bauer 8 years ago
4 changed file(s) with 4 addition(s) and 108 deletion(s). Raw diff Collapse all Expand all
6565 decor.CountersKibiByte("%6.1f / %6.1f", decor.WCSyncWidth),
6666 ),
6767 mpb.AppendDecorators(
68 decor.EwmaETA(decor.ET_STYLE_HHMMSS, 2048, sbEta, decor.WCSyncWidth),
69 decor.TotalAverageSpeed(decor.UnitKiB, "% .2f"),
68 decor.EwmaETA(decor.ET_STYLE_HHMMSS, 1024*4, sbEta, decor.WCSyncWidth),
69 decor.AverageSpeed(decor.UnitKiB, "% .2f"),
7070 ),
7171 )
7272
4848 decor.CountersKibiByte("% 6.1f / % 6.1f"),
4949 ),
5050 mpb.AppendDecorators(
51 decor.EwmaETA(decor.ET_STYLE_MMSS, 2048, sbEta),
51 decor.EwmaETA(decor.ET_STYLE_MMSS, 1024*8, sbEta),
5252 decor.Name(" ] "),
53 decor.TotalAverageSpeed(decor.UnitKiB, "% .2f"),
53 decor.AverageSpeed(decor.UnitKiB, "% .2f"),
5454 ),
5555 )
5656
+0
-55
examples/prependETA/main.go less more
0 package main
1
2 import (
3 "fmt"
4 "math/rand"
5 "sync"
6 "time"
7
8 "github.com/vbauerster/mpb"
9 "github.com/vbauerster/mpb/decor"
10 )
11
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
15
16 func main() {
17 var wg sync.WaitGroup
18 p := mpb.New(mpb.WithWaitGroup(&wg))
19 total := 100
20 numBars := 3
21 wg.Add(numBars)
22
23 for i := 0; i < numBars; i++ {
24 var name string
25 if i != 1 {
26 name = fmt.Sprintf("Bar#%d:", i)
27 }
28 sbEta := make(chan time.Time)
29 b := p.AddBar(int64(total),
30 mpb.PrependDecorators(
31 decor.Name(name, decor.WCSyncWidth),
32 decor.OnComplete(
33 decor.EwmaETA(decor.ET_STYLE_MMSS, 60, sbEta, decor.WC{W: 6}),
34 "Done",
35 decor.WCSyncSpace,
36 ),
37 ),
38 mpb.AppendDecorators(
39 decor.Percentage(decor.WC{W: 5}),
40 ),
41 )
42 go func() {
43 defer wg.Done()
44 max := 100 * time.Millisecond
45 for i := 0; i < total; i++ {
46 sbEta <- time.Now()
47 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
48 b.Increment()
49 }
50 }()
51 }
52
53 p.Wait()
54 }
+0
-49
examples/prependElapsed/main.go less more
0 package main
1
2 import (
3 "fmt"
4 "math/rand"
5 "sync"
6 "time"
7
8 "github.com/vbauerster/mpb"
9 "github.com/vbauerster/mpb/decor"
10 )
11
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
15
16 func main() {
17 var wg sync.WaitGroup
18 p := mpb.New(mpb.WithWaitGroup(&wg))
19 total := 100
20 numBars := 3
21 wg.Add(numBars)
22
23 for i := 0; i < numBars; i++ {
24 var name string
25 if i != 1 {
26 name = fmt.Sprintf("Bar#%d:", i)
27 }
28 b := p.AddBar(int64(total),
29 mpb.PrependDecorators(
30 decor.Name(name, decor.WCSyncWidthR),
31 decor.Elapsed(decor.ET_STYLE_GO, decor.WCSyncSpace),
32 ),
33 mpb.AppendDecorators(
34 decor.Percentage(decor.WC{W: 5}),
35 ),
36 )
37 go func() {
38 defer wg.Done()
39 max := 100 * time.Millisecond
40 for i := 0; i < total; i++ {
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
42 b.Increment()
43 }
44 }()
45 }
46
47 p.Wait()
48 }