Skip to content

Commit

Permalink
[ProgressBar] Refactor progress time evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
geektoni authored and vigsterkr committed Jun 2, 2017
1 parent 176fdd0 commit fb510cc
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions src/shogun/base/progress.h
Expand Up @@ -77,31 +77,35 @@ namespace shogun
const SGIO& io, float64_t max_value, float64_t min_value)
: m_io(io), m_max_value(max_value), m_min_value(min_value),
m_prefix("PROGRESS: "), m_mode(UTF8), m_last_progress(0),
m_last_progress_time(0), m_progress_start_time(0)
m_last_progress_time(0),
m_progress_start_time(CTime::get_curtime())
{
}
ProgressPrinter(
const SGIO& io, float64_t max_value, float64_t min_value,
const std::string& prefix)
: m_io(io), m_max_value(max_value), m_min_value(min_value),
m_prefix(prefix), m_mode(UTF8), m_last_progress(0),
m_last_progress_time(0), m_progress_start_time(0)
m_last_progress_time(0),
m_progress_start_time(CTime::get_curtime())
{
}
ProgressPrinter(
const SGIO& io, float64_t max_value, float64_t min_value,
const SG_PRG_MODE mode)
: m_io(io), m_max_value(max_value), m_min_value(min_value),
m_prefix("PROGRESS: "), m_mode(mode), m_last_progress(0),
m_last_progress_time(0), m_progress_start_time(0)
m_last_progress_time(0),
m_progress_start_time(CTime::get_curtime())
{
}
ProgressPrinter(
const SGIO& io, float64_t max_value, float64_t min_value,
const std::string& prefix, const SG_PRG_MODE mode)
: m_io(io), m_max_value(max_value), m_min_value(min_value),
m_prefix(prefix), m_mode(mode), m_last_progress(0),
m_last_progress_time(0), m_progress_start_time(0)
m_last_progress_time(0),
m_progress_start_time(CTime::get_curtime())
{
}
~ProgressPrinter()
Expand Down Expand Up @@ -141,16 +145,15 @@ namespace shogun
float64_t runtime = CTime::get_curtime();

if (difference > 0.0)
v = 100 * (current_value - m_min_value + 1) /
(m_max_value - m_min_value + 1);
v = 100 * (current_value + 1 - m_min_value) /
(m_max_value - m_min_value);

// Set up chunk size
size_chunk = difference / (float64_t)progress_bar_space;

if (m_last_progress == 0)
{
m_last_progress_time = runtime;
m_progress_start_time = runtime;
m_last_progress = v;
}
else
Expand All @@ -159,20 +162,6 @@ namespace shogun

if ((v != 100.0) && (runtime - m_last_progress_time < 0.5))
{
// This is made to display correctly the percentage
// if the algorithm execution is too fast
if (current_value >= m_max_value - 1)
{
v = 100;
m_last_progress = v - 1e-6;
snprintf(
str, sizeof(str), "%%s %.2f %%1.1f "
"seconds remaining %%1.1f "
"seconds total\r");
m_io.message(
MSG_MESSAGEONLY, "", "", -1, str, m_prefix.c_str(),
v, estimate, total_estimate);
}
return;
}

Expand All @@ -188,7 +177,7 @@ namespace shogun
m_io.message(MSG_MESSAGEONLY, "", "", -1, "%s |", m_prefix.c_str());
for (index_t i = 1; i < progress_bar_space; i++)
{
if (current_value > i * size_chunk)
if (current_value + 1 - m_min_value > i * size_chunk)
{
m_io.message(
MSG_MESSAGEONLY, "", "", -1, "%s",
Expand Down Expand Up @@ -219,9 +208,10 @@ namespace shogun
MSG_MESSAGEONLY, "", "", -1, str, estimate, total_estimate);
}

// If we arrive to the end, we print a new line (fancier output)
if (current_value >= m_max_value)
m_io.message(MSG_MESSAGEONLY, "", "", -1, "\n");
if (current_value + 1 - m_min_value >= m_max_value)
{
return;
}
}

/** Print the progress bar end */
Expand All @@ -232,6 +222,7 @@ namespace shogun
return;

print_progress(m_max_value);
m_io.message(MSG_MESSAGEONLY, "", "", -1, "\n");
}

/** @return last progress as a percentage */
Expand Down

0 comments on commit fb510cc

Please sign in to comment.