forked from GerhardHoffmann/DCLibraries
Use actually reporting coe, not just some test code.
This commit is contained in:
parent
a1237749dc
commit
f6efb1ee9a
@ -4,10 +4,15 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user