27 #ifndef SRC_ENV_PROGRESS_BAR_IPP_ 28 #define SRC_ENV_PROGRESS_BAR_IPP_ 35 num_tasks_{num_tasks},
36 start_time_{std::chrono::high_resolution_clock::now()} {}
47 num_solved_tasks_ = 0;
51 operator<<(std::ostream & os,
const ProgressBar & progress_bar) {
53 std::streamsize precision{os.precision()};
55 os.setf(std::ios::fixed, std::ios::floatfield);
56 double progress_in_percent{100.0 *
static_cast<double>(progress_bar.num_solved_tasks_) / static_cast<double>(progress_bar.num_tasks_)};
58 for (std::size_t i{1}; i <= 10; i++) {
59 if (static_cast<double>(i) <= progress_in_percent / 10.0) {
62 else if (static_cast<double>(i - 1) < progress_in_percent / 10.0) {
70 if (progress_in_percent < 100) {
73 if (progress_in_percent < 10) {
76 os << progress_in_percent <<
" %";
77 if (progress_in_percent > 0) {
78 std::size_t max_num_digits{7};
79 std::size_t num_digits{4};
80 std::chrono::duration<double> runtime_so_far = std::chrono::high_resolution_clock::now() - progress_bar.start_time_;
81 double estimated_remaining_runtime{(runtime_so_far.count() * ((100.0 / progress_in_percent) - 1.0)) / (60.0 * 60.0)};
82 if (estimated_remaining_runtime >= 10) {
85 if (estimated_remaining_runtime >= 100) {
88 if (estimated_remaining_runtime >= 1000) {
91 while(num_digits++ < max_num_digits) {
94 os <<
" " << estimated_remaining_runtime;
100 os.unsetf(std::ios::floatfield);
101 os.precision(precision);
ProgressBar(std::size_t num_tasks)
Constructs a progress bar for given number of tasks.
Global namespace for GEDLIB.
void increment()
Increments the number of solved tasks.
void reset()
Sets the number of solved tasks to 0.