Smart progress bar ETA computation

后端 未结 11 504
谎友^
谎友^ 2020-12-22 16:10

In many applications, we have some progress bar for a file download, for a compression task, for a search, etc. We all often use progress bars to let users know something is

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 16:24

    Whilst all the examples are valid, for the specific case of 'time left to download', I thought it would be a good idea to look at existing open source projects to see what they do.

    From what I can see, Mozilla Firefox is the best at estimating the time remaining.

    Mozilla Firefox

    Firefox keeps a track of the last estimate for time remaining, and by using this and the current estimate for time remaining, it performs a smoothing function on the time. See the ETA code here. This uses a 'speed' which is previously caculated here and is a smoothed average of the last 10 readings.

    This is a little complex, so to paraphrase:

    • Take a smoothed average of the speed based 90% on the previous speed and 10% on the new speed.
    • With this smoothed average speed work out the estimated time remaining.
    • Use this estimated time remaining, and the previous estimated time remaining to created a new estimated time remaining (in order to avoid jumping)

    Google Chrome

    Chrome seems to jump about all over the place, and the code shows this.

    One thing I do like with Chrome though is how they format time remaining. For > 1 hour it says '1 hrs left' For < 1 hour it says '59 mins left' For < 1 minute it says '52 secs left'

    You can see how it's formatted here

    DownThemAll! Manager

    It doesn't use anything clever, meaning the ETA jumps about all over the place.

    See the code here

    pySmartDL (a python downloader)

    Takes the average ETA of the last 30 ETA calculations. Sounds like a reasonable way to do it.

    See the code here/blob/916f2592db326241a2bf4d8f2e0719c58b71e385/pySmartDL/pySmartDL.py#L651)

    Transmission

    Gives a pretty good ETA in most cases (except when starting off, as might be expected).

    Uses a smoothing factor over the past 5 readings, similar to Firefox but not quite as complex. Fundamentally similar to Gooli's answer.

    See the code here

提交回复
热议问题