Git Product home page Git Product logo

progress-estimator's Introduction

Progress Estimator

PHP library to estimate time remaining for a list of tasks.

Build Status Percentage of issues still open

When processing a batch of items that takes a long time to run, this library can be used to to calculate and display the estimated time remaining.

Processing 12 items
[1/12]: Bacon ipsum dolor amet (0:35)
[2/12]: Cow porchetta labore shankle (0:33)
[3/12]: Filet mignon porchetta eiusmod tri-tip (0:28)
[4/12]: Venison aliqua, ad brisket pariatur (0:22)
[5/12]: Turkey reprehenderit picanha (0:18)
[6/12]: Turducken fatback ground round (0:16)
[7/12]: Strip steak leberkas laborum (0:12)
[8/12]: Pork belly excepteur buffalo (0:09)
[9/12]: ham chuck ipsum nostrud jerky (0:07)
[10/12]: Rump shank jalapeno (0:05)
[11/12]: Pancetta chicken do spare ribs, (0:02)
[12/12]: Meatball tenderloin picanha (0:00)

Installation and Usage

This package can be installed via composer.

composer require petenelson/progress-estimator

Here is some example code below, and be sure to check the examples.php file for a working implementation.

require_once __DIR__ . '/vendor/autoload.php';

$items = get_large_list_of_items();
$count = count($items);

// Create the progress estimator.
$estimator = new \PHPEstimator\ProgressEstimator($count);

// Loop through the list of items to process.
for ($i=0; $i < $count; $i++) {

	// Perform some work on each item.
	some_long_running_process_here($items[$i]);

	// Increments the counter and saves the execution time of that item.
	$estimator->tick();

	// Display the current item processed and estimated time remaining.
	$output = sprintf(
		'Processed: %1$s (%2$s)' . PHP_EOL,
		$i,
		$estimator->formatTime($estimator->timeLeft())
	);

	echo $output;
}

progress-estimator's People

Contributors

petenelson avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

progress-estimator's Issues

Implement different estimate calculation types

The current implementation takes the average execution time of each item to determine the estimated time remaining. Depending on the scenario, item processing may go slower for each item as the processing progresses, such as a large database migration that has more and more data to query, processing images in order of their file size, etc.

Let's say there are 100 items to process and processing time increases as they are processed. The first twenty items take one second each, the next twenty take five seconds each, and the next twenty take ten seconds each. Using the current implementation, that's an average of 5.3 seconds per item.

Rather than using an overall average, I'd like to implement a parameter in the constructor that takes a sample mode and a sample size. If we pass in a calculation mode of count and a sample size of 40, the code would look at the last forty items processed to get an average time of 7.5 seconds per item. This time would be used to calculate the estimated time remaining for the rest of the items to be processed. I would also like to allow for a calculation mode of percent to look at the last X percent of items to get the average.

Examples:

// Use the last 40 items to determine an average.
$estimator = new \PHPEstimator\Estimator(
   100,
   ['calculation_mode' => 'count', 'sample_size' => 40]
);

// Use the last 10 percent of the total items to determine an average.
$estimator = new \PHPEstimator\Estimator(
   100,
   ['calculation_mode' => 'percent', 'sample_size' => 10]
);

The code would not switch over to using a different calculation mode until the number of items processed reaches the sample size.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.