* @brief Generates a string progress bar * * @param current current job * @param total total number of jobs * @param start_info progress bar prior info */
| 61 | * @param start_info progress bar prior info |
| 62 | */ |
| 63 | void status_bar(int64_t current, int64_t total, const std::string& start_info) { |
| 64 | auto precision = std::cout.precision(); |
| 65 | static auto prev_time = std::chrono::high_resolution_clock::now(); |
| 66 | static auto prev = current - 1; |
| 67 | static auto prev2 = prev; |
| 68 | static auto prev2_time = prev_time; |
| 69 | |
| 70 | auto curr_time = std::chrono::high_resolution_clock::now(); |
| 71 | |
| 72 | double percent = 100.0 * (double)(current + 1) / (double)total; |
| 73 | std::string str = "["; |
| 74 | for (int i = 0; i < 50; ++i) { |
| 75 | if (percent >= i * 2) |
| 76 | str += "="; |
| 77 | else |
| 78 | str += " "; |
| 79 | } |
| 80 | str += "]"; |
| 81 | |
| 82 | auto time = |
| 83 | current != prev |
| 84 | ? (total - current) * (curr_time - prev_time) / (current - prev) |
| 85 | : (total - current) * (curr_time - prev2_time) / (current - prev2); |
| 86 | |
| 87 | if (current != prev && prev != prev2) { |
| 88 | prev2 = prev; |
| 89 | prev2_time = prev_time; |
| 90 | } |
| 91 | prev = current; |
| 92 | prev_time = curr_time; |
| 93 | |
| 94 | if (current != total) { |
| 95 | using namespace std::chrono_literals; |
| 96 | std::cout << start_info << " " << std::fixed << std::setprecision(1) |
| 97 | << percent << "% " << str << " Time Remaining: "; |
| 98 | if (std::chrono::duration_cast<std::chrono::seconds>(time).count() > |
| 99 | 300) |
| 100 | std::cout << std::chrono::duration_cast<std::chrono::minutes>(time) |
| 101 | .count() |
| 102 | << " min"; |
| 103 | else |
| 104 | std::cout << std::chrono::duration_cast<std::chrono::seconds>(time) |
| 105 | .count() |
| 106 | << " s"; |
| 107 | |
| 108 | std::cout << std::string(5, ' ') << '\r'; |
| 109 | } else |
| 110 | std::cout << "\rDone!" << std::string(120, ' ') << std::endl; |
| 111 | |
| 112 | std::cout << std::setprecision(precision) << std::defaultfloat; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @brief Returns the euclidean dot product for two cartesian vectors with 3 |