ComPWA
Common Partial-Wave-Analysis Framework
ProgressBar.cpp
Go to the documentation of this file.
1
// Copyright (c) 2013 The ComPWA Team.
2
// This file is part of the ComPWA framework, check
3
// https://github.com/ComPWA/ComPWA/license.txt for details.
4
5
#include "
Core/ProgressBar.hpp
"
6
7
#include <chrono>
8
#include <iostream>
9
10
namespace
ComPWA
{
11
12
ProgressBar::ProgressBar
() :
ProgressBar
(0, 0) {}
13
14
ProgressBar::ProgressBar
(std::size_t size,
int
update
)
15
:
numEvents
(size),
updateInterval
(update),
hasStarted
(0),
startTime
(0),
16
currentPercent
(0),
currentEvent
(0),
lastUpdate
(0) {
17
if
(update == 0)
18
updateInterval
= 1;
19
}
20
21
ProgressBar::~ProgressBar
() { std::cout << std::endl; }
22
23
void
ProgressBar::next
(
size_t
increment) {
24
if
(!
hasStarted
) {
25
lastUpdate
= 0;
26
currentEvent
= 0;
27
time(&
startTime
);
28
hasStarted
= 1;
29
update
();
30
fflush(stdout);
31
}
32
currentEvent
+= increment;
33
if
(
currentEvent
>
numEvents
)
34
currentEvent
=
numEvents
;
35
if
((
int
)((
timePassed
() -
lastUpdate
)) >
updateInterval
)
36
update
();
37
if
(
currentEvent
==
numEvents
) {
38
update
();
39
std::cout << std::endl;
40
}
41
}
42
void
ProgressBar::update
() {
43
// std::cout<<"update()"<<std::endl;
44
// std::cout<<timePassed()<<" "<<lastUpdate<<"
45
//"<<(int)((timePassed()-lastUpdate))<<std::endl;
46
currentPercent
= (double)
currentEvent
/
numEvents
* 100;
47
int
nStars = ((int)(
currentPercent
/ 10 + 0.5));
48
char
buf[10];
49
int
i = 0;
50
for
(; i < nStars; i++)
51
buf[i] =
'*'
;
52
for
(; i < 10; i++)
53
buf[i] =
'-'
;
54
// for( ; i<15; i++) buf[i]=' ';
55
time_t estEndTime =
endTime
();
56
char
timebuf[10];
57
strftime(timebuf, 10,
"%I:%M%p"
, localtime(&estEndTime));
58
// the escape sequence \e[?25l switches off the courser and \e[?25h switch it
59
// on again
60
printf(
"\e[?25l \r %4.2fmin [ %.*s %4.2f%% ] %4.2fmin , end time: %7s "
61
" \e[?25h"
,
62
timePassed
() / 60, 10, buf,
currentPercent
,
timeRemaining
() / 60,
63
timebuf);
64
fflush(stdout);
65
66
lastUpdate
=
timePassed
();
67
return
;
68
}
69
70
double
ProgressBar::timeRemaining
() {
71
if
(
currentPercent
== 0)
72
return
0.0;
73
return
timePassed
() * (1 /
currentPercent
* 100 - 1);
74
}
75
double
ProgressBar::timePassed
() {
76
time_t currentTime;
77
time(¤tTime);
78
return
difftime(currentTime,
startTime
);
79
}
80
81
time_t
ProgressBar::endTime
() {
82
time_t currentTime;
83
time(¤tTime);
84
time_t estEndTime = currentTime +
timeRemaining
();
85
return
estEndTime;
86
}
87
88
}
// namespace ComPWA
ComPWA::ProgressBar
Definition:
ProgressBar.hpp:12
ComPWA
Definition:
Efficiency.cpp:7
ComPWA::ProgressBar::numEvents
std::size_t numEvents
Definition:
ProgressBar.hpp:29
ComPWA::ProgressBar::endTime
time_t endTime()
Definition:
ProgressBar.cpp:81
ComPWA::ProgressBar::update
void update()
Definition:
ProgressBar.cpp:42
ComPWA::ProgressBar::~ProgressBar
~ProgressBar()
Definition:
ProgressBar.cpp:21
ComPWA::ProgressBar::timePassed
double timePassed()
Definition:
ProgressBar.cpp:75
ProgressBar.hpp
ComPWA::ProgressBar::hasStarted
bool hasStarted
Definition:
ProgressBar.hpp:31
ComPWA::ProgressBar::lastUpdate
double lastUpdate
Definition:
ProgressBar.hpp:36
ComPWA::ProgressBar::ProgressBar
ProgressBar()
Definition:
ProgressBar.cpp:12
ComPWA::ProgressBar::currentPercent
double currentPercent
Definition:
ProgressBar.hpp:34
ComPWA::ProgressBar::startTime
time_t startTime
Definition:
ProgressBar.hpp:32
ComPWA::ProgressBar::updateInterval
int updateInterval
Definition:
ProgressBar.hpp:30
ComPWA::ProgressBar::timeRemaining
double timeRemaining()
Definition:
ProgressBar.cpp:70
ComPWA::ProgressBar::next
void next(size_t increment=1)
indicate the next step in process
Definition:
ProgressBar.cpp:23
ComPWA::ProgressBar::currentEvent
unsigned int currentEvent
Definition:
ProgressBar.hpp:35
Core
ProgressBar.cpp
Generated on Mon Jun 22 2020 13:03:33 for ComPWA by
1.8.13