examples upd
Vladimir Bauer
8 years ago
| 65 | 65 |
decor.CountersKibiByte("%6.1f / %6.1f", decor.WCSyncWidth),
|
| 66 | 66 |
),
|
| 67 | 67 |
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"),
|
| 70 | 70 |
),
|
| 71 | 71 |
)
|
| 72 | 72 |
|
| 48 | 48 |
decor.CountersKibiByte("% 6.1f / % 6.1f"),
|
| 49 | 49 |
),
|
| 50 | 50 |
mpb.AppendDecorators(
|
| 51 | |
decor.EwmaETA(decor.ET_STYLE_MMSS, 2048, sbEta),
|
|
51 |
decor.EwmaETA(decor.ET_STYLE_MMSS, 1024*8, sbEta),
|
| 52 | 52 |
decor.Name(" ] "),
|
| 53 | |
decor.TotalAverageSpeed(decor.UnitKiB, "% .2f"),
|
|
53 |
decor.AverageSpeed(decor.UnitKiB, "% .2f"),
|
| 54 | 54 |
),
|
| 55 | 55 |
)
|
| 56 | 56 |
|
| 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 | |
}
|
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 | |
}
|