Progressively determine the eta of a process out of the percentage reported.
Everything is customizable, no need to define checkpoints or any other shenanigans
npm i simple-eta
const makeEta = require('simple-eta');
const eta = makeEta({ min: 0, max: 100 });
eta.start();
for (let progress = 1; progress <= 100; i += 1) {
// Operation that takes time
eta.report(progress);
console.log(`Aprox. ${eta.estimate()} seconds left`);
}
- min
{number=0}
- define the lower limit of your interval - max
{number=1}
- define the upper limit of your interval - historyTimeConstant
{number=2.5}
- define (in seconds) how far into the past to consider data points as still relevanthigher history value
: more time stable. spikes in progress speed will affect ETA lesslower history value
: more adaptive to changes. spikes in progress speed will affect ETA more
- autostart
{boolean=true}
- add the first history point when the class is instantiated or reset
Add the first point to the history. Equivalent to .report(min)
.
Automatically called if autostart
is true
.
Resets the history of the ETA.
Report the progress within the defined interval, adding a point to the history.
Values outside the interval will produce false results.
Estimates the time left from the last .report
call to complete the interval.
Time is returned in seconds. Returns Infinity
when an ETA is not available.
Gets the estimated progress speed (progress per second).