Commit 6c1fa9e6d86f10002fbacfef71353e983ca024c0

Authored by David Mayerich
1 parent df98143c

added time estimates to the progress bar

Showing 1 changed file with 31 additions and 1 deletions   Show diff stats
stim/ui/progressbar.h
@@ -5,7 +5,28 @@ @@ -5,7 +5,28 @@
5 #include <sstream> 5 #include <sstream>
6 using namespace std; 6 using namespace std;
7 7
8 -static void rtsProgressBar(unsigned int percent) 8 +void stimPrintTime(unsigned long long s) {
  9 + char buffer[26];
  10 + std::cout << std::fixed << std::showpoint << std::setprecision(1);
  11 + if (s >= 60) { //if there are more than 60 seconds
  12 + unsigned long long m = s / 60; //get the number of minutes
  13 + s = s - m * 60; //get the number of remaining seconds
  14 + if (m > 60) { //if more than 60 minutes
  15 + unsigned long long h = m / 60;
  16 + m = m - h * 60; //get the number of remaining minutes
  17 + if (h > 24) { //if there are more than 24 hours
  18 + unsigned long long d = h / 24;
  19 + h = h - d * 24; //get the number of remaining hours
  20 + std::cout << " " << d << "d";
  21 + }
  22 + std::cout << " " << h << "h";
  23 + }
  24 + std::cout << " " << m << "m";
  25 + }
  26 + std::cout << " " << s << "s";
  27 +}
  28 +
  29 +static void rtsProgressBar(unsigned int percent, double elapsed_s = 0)
9 { 30 {
10 //std::cout<<percent<<std::endl; 31 //std::cout<<percent<<std::endl;
11 stringstream bar; 32 stringstream bar;
@@ -26,6 +47,15 @@ static void rtsProgressBar(unsigned int percent) @@ -26,6 +47,15 @@ static void rtsProgressBar(unsigned int percent)
26 bar<<"]"; 47 bar<<"]";
27 cout << "\r"; // carriage return back to beginning of line 48 cout << "\r"; // carriage return back to beginning of line
28 cout << bar.str() << " " << slash[x] << " " << percent << " %"; // print the bars and percentage 49 cout << bar.str() << " " << slash[x] << " " << percent << " %"; // print the bars and percentage
  50 + if (elapsed_s > 0) {
  51 + stimPrintTime(elapsed_s);
  52 + if (percent > 0) {
  53 + std::cout << " / ";
  54 + double s_per_percent = elapsed_s / percent;
  55 + double total = s_per_percent * 100;
  56 + stimPrintTime(total);
  57 + }
  58 + }
29 cout.flush(); 59 cout.flush();
30 x++; // increment to make the slash appear to rotate 60 x++; // increment to make the slash appear to rotate
31 if(x == 4) 61 if(x == 4)