vbauerster / mpb

multi progress bar for Go cli applications
The Unlicense
2.29k stars 123 forks source link

Left time field and Speed field remain zero while running #69

Closed WangYihang closed 4 years ago

WangYihang commented 4 years ago

Description

I am implementing a progress bar using your great repo, but I got stuck on the following situation. The speed field and left time field remains zero while the program is running, could you please help me to figure out where I am wrong? Thank you so much!

Sample code

package main

import (
    "time"

    "github.com/vbauerster/mpb/v5"
    "github.com/vbauerster/mpb/v5/decor"
)

func main() {
    var totalBytes int64 = 1024

    p := mpb.New(
        mpb.WithWidth(60),
        mpb.WithRefreshRate(180*time.Millisecond),
    )

    bar := p.AddBar(totalBytes, mpb.BarStyle("[=>-|"),
        mpb.PrependDecorators(
            decor.CountersKibiByte("% .2f / % .2f"),
        ),
        mpb.AppendDecorators(
            decor.EwmaETA(decor.ET_STYLE_GO, 90),
            decor.Name(" ] "),
            decor.EwmaSpeed(decor.UnitKiB, "% .2f", 60),
        ),
    )

    for i := 0; i < 1024; i++ {
        bar.Increment()
        time.Sleep(1 * time.Second)
    }

    p.Wait()
}

Current output after 4s running

4.00 b / 1.00 KiB [----------------------------------------------------------| 0s ] 0.00 b/s

Expected output after 4s running

4.00 b / 1.00 KiB [----------------------------------------------------------| 1020s ] 1.00 b/s
vbauerster commented 4 years ago

As you're using ewma based decorators you need to call bar.DecoratorEwmaUpdate per iteration.

WangYihang commented 4 years ago

WOW, Cool, It works! Thank you bro!

WangYihang commented 4 years ago

Thank you for your quick repsond! CLOSED.