From f6efb1ee9ac141449b5ef5249bb3da5febd2a752 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 2 Feb 2024 13:31:32 +0100 Subject: [PATCH] Use actually reporting coe, not just some test code. --- src/reporting_thread.cpp | 44 +++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/reporting_thread.cpp b/src/reporting_thread.cpp index e27e44a..d26a653 100644 --- a/src/reporting_thread.cpp +++ b/src/reporting_thread.cpp @@ -4,10 +4,15 @@ #include #include +#include +#include + +#include ReportingThread::ReportingThread(hwapi *hw) : m_hw(hw) , m_fileToDownload(m_hw->dcDownloadFileName()) { + // , m_f([](QString const&){}) { } ReportingThread::~ReportingThread() { @@ -17,7 +22,9 @@ ReportingThread::~ReportingThread() { // each component which has connects for the corresponding signals. void ReportingThread::run() { - qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD"; + qCritical() + << QDateTime::currentDateTime() << "START REPORT THREAD" + << "(PART OF APPLICATION" << QCoreApplication::applicationName() << ")"; static QString report(""); @@ -96,28 +103,37 @@ void ReportingThread::run() { qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks; if (totalBlocks) { - qint64 const start = QDateTime::currentMSecsSinceEpoch(); - double durationMillis = 0; + QDateTime const start = QDateTime::currentDateTime(); uint16_t currentBlockNumber = 0; + uint16_t prevBlockNumber = ~0; while (m_hw->dcDownloadGetRunning()) { currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber(); + if (prevBlockNumber != currentBlockNumber) { + double durationSecs = start.secsTo(QDateTime::currentDateTime()); - durationMillis += QDateTime::currentMSecsSinceEpoch() - start; + double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs; + long estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber))); + long estimatedMinutesLeft = + ((estimatedSecondsLeft % 60) == 0) ? + (estimatedSecondsLeft / 60) : + ((estimatedSecondsLeft + 60) / 60); + estimatedSecondsLeft = (estimatedSecondsLeft % 60); - double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationMillis / currentBlockNumber) : durationMillis; - double const estimatedSecondsLeft = (timeAveragePerBlock * (totalBlocks - currentBlockNumber)) / 1000.0; + double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0; + report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)") + .arg(totalBlocks) + .arg(currentBlockNumber) + .arg(percent, 0, 'f', 2) + .arg(estimatedMinutesLeft) + .arg(estimatedSecondsLeft, 2); - double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0; - report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4s)") - .arg(totalBlocks) - .arg(currentBlockNumber) - .arg(percent, 0, 'f', 2) - .arg(estimatedSecondsLeft, 0, 'f', 2); + qCritical() << m_hw << "RT report" << report; - qCritical() << "RT report" << report; + emit m_hw->hwapi_reportDCDownloadStatus(report); - emit m_hw->hwapi_reportDCDownloadStatus(report); + prevBlockNumber = currentBlockNumber; + } QThread::msleep(100); }