Re: function to approximate time elapsed



"CosminB [BRT]" <cosminb@xxxxxxxxx> wrote in message
news:1176396414.790112.49250@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi all,

I need a function to approximate the time passing. I have a rough
estimate for an operation, how long it should take. But very often, it
takes longer. I need a function to fill a progress bar about how much
of the operation has been completed. These are the requirements:

Suppose D is the time in which the operation should complete. If the
time elapsed is less than D, then the progress bar should fill (almost
linearly) from 0% to 80%. After the D seconds are elapsed, I need the
progress bar to slow down, going from 80% to 99%, never reaching 100%.
How can I put this into a function y = f(x)? Any ideas much
appreciated.

I can't answer your question, because you are approaching it the wrong way.
You can *ALWAYS* approximate the time a programming task takes and accordingly
adjust your progress bar.

Here's the way I do it in my program. Suppose your task consists of n
procedures:

proc1, proc2,...,procn.

const
kTotalCount = 100; {number of tasks, procedures, or whatever, n=100}
var
count:integer;

InitializeProgressBar;
begin
count:=0;
DrawDialog;
end;

procedure DrawNewProgress;
begin
percentage:=barLength * count div kTotalCount;
DrawDialogRect(percentage); {or some other parameter}
end;

UpdateProgressBar;
begin
DrawNewProgress;
end;

procedure FinishProgressBar;
begin
DrawRect(barLength);
CloseDialog;
end;

procedure procn;
begin
count:=count+1;
UpdateProgressBar;
...(task)
end;

begin {main}
InitializeProgressBar;
proc1;
proc2;
...
procn;
FinishProgressBar;
end.

If you want your progress bar to have a "finer" resolution that the above,
change kTotalCount to a larger number and insert more statements like the ones
below within more tasks:

count:=count+1; {* increment *}
UpdateProgressBar;

For example, if you want your progress bar to not jump abruptly, the number of
above increment statements {*} should equal kTotalCount (although it's not
strictly necessary) and your procn's should roughly take equal time to
execute. If a particular prock takes longer to execute, say by a factor of 10
relative to the other procs, insert 10 increments {*} inside it, instead of
just 1, equally spaced among subtasks.

The finer the resolution, the more "linear" the bar's appearance will be,
although there is no way to make it perfectly linear, because there is no way
to predict in advance how long the tasks will take.

Thanks in advance,
Cosmin.
--
I.N. Galidakis --- http://ioannis.virtualcomposer2000.com/

.



Relevant Pages

  • Re: bonus parameters progression
    ... It's a game. ... to a logarithmic scale, but still converting units. ... of the progress bar: irregular, linear, exponential, logarythmic, ... for the progress bar to finish, ...
    (rec.games.roguelike.development)
  • Re: function to approximate time elapsed
    ... I need afunctionto fill a progress bar about how much ... The finer the resolution, the more "linear" the bar's appearance will be, ... installing an application using the MSI installer. ...
    (sci.math)
  • Re: DELETE statement - Progress
    ... I need to execute a DELETE statement (SQL Server), ... I would like to make a progress bar where I would show a % ... Execute that repeatedly until @@rowcount returns 0. ...
    (microsoft.public.data.ado)
  • Re: Displaying a Progress Indicator (VBA)
    ... Your code should execute almost instantly and therefore a progress bar ... Sometimes I come across lengthy macros and wonder if my computer "hung up" on ... Sub Macro1() ... How do I create a progress bar for this code. ...
    (microsoft.public.excel.misc)
  • Re: Using Thread.sleep(..) and Swing Components
    ... Peter Duniho wrote: ... Operations that take any significant amount of time should be handled on a different thread, using the EventQueue.invokeLaterand EventQueue.invokeAndWaitmethods to execute any code that is required to be executed on the EDT (such as setting the value of a progress bar control). ...
    (comp.lang.java.programmer)