Skip to content

Commit

Permalink
Merge pull request #3694 from geektoni/patch-12
Browse files Browse the repository at this point in the history
Fix wrong behaviour of SGIO::progress
  • Loading branch information
vigsterkr committed Mar 15, 2017
2 parents 15db575 + 2356cb4 commit 2599ce5
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/shogun/io/SGIO.cpp
Expand Up @@ -54,7 +54,7 @@ char SGIO::directory_name[FBUFSIZE];

SGIO::SGIO()
: target(stdout), last_progress_time(0), progress_start_time(0),
last_progress(1), show_progress(false), location_info(MSG_NONE),
last_progress(-1), show_progress(false), location_info(MSG_NONE),
syntax_highlight(true), loglevel(MSG_WARN)
{
m_refcount = new RefCount();
Expand Down Expand Up @@ -170,7 +170,7 @@ void SGIO::progress(
if (decimals < 1)
decimals = 1;

if (last_progress>v)
if (last_progress==-1)
{
last_progress_time = runtime;
progress_start_time = runtime;
Expand All @@ -182,7 +182,19 @@ void SGIO::progress(
last_progress = v-1e-6;

if ((v!=100.0) && (runtime - last_progress_time<0.5))
{

// This is made to display correctly the percentage
// if the algorithm execution is too fast
if (current_val >= max_val-1)
{
v = 100;
snprintf(str, sizeof(str), "%%s %%%d.%df%%%% %%1.1f seconds remaining %%1.1f seconds total ",decimals+3, decimals);
message(MSG_MESSAGEONLY, "", "", -1, str, prefix, v, estimate, total_estimate);
message(MSG_MESSAGEONLY, "", "", -1, "\n");
}
return;
}

last_progress_time = runtime;
estimate = (1-v/100)*(last_progress_time-progress_start_time)/(v/100);
Expand All @@ -200,6 +212,13 @@ void SGIO::progress(
message(MSG_MESSAGEONLY, "", "", -1, str, prefix, v, estimate, total_estimate);
}

// Print a new line if the execution is completed
// to prevent bad display
if (current_val >= max_val-1)
{
message(MSG_MESSAGEONLY, "", "", -1, "\n");
}

fflush(target);
}

Expand Down

0 comments on commit 2599ce5

Please sign in to comment.