|
2 | 2 |
|
3 | 3 | #include "simplnx/DataStructure/DataArray.hpp" |
4 | 4 | #include "simplnx/DataStructure/NeighborList.hpp" |
| 5 | +#include "simplnx/Utilities/MessageHelper.hpp" |
5 | 6 |
|
6 | 7 | using namespace nx::core; |
7 | 8 |
|
@@ -66,30 +67,13 @@ class FindDensityGrouping |
66 | 67 | // Default value-initialized to zeroes: https://en.cppreference.com/w/cpp/named_req/DefaultInsertable |
67 | 68 | checkedFeatureVolumes.resize(numFeatures); |
68 | 69 | } |
69 | | - int32_t progInt = 0; |
70 | | - usize prevParentId = 1; |
71 | | - usize currentParentId = 1; |
72 | | - auto start = std::chrono::steady_clock::now(); |
73 | | - |
| 70 | + MessageHelper messageHelper(m_MessageHandler); |
| 71 | + ThrottledMessenger throttledMessenger = messageHelper.createThrottledMessenger(); |
| 72 | + |
74 | 73 | for(usize parentIdx = 1; parentIdx < numParents; parentIdx++) |
75 | 74 | { |
76 | | - progInt = static_cast<float>(parentIdx) / static_cast<float>(numParents) * 100.0f; |
77 | | - auto now = std::chrono::steady_clock::now(); |
78 | | - // Only send updates every 1 second |
79 | | - if(std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count() > 1000) |
80 | | - { |
81 | | - currentParentId = parentIdx; |
82 | | - auto totalParentIds = currentParentId - prevParentId; |
83 | | - auto rate = static_cast<float>(totalParentIds) / static_cast<float>(std::chrono::duration_cast<std::chrono::seconds>(now - start).count()); |
| 75 | + throttledMessenger.sendThrottledMessage([&]() { return fmt::format("[{}%]", CalculatePercentComplete(parentIdx, numParents)); }); |
84 | 76 |
|
85 | | - auto remainingParents = numParents - parentIdx; |
86 | | - auto minutesRemain = (remainingParents / rate) / 60; // Convert to minutes |
87 | | - |
88 | | - std::string message = fmt::format("{}/{} [{}%] at {} parents/sec. Time Remain: {:.2f} Minutes", parentIdx, numParents, progInt, rate, minutesRemain); |
89 | | - m_MessageHandler(nx::core::IFilter::ProgressMessage{nx::core::IFilter::Message::Type::Info, message, progInt}); |
90 | | - start = std::chrono::steady_clock::now(); |
91 | | - prevParentId = currentParentId; |
92 | | - } |
93 | 77 | if(m_ShouldCancel) |
94 | 78 | { |
95 | 79 | return {}; |
|
0 commit comments