21 #include <UtilLib/include/ProgressBar.hpp>
22 #include <UtilLib/include/TerminalColors.hpp>
28 unsigned int expectedCount,
29 double updateInterval,
32 expectedCount_(expectedCount),
37 updateInterval_(updateInterval) {
38 outputStream_ <<
"progress: " << std::setw(4) << std::setprecision(3) <<
39 static_cast<float>(tic_) <<
"% estimated time remaining:" << std::setw(
40 6) << std::setprecision(3) <<
"inf sec\n"
41 <<
"0% 10 20 30 40 50 60 70 80 90 100%\n"
42 <<
"|----|----|----|----|----|----|----|----|----|----|"
49 if (count_ >= nextTicCount_) {
52 }
else if (count_ > updateCount_) {
66 void ProgressBar::displayTic() {
67 unsigned int tics_needed =
68 static_cast<unsigned int>((
static_cast<double>(count_) /
69 expectedCount_) * 50.0);
71 outputStream_ <<
'*' << std::flush;
72 }
while (++tic_ < tics_needed);
74 nextTicCount_ =
static_cast<unsigned int>((tic_ / 50.0) * expectedCount_);
76 if (count_ == expectedCount_) {
77 outputStream_ << STORE_CURSOR << GO_LINE_UP << GO_LINE_UP << GO_LINE_UP
78 << GO_LINE_BEGIN <<
"progress: " << std::setw(4)
79 << std::setprecision(3) <<
static_cast<float>(100)
80 <<
"% estimated time remaining:" << std::setw(6)
81 << std::setprecision(3) << 0.0 <<
" sec" << DEL_END
86 outputStream_ <<
"\noverall runtime: " << std::setw(9) << BOLDWHITE
87 << std::setprecision(6) << wholeTime_.
stop() <<
" sec"
88 << RESET << std::endl;
92 void ProgressBar::displayPercentage() {
93 const float percentage =
static_cast<float>(count_) / (expectedCount_) *
95 const float dt = wholeTime_.
stop();
96 const float remainingTime = 100 * dt / percentage - dt;
97 updateCount_ = count_ + count_ / dt * updateInterval_;
106 outputStream_ << STORE_CURSOR << GO_LINE_UP << GO_LINE_UP << GO_LINE_UP
107 << GO_LINE_BEGIN <<
"progress: " << std::setw(4)
108 << BOLDWHITE << std::setprecision(3) << percentage <<
"% "
109 << RESET <<
"estimated time remaining: " << std::setw(6)
110 << BOLDWHITE << std::setprecision(3) << remainingTime << RESET
111 <<
" sec" << DEL_END << RESET_CURSOR << std::flush;
unsigned int operator+=(unsigned int increment)
void start()
starts the timer
ProgressBar(unsigned int expected_count, double updateInterval=30, std::ostream &os=std::cout)
unsigned int operator++()
Prefix operator.
double stop()
stops the timer and returns the time in sec