Guest User

Untitled

a guest
Dec 11th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. const progressDefaultColor = typeof chalk !== 'undefined' ? chalk.magenta : (x) => x;
  2. const progressErrorColor = typeof chalk !== 'undefined' ? chalk.red : (x) => x;
  3. function formatProgress(startTime, queuedCount, finishedCount, errorsCount) {
  4. const progressPercent = (100 * finishedCount) / queuedCount;
  5. const errorsPercent = (100 * errorsCount) / queuedCount;
  6. const elapsedTimeSeconds = (Date.now() - startTime) / 1000;
  7. const estimatedTimeSeconds = progressPercent > 0 ? 100 * (elapsedTimeSeconds / progressPercent) : 0;
  8. const itemsPerSecond = finishedCount / elapsedTimeSeconds;
  9. return (
  10. progressDefaultColor(
  11. `${finishedCount} of ${queuedCount} (${progressPercent.toFixed(2)}%, ${itemsPerSecond.toFixed(2)}/sec) `,
  12. ) +
  13. (errorsCount > 0 ? progressErrorColor(`${errorsCount} with errors (${errorsPercent.toFixed(2)}%) `) : '') +
  14. progressDefaultColor(`${elapsedTimeSeconds.toFixed(0)}sec elapsed, ${estimatedTimeSeconds.toFixed(0)}sec estimated`)
  15. );
  16. }
Add Comment
Please, Sign In to add comment