Re: function to approximate time elapsed
- From: "Ioannis" <morpheus@xxxxxxxxxxxx>
- Date: Thu, 12 Apr 2007 20:26:03 +0300
"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/
.
- Follow-Ups:
- Re: function to approximate time elapsed
- From: CosminB [BRT]
- Re: function to approximate time elapsed
- References:
- function to approximate time elapsed
- From: CosminB [BRT]
- function to approximate time elapsed
- Prev by Date: Re: Map S^n -> S^n with topological degree zero
- Next by Date: Re: function to approximate time elapsed
- Previous by thread: function to approximate time elapsed
- Next by thread: Re: function to approximate time elapsed
- Index(es):
Relevant Pages
|