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 <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
ReportingThread::ReportingThread(hwapi *hw)
|
ReportingThread::ReportingThread(hwapi *hw)
|
||||||
: m_hw(hw)
|
: m_hw(hw)
|
||||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||||
|
// , m_f([](QString const&){}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportingThread::~ReportingThread() {
|
ReportingThread::~ReportingThread() {
|
||||||
@ -17,7 +22,9 @@ ReportingThread::~ReportingThread() {
|
|||||||
// each component which has connects for the corresponding signals.
|
// each component which has connects for the corresponding signals.
|
||||||
void ReportingThread::run() {
|
void ReportingThread::run() {
|
||||||
|
|
||||||
qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
|
qCritical()
|
||||||
|
<< QDateTime::currentDateTime() << "START REPORT THREAD"
|
||||||
|
<< "(PART OF APPLICATION" << QCoreApplication::applicationName() << ")";
|
||||||
|
|
||||||
static QString report("");
|
static QString report("");
|
||||||
|
|
||||||
@ -96,28 +103,37 @@ void ReportingThread::run() {
|
|||||||
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
|
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
|
||||||
|
|
||||||
if (totalBlocks) {
|
if (totalBlocks) {
|
||||||
qint64 const start = QDateTime::currentMSecsSinceEpoch();
|
QDateTime const start = QDateTime::currentDateTime();
|
||||||
double durationMillis = 0;
|
|
||||||
uint16_t currentBlockNumber = 0;
|
uint16_t currentBlockNumber = 0;
|
||||||
|
uint16_t prevBlockNumber = ~0;
|
||||||
|
|
||||||
while (m_hw->dcDownloadGetRunning()) {
|
while (m_hw->dcDownloadGetRunning()) {
|
||||||
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
|
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)));
|
||||||
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationMillis / currentBlockNumber) : durationMillis;
|
long estimatedMinutesLeft =
|
||||||
double const estimatedSecondsLeft = (timeAveragePerBlock * (totalBlocks - currentBlockNumber)) / 1000.0;
|
((estimatedSecondsLeft % 60) == 0) ?
|
||||||
|
(estimatedSecondsLeft / 60) :
|
||||||
|
((estimatedSecondsLeft + 60) / 60);
|
||||||
|
estimatedSecondsLeft = (estimatedSecondsLeft % 60);
|
||||||
|
|
||||||
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
|
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
|
||||||
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4s)")
|
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
|
||||||
.arg(totalBlocks)
|
.arg(totalBlocks)
|
||||||
.arg(currentBlockNumber)
|
.arg(currentBlockNumber)
|
||||||
.arg(percent, 0, 'f', 2)
|
.arg(percent, 0, 'f', 2)
|
||||||
.arg(estimatedSecondsLeft, 0, 'f', 2);
|
.arg(estimatedMinutesLeft)
|
||||||
|
.arg(estimatedSecondsLeft, 2);
|
||||||
|
|
||||||
qCritical() << "RT report" << report;
|
qCritical() << m_hw << "RT report" << report;
|
||||||
|
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||||
|
|
||||||
|
prevBlockNumber = currentBlockNumber;
|
||||||
|
}
|
||||||
QThread::msleep(100);
|
QThread::msleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user