https://github.com/legraphista/eta
Progressively determine the eta of a process out of the percentage reported.
https://github.com/legraphista/eta
Last synced: 13 days ago
JSON representation
Progressively determine the eta of a process out of the percentage reported.
- Host: GitHub
- URL: https://github.com/legraphista/eta
- Owner: legraphista
- License: mit
- Created: 2018-09-01T12:32:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-21T18:05:44.000Z (over 3 years ago)
- Last Synced: 2024-11-14T09:27:28.695Z (7 months ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 11
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple ETA
_Progressively determine the eta of a process out of the percentage reported._
_Everything is customizable, no need to define checkpoints or any other shenanigans_# Install
```
npm i simple-eta
``````javascript
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`);
}
```## Constructor
- 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 relevant
- `higher history value`: more time stable. spikes in progress speed will affect ETA less
- `lower 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## Methods
### `.start():void`
Add the first point to the history. Equivalent to `.report(min)`.
Automatically called if `autostart` is `true`.### `.reset():void`
Resets the history of the ETA.### `.report(number):void`
Report the progress within the defined interval, adding a point to the history.
Values outside the interval will produce false results.### `.estimate():number`
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.### `.rate():number`
Gets the estimated progress speed (progress per second).