forked from GerhardHoffmann/DCLibraries
run(): improve on output sent to GUI of ATBUpdateTool.
This commit is contained in:
parent
35f7d56c2a
commit
544bab4332
@ -8,6 +8,7 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
ReportingThread::ReportingThread(hwapi *hw)
|
ReportingThread::ReportingThread(hwapi *hw)
|
||||||
: m_hw(hw)
|
: m_hw(hw)
|
||||||
@ -99,14 +100,27 @@ void ReportingThread::run() {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint16_t const totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
|
uint16_t totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
|
||||||
|
cnt = 10;
|
||||||
|
while(--cnt > 0 && totalBlocks == 0) {
|
||||||
|
totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
|
||||||
|
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
|
||||||
|
<< QString("line=%1 TOTAL BLOCKS=%2 (%3)")
|
||||||
|
.arg(__LINE__).arg(totalBlocks).arg(cnt);
|
||||||
|
QThread::sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
|
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << __PRETTY_FUNCTION__
|
||||||
|
<< QString("line=%1 TOTAL BLOCKS=%2").arg(__LINE__).arg(totalBlocks);
|
||||||
|
|
||||||
if (totalBlocks) {
|
if (totalBlocks) {
|
||||||
QDateTime const start = QDateTime::currentDateTime();
|
QDateTime const start = QDateTime::currentDateTime();
|
||||||
uint16_t currentBlockNumber = 0;
|
uint16_t currentBlockNumber = 0;
|
||||||
uint16_t prevBlockNumber = ~0;
|
uint16_t prevBlockNumber = ~0;
|
||||||
|
uint64_t estimatedMinutesLeftMax = ~0ULL;
|
||||||
|
uint64_t estimatedSecondsLeftMax = ~0ULL;
|
||||||
|
uint64_t estimatedMinutesLeftPrev = 0;
|
||||||
|
uint64_t estimatedSecondsLeftPrev = 0;
|
||||||
|
|
||||||
while (m_hw->dcDownloadGetRunning()) {
|
while (m_hw->dcDownloadGetRunning()) {
|
||||||
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
|
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||||
@ -114,24 +128,48 @@ void ReportingThread::run() {
|
|||||||
double durationSecs = start.secsTo(QDateTime::currentDateTime());
|
double durationSecs = start.secsTo(QDateTime::currentDateTime());
|
||||||
|
|
||||||
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs;
|
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs;
|
||||||
long estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber)));
|
uint64_t estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber)));
|
||||||
long estimatedMinutesLeft =
|
uint64_t estimatedMinutesLeft =
|
||||||
((estimatedSecondsLeft % 60) == 0) ?
|
((estimatedSecondsLeft % 60) == 0) ?
|
||||||
(estimatedSecondsLeft / 60) :
|
(estimatedSecondsLeft / 60) :
|
||||||
((estimatedSecondsLeft + 60) / 60);
|
((estimatedSecondsLeft + 60) / 60);
|
||||||
|
|
||||||
estimatedSecondsLeft = (estimatedSecondsLeft % 60);
|
estimatedSecondsLeft = (estimatedSecondsLeft % 60);
|
||||||
|
|
||||||
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
|
if ((estimatedMinutesLeft <= estimatedMinutesLeftMax)
|
||||||
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
|
|| (estimatedSecondsLeft <= estimatedSecondsLeftMax)) {
|
||||||
.arg(totalBlocks)
|
estimatedMinutesLeftMax = estimatedMinutesLeft;
|
||||||
.arg(currentBlockNumber)
|
estimatedSecondsLeftMax = estimatedSecondsLeft;
|
||||||
.arg(percent, 0, 'f', 2)
|
estimatedMinutesLeftPrev = estimatedMinutesLeft;
|
||||||
.arg(estimatedMinutesLeft)
|
estimatedSecondsLeftPrev = estimatedSecondsLeft;
|
||||||
.arg(estimatedSecondsLeft, 2);
|
|
||||||
|
|
||||||
qCritical() << m_hw << "RT report" << report;
|
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);
|
||||||
|
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
|
||||||
|
<< QString("line=%1: RT report").arg(__LINE__) << report;
|
||||||
|
|
||||||
|
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
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(estimatedMinutesLeftPrev)
|
||||||
|
.arg(estimatedSecondsLeftPrev, 2);
|
||||||
|
|
||||||
|
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
|
||||||
|
<< QString("line=%1: RT report").arg(__LINE__) << report;
|
||||||
|
|
||||||
|
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||||
|
}
|
||||||
|
|
||||||
prevBlockNumber = currentBlockNumber;
|
prevBlockNumber = currentBlockNumber;
|
||||||
}
|
}
|
||||||
@ -150,7 +188,7 @@ void ReportingThread::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
|
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << __PRETTY_FUNCTION__
|
||||||
<< QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__);
|
<< QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__);
|
||||||
|
|
||||||
cnt = 10;
|
cnt = 10;
|
||||||
|
Loading…
Reference in New Issue
Block a user