MINT2
Public Member Functions | Private Attributes | List of all members
LoadingBar Class Reference

#include <LoadingBar.h>

Public Member Functions

 LoadingBar (int nIterations, int nSteps=20)
 
void printTimeDiff (double minutes)
 
void update (int i)
 
 ~LoadingBar ()
 

Private Attributes

int _nIterations
 
int _nSteps
 
int _prevStep
 
time_t _tstart
 

Detailed Description

Definition at line 11 of file LoadingBar.h.

Constructor & Destructor Documentation

◆ LoadingBar()

LoadingBar::LoadingBar ( int  nIterations,
int  nSteps = 20 
)

Definition at line 3 of file LoadingBar.cpp.

3  :
4  _nIterations(nIterations),
5  _nSteps (nSteps),
6  _prevStep (-1)
7 {
8 
9  _tstart = time(0);
10 
11 
12 }
int _prevStep
Definition: LoadingBar.h:15
int _nIterations
Definition: LoadingBar.h:13
int _nSteps
Definition: LoadingBar.h:14
time_t _tstart
Definition: LoadingBar.h:17

◆ ~LoadingBar()

LoadingBar::~LoadingBar ( )

Definition at line 79 of file LoadingBar.cpp.

79  {
80 
81 }

Member Function Documentation

◆ printTimeDiff()

void LoadingBar::printTimeDiff ( double  minutes)

Definition at line 15 of file LoadingBar.cpp.

15  {
16 
17  if (minutes > 60.0){
18  int hours = floor( minutes / 60.0 );
19  int mins = floor( minutes - hours*60.0 );
20  std::cout << hours << "h " << mins;
21  }
22  else if (minutes < 60.0 && minutes > 1.0){
23  int mins = floor( minutes );
24  int seconds = floor( double( minutes - mins )*60.0 );
25  std::cout << mins << "m " << seconds;
26  }
27  else{
28  int seconds = floor( (minutes)*600.0 );
29  std::cout << seconds*0.1 << "s";
30  }
31 }

◆ update()

void LoadingBar::update ( int  i)

Definition at line 33 of file LoadingBar.cpp.

33  {
34 
35  double frac = double(i+1)/double(_nIterations);
36  int steps = floor(_nSteps*frac);
37 
38  int per = floor(100*frac);
39 
40 
41  if (_prevStep != per){
42 
43  double delT = difftime(time(0), _tstart);
44 
45  double detTMins = delT / 60.0;
46  double evtsPerMin = (double(i)/detTMins);
47 
48  double totalTimeMins = double(_nIterations)/evtsPerMin;
49  double remainingTime = totalTimeMins*(1.0-frac);
50 
51  std::cout << "\r [";
52 
53  for (int j = 0; j < _nSteps; j++){
54  if (j < steps) std::cout << "=";
55  else std::cout << " ";
56  }
57 
58  std::cout << "] " << per << "% Complete. ";
59  printTimeDiff(remainingTime);
60  std::cout << " left. " << std::flush;
61 
62  _prevStep = per;
63 
64  }
65 
66  if ( frac == 1.0 ) {
67 
68  double delT = difftime(time(0), _tstart);
69  double detTMins = delT / 60.0;
70  double evtsPerMin = (double(_nIterations)/detTMins);
71 
72  std::cout << "\r Completed in ";
73  printTimeDiff(detTMins);
74  std::cout << " which is " << floor(evtsPerMin) << " iterations/min " << std::flush << std::endl;
75 
76  }
77 }
int _prevStep
Definition: LoadingBar.h:15
int _nIterations
Definition: LoadingBar.h:13
void printTimeDiff(double minutes)
Definition: LoadingBar.cpp:15
int _nSteps
Definition: LoadingBar.h:14
time_t _tstart
Definition: LoadingBar.h:17

Member Data Documentation

◆ _nIterations

int LoadingBar::_nIterations
private

Definition at line 13 of file LoadingBar.h.

◆ _nSteps

int LoadingBar::_nSteps
private

Definition at line 14 of file LoadingBar.h.

◆ _prevStep

int LoadingBar::_prevStep
private

Definition at line 15 of file LoadingBar.h.

◆ _tstart

time_t LoadingBar::_tstart
private

Definition at line 17 of file LoadingBar.h.


The documentation for this class was generated from the following files: