From 6c1fa9e6d86f10002fbacfef71353e983ca024c0 Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Sun, 3 Sep 2017 10:07:03 -0500 Subject: [PATCH] added time estimates to the progress bar --- stim/ui/progressbar.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/stim/ui/progressbar.h b/stim/ui/progressbar.h index aed05ef..445d6a4 100644 --- a/stim/ui/progressbar.h +++ b/stim/ui/progressbar.h @@ -5,7 +5,28 @@ #include using namespace std; -static void rtsProgressBar(unsigned int percent) +void stimPrintTime(unsigned long long s) { + char buffer[26]; + std::cout << std::fixed << std::showpoint << std::setprecision(1); + if (s >= 60) { //if there are more than 60 seconds + unsigned long long m = s / 60; //get the number of minutes + s = s - m * 60; //get the number of remaining seconds + if (m > 60) { //if more than 60 minutes + unsigned long long h = m / 60; + m = m - h * 60; //get the number of remaining minutes + if (h > 24) { //if there are more than 24 hours + unsigned long long d = h / 24; + h = h - d * 24; //get the number of remaining hours + std::cout << " " << d << "d"; + } + std::cout << " " << h << "h"; + } + std::cout << " " << m << "m"; + } + std::cout << " " << s << "s"; +} + +static void rtsProgressBar(unsigned int percent, double elapsed_s = 0) { //std::cout< 0) { + stimPrintTime(elapsed_s); + if (percent > 0) { + std::cout << " / "; + double s_per_percent = elapsed_s / percent; + double total = s_per_percent * 100; + stimPrintTime(total); + } + } cout.flush(); x++; // increment to make the slash appear to rotate if(x == 4) -- libgit2 0.21.4