Skip to content

Commit

Permalink
RF: use ratio_done instead of progress
Browse files Browse the repository at this point in the history
  • Loading branch information
nno committed Oct 5, 2016
1 parent 3e2d00b commit cc8c9e0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions mvpa/cosmo_show_progress.m
@@ -1,11 +1,11 @@
function progress_line=cosmo_show_progress(clock_start, progress, msg, prev_progress_line)
function progress_line=cosmo_show_progress(clock_start, ratio_done, msg, prev_progress_line)
% Shows a progress bar, and time elapsed and expected to complete.
%
% progress_line=cosmo_show_progress(clock_start, progress[, msg[, prev_progress_line]])
%
% Inputs:
% clock_start The time the task started (from clock()).
% progress 0 <= progress <= 1, where 0 means nothing
% ratio_done 0 <= ratio_done <= 1, where 0 means nothing
% completed and 1 means fully completed.
% msg String with a message to be shown next to the
% progress bar (optional).
Expand Down Expand Up @@ -33,10 +33,11 @@
% % this code takes just over 3 seconds to run, and fills a progress bar.
% prev_msg='';
% clock_start=clock();
% for k=0:100
% for k=1:100
% pause(.03);
% status=sprintf('done %.1f%%', k);
% prev_msg=cosmo_show_progress(clock_start,k/100,status,prev_msg);
% ratio_done=k/100;
% prev_msg=cosmo_show_progress(clock_start,ratio_done,status,prev_msg);
% end
% % output:
% > +00:00:03 [####################] -00:00:00 done 100.0%
Expand All @@ -53,25 +54,26 @@
if nargin<3 || isempty(msg)
msg='';
end
if progress<0 || progress>1
error('illegal progress %d: should be between 0 and 1', progress);
if ratio_done<0 || ratio_done>1
error('illegal progress %d: should be between 0 and 1', ratio_done);
end

if progress==0
if ratio_done==0
ratio_to_do=Inf;
else
ratio_to_do=(1-progress)/progress;
ratio_to_do=(1-ratio_done)/ratio_done;
end

took=etime(clock, clock_start);
clock_now=clock();
took=etime(clock_now, clock_start);
eta=ratio_to_do*took; % 'estimated time of arrival'

% set number of backspace characters
delete_str=repmat(sprintf('\b'),1,delete_count);

% define the bar
bar_width=20;
bar_done=round(progress*bar_width);
bar_done=round(ratio_done*bar_width);
bar_eta=bar_width-bar_done;
bar_str=[repmat('#',1,bar_done) repmat('-',1,bar_eta)];

Expand All @@ -82,7 +84,7 @@
secs2str(-eta)),...
msg];

if progress==1
if ratio_done==1
postfix=sprintf('\n');
else
postfix='';
Expand Down

0 comments on commit cc8c9e0

Please sign in to comment.