#include "mining_tab_helpers.h" #include #include #include namespace dragonx { namespace ui { int GetMaxMiningThreads() { int hardwareThreads = static_cast(std::thread::hardware_concurrency()); return std::max(1, hardwareThreads); } int ClampMiningThreads(int requestedThreads, int maxThreads) { int boundedMax = std::max(1, maxThreads); return std::clamp(requestedThreads, 1, boundedMax); } bool IsPoolMiningActive(bool poolMode, bool xmrigRunning, bool soloMiningRunning) { return poolMode ? xmrigRunning : (soloMiningRunning || xmrigRunning); } std::string FormatHashrate(double hashrate) { char buffer[64]; if (hashrate >= 1e12) { snprintf(buffer, sizeof(buffer), "%.2f TH/s", hashrate / 1e12); } else if (hashrate >= 1e9) { snprintf(buffer, sizeof(buffer), "%.2f GH/s", hashrate / 1e9); } else if (hashrate >= 1e6) { snprintf(buffer, sizeof(buffer), "%.2f MH/s", hashrate / 1e6); } else if (hashrate >= 1e3) { snprintf(buffer, sizeof(buffer), "%.2f KH/s", hashrate / 1e3); } else { snprintf(buffer, sizeof(buffer), "%.2f H/s", hashrate); } return std::string(buffer); } double EstimateHoursToBlock(double localHashrate, double networkHashrate, double difficulty) { (void)difficulty; if (localHashrate <= 0.0 || networkHashrate <= 0.0) return 0.0; double blocksPerHour = 3600.0 / 75.0; double share = localHashrate / networkHashrate; if (share <= 0.0) return 0.0; return 1.0 / (blocksPerHour * share); } std::string FormatEstTime(double estimatedHours) { char buffer[64]; if (estimatedHours <= 0.0) { return "N/A"; } else if (estimatedHours < 1.0) { snprintf(buffer, sizeof(buffer), "~%.0f min", estimatedHours * 60.0); } else if (estimatedHours < 24.0) { snprintf(buffer, sizeof(buffer), "~%.1f hrs", estimatedHours); } else if (estimatedHours < 168.0) { snprintf(buffer, sizeof(buffer), "~%.1f days", estimatedHours / 24.0); } else { snprintf(buffer, sizeof(buffer), "~%.1f weeks", estimatedHours / 168.0); } return std::string(buffer); } } // namespace ui } // namespace dragonx