Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Module to calculate ETA

by bessarabov (Acolyte)
on Mar 01, 2013 at 18:13 UTC ( #1021312=perlquestion: print w/replies, xml ) Need Help??
bessarabov has asked for the wisdom of the Perl Monks concerning the following question:

Module to calculate ETA

I have a task that I'm solving. There is a web page that shows the progress of some long lasting process. The process consists of bunch of small tasks. I need to calculate estimated time of process accomplishment.

This sound pretty easy. I have start time, I know the number of small tasks that would be done. After complition each small task I can use the simple formula to calculate ETA:

estimated_time = number_of_tasks_left * ( ( current_time - start_time ) / number_of_tasks_done )

But I can't imagine that I'm the first who needs such a thing. I've tried to find CPAN module that can solve this kind of problem, but I found noting.

Actually there is a great module Term::ProgressBar that calculated ETA. I use this module in my console scripts and I'm supper happy with it, but I need to calculate ETA and output it on a web page, and for this task this module doesn't suit.

Actually I have written a draft of module Time::ETA that will solve my problem (you can see the working example). But I can't believe that there is no module for this purpose on CPAN.

My question is there some CPAN module that can help me solve my task, or I should complete Time::ETA and upload it to CPAN?

UPDATE: I've created and released module Time::ETA

Replies are listed 'Best First'.
Re: Module to calculate ETA
by SuicideJunkie (Vicar) on Mar 01, 2013 at 19:01 UTC

    As you noted, calculating ETA is three trivial math operations. Thus, I'm not at all surprised that there is no module for it.

    To make it worthwhile, you should probably add a start() / pause() / resume() to manage the clock, and perhaps track time at higher rez than unit seconds. Perhaps allow for multiple simultaneous timers and a combined ETA. Options for weighting more recent data points over old data points would be good too.

Re: Module to calculate ETA
by Khen1950fx (Canon) on Mar 02, 2013 at 16:00 UTC
    #!/usr/bin/perl use strict; use warnings; use Time::Progress; $| = 1; my $p = new Time::Progress; $p->restart; sleep 5; # or put your work here print $p->report( "done %p elapsed: %L (%l sec), ETA %E (%e sec)\n", 50); $p->stop; print $p->elapsed_str;
Re: Module to calculate ETA
by Anonymous Monk on Mar 02, 2013 at 23:31 UTC

    I'm assuming the purpose of the module is only to calculate the eta, and not to generate and update the web page (otherwise a name like Time::ETA::HTML would be more appropriate). So yes, certainly complete and upload it if you cannot find a module to fit your needs. But please:

    • design a reasonably intuitive api
    • document it clearly
    • include "see also" in the POD with a list of similar modules, such as Term::ProgressBar
    • be willing to do the necessary maintenance

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021312]
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-03-19 04:06 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (232 votes). Check out past polls.