Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const progressDefaultColor = typeof chalk !== 'undefined' ? chalk.magenta : (x) => x;
- const progressErrorColor = typeof chalk !== 'undefined' ? chalk.red : (x) => x;
- function formatProgress(startTime, queuedCount, finishedCount, errorsCount) {
- const progressPercent = (100 * finishedCount) / queuedCount;
- const errorsPercent = (100 * errorsCount) / queuedCount;
- const elapsedTimeSeconds = (Date.now() - startTime) / 1000;
- const estimatedTimeSeconds = progressPercent > 0 ? 100 * (elapsedTimeSeconds / progressPercent) : 0;
- const itemsPerSecond = finishedCount / elapsedTimeSeconds;
- return (
- progressDefaultColor(
- `${finishedCount} of ${queuedCount} (${progressPercent.toFixed(2)}%, ${itemsPerSecond.toFixed(2)}/sec) `,
- ) +
- (errorsCount > 0 ? progressErrorColor(`${errorsCount} with errors (${errorsPercent.toFixed(2)}%) `) : '') +
- progressDefaultColor(`${elapsedTimeSeconds.toFixed(0)}sec elapsed, ${estimatedTimeSeconds.toFixed(0)}sec estimated`)
- );
- }
Add Comment
Please, Sign In to add comment