A utility class to track the duration of multiple tasks and estimate completion times.
// let's assume the date is Jan 1, 2000, 00:00:00const tracker = new TaskDurationTracker(5); // Initialize tracker for 5 tasksfor (let i = 0; i < 5; i++) { performTask(i); // Lets assume it takes 1 second to perform a task tracker.recordTaskEnd(); // Record the end of the task console.log(`Completed ${tracker.getCompletedTasks()} out of ${tracker.tasksCount} tasks.`); console.log(`Elapsed Time: ${tracker.getElapsedTime().milliseconds} ms`); console.log(`Estimated Completion Time: ${tracker.getEstimatedCompletionTime().milliseconds} ms`); console.log(`Expected Finish Time: ${tracker.getExpectedFinishTime()}`);} // OUTPUT:// Completed 1 out of 5 tasks.// Elapsed Time: 1000 ms// Estimated Completion Time: 4000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 2 out of 5 tasks.// Elapsed Time: 2000 ms// Estimated Completion Time: 3000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 3 out of 5 tasks.// Elapsed Time: 3000 ms// Estimated Completion Time: 2000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 4 out of 5 tasks.// Elapsed Time: 4000 ms// Estimated Completion Time: 1000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 5 out of 5 tasks.// Elapsed Time: 5000 ms// Estimated Completion Time: 0 ms// Expected Finish Time: Jan 1, 2000, 00:00:05 Copy
// let's assume the date is Jan 1, 2000, 00:00:00const tracker = new TaskDurationTracker(5); // Initialize tracker for 5 tasksfor (let i = 0; i < 5; i++) { performTask(i); // Lets assume it takes 1 second to perform a task tracker.recordTaskEnd(); // Record the end of the task console.log(`Completed ${tracker.getCompletedTasks()} out of ${tracker.tasksCount} tasks.`); console.log(`Elapsed Time: ${tracker.getElapsedTime().milliseconds} ms`); console.log(`Estimated Completion Time: ${tracker.getEstimatedCompletionTime().milliseconds} ms`); console.log(`Expected Finish Time: ${tracker.getExpectedFinishTime()}`);} // OUTPUT:// Completed 1 out of 5 tasks.// Elapsed Time: 1000 ms// Estimated Completion Time: 4000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 2 out of 5 tasks.// Elapsed Time: 2000 ms// Estimated Completion Time: 3000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 3 out of 5 tasks.// Elapsed Time: 3000 ms// Estimated Completion Time: 2000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 4 out of 5 tasks.// Elapsed Time: 4000 ms// Estimated Completion Time: 1000 ms// Expected Finish Time: Jan 1, 2000, 00:00:05// Completed 5 out of 5 tasks.// Elapsed Time: 5000 ms// Estimated Completion Time: 0 ms// Expected Finish Time: Jan 1, 2000, 00:00:05
The interval of the task to add.
Adds a task interval to the tracker.
the number of completed tasks.
Gets the number of completed tasks.
the total elapsed time since the first task started.
Gets the total elapsed time since the first task started.
Estimates the total time taken to complete all tasks.
Gets the expected finish time for all tasks.
the mean time taken per task.
Gets the mean time taken per task.
the number of remaining tasks.
Gets the number of remaining tasks.
the start time of the first task, or the creation time if no tasks have been started.
Gets the start time of the first task, or the creation time if no tasks have been started.
Marks the current task as completed,
Description
A utility class to track the duration of multiple tasks and estimate completion times.
Example
See