Blame view

stim/ui/progressbar.h 1.79 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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  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)

a47a23a9   dmayerich   added ENVI functions
31
  {

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

a47a23a9   dmayerich   added ENVI functions
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  	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...
51
52
53
54
55
56
57
58
59
  	if (elapsed_s > 0) {

  		stimPrintTime(elapsed_s);

  		if (percent > 0) {

  			std::cout << " / ";

  			double s_per_percent = elapsed_s / percent;

  			double total = s_per_percent * 100;

  			stimPrintTime(total);

  		}

  	}

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

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

  	if(x == 4)

  	x = 0; // reset slash animation

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

  

  #endif