php-cli-progress-bar icon indicating copy to clipboard operation
php-cli-progress-bar copied to clipboard

Nitpicking - ETC is inaccurate when instantiating the progress bar "soon"

Open fredericgboutin-yapla opened this issue 1 year ago • 0 comments

Hi, My ❤️ to you for this great component.

I just had a situation where I began running a lengthy script with this progress bar and at the very very beginning I saw the ETC showing a way too high value.

The problem is, I have recently generalized the progress bar usage in all my scripts, meaning that I provide an already instantiated progress bar. My problematic script in this scenario, only call setMaxProgress() once it has run a lengthy query on the database.

When looking at the code I see that the $startTime is set in the constructor, - see https://github.com/DivineOmega/php-cli-progress-bar/blob/0c2d8d64d27dce8c2f214260c1e28f9fb4821bdc/src/ProgressBar.php#L22 - so it clearly explain why the ETC was initially way too high because it included the lengthy database query my script did in the beginning.

To fix that, I suppose we could simply reset the $startTime when calling setMaxProgress().

I'm not sure if people are using the progress bar with multiple calls to setMaxProgress() for the same task, though.

We could as well make use of a start() method that would explicitly reset the $startTime.

What do you think?

fredericgboutin-yapla avatar Feb 29 '24 16:02 fredericgboutin-yapla