Blame view

stim/ui/progressbar.h 1.81 KB
cbce396e   David Mayerich   added support for...
1
2
3
  #ifndef RTS_PROGRESSBAR_H

  #define RTS_PROGRESSBAR_H

  

a47a23a9   dmayerich   added ENVI functions
4
5
  #include <iostream>

  #include <sstream>

48673e7e   David Mayerich   fixed progress ba...
6
  #include <iomanip>

a47a23a9   dmayerich   added ENVI functions
7
8
  using namespace std;

  

6c1fa9e6   David Mayerich   added time estima...
9
  void stimPrintTime(unsigned long long s) {

6c1fa9e6   David Mayerich   added time estima...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  	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)

a47a23a9   dmayerich   added ENVI functions
30
  {

cbce396e   David Mayerich   added support for...
31
  	//std::cout<<percent<<std::endl;

a47a23a9   dmayerich   added ENVI functions
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  	stringstream bar;

  	static int x = 0;

  	string slash[4];

  	slash[0] = "\\";

  	slash[1] = "-";

  	slash[2] = "/";

  	slash[3] = "|";

  	bar<<"[";

  	for(int i=0; i<40; i++)

  	{

  		if(percent > (float)i/(float)40 *100)

  			bar << "*";

  		else

  			bar << " ";

  	}

  	bar<<"]";

  	cout << "\r"; // carriage return back to beginning of line

  	cout << bar.str() << " " << slash[x] << " " << percent << " %"; // print the bars and percentage

6c1fa9e6   David Mayerich   added time estima...
50
  	if (elapsed_s > 0) {

c685653d   David Mayerich   fixed a bug in th...
51
  		stimPrintTime((unsigned long long)elapsed_s);

6c1fa9e6   David Mayerich   added time estima...
52
53
54
55
  		if (percent > 0) {

  			std::cout << " / ";

  			double s_per_percent = elapsed_s / percent;

  			double total = s_per_percent * 100;

c685653d   David Mayerich   fixed a bug in th...
56
  			stimPrintTime((unsigned long long)total);

6c1fa9e6   David Mayerich   added time estima...
57
58
  		}

  	}

cbce396e   David Mayerich   added support for...
59
  	cout.flush();

a47a23a9   dmayerich   added ENVI functions
60
61
62
  	x++; // increment to make the slash appear to rotate

  	if(x == 4)

  	x = 0; // reset slash animation

cbce396e   David Mayerich   added support for...
63
64
65
  }

  

  #endif