Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong behaviour of SGIO::progress #3694

Merged
merged 1 commit into from
Mar 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/shogun/io/SGIO.cpp
Original file line number Diff line number Diff line change
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