Skip to content

Commit

Permalink
Merge pull request #235 from meritlabs/bug/fix-download-estimate
Browse files Browse the repository at this point in the history
Fix computation of download estimate.
  • Loading branch information
ferrerrajc authored Feb 12, 2018
2 parents 29bf6f3 + 707b81b commit 52cbfd2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/qt/forms/modaloverlay.ui
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ QLabel { color: rgb(40,40,40); }</string>
</font>
</property>
<property name="text">
<string>Progress increase per hour</string>
<string>Blocks Per Hour</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="progressIncreasePerH">
<widget class="QLabel" name="blocksPerH">
<property name="text">
<string>calculating...</string>
</property>
Expand Down
44 changes: 24 additions & 20 deletions src/qt/modaloverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ModalOverlay::ModalOverlay(QWidget *parent) :
raise();
}

blockProcessTime.clear();
block_time_samples.clear();
setVisible(false);
}

Expand Down Expand Up @@ -81,6 +81,7 @@ void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate)
void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate)
{
QDateTime currentDate = QDateTime::currentDateTime();
setKnownBestHeight(count, blockDate);

//We want to change progress text if importing so the
//user knows we are in reindexing stage.
Expand All @@ -98,28 +99,31 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate)
// keep a vector of samples of verification progress at height
double verificationProgress = bestHeaderHeight == 0 ? 0 :
static_cast<double>(count) / static_cast<double>(bestHeaderHeight);
qint64 currentMillis = currentDate.toMSecsSinceEpoch();
blockProcessTime.push_front(qMakePair(currentMillis, verificationProgress));

qint64 current_millis = currentDate.toMSecsSinceEpoch();
block_time_samples.push_front(qMakePair(current_millis, count));

// show progress speed if we have more then one sample
if (blockProcessTime.size() == AVG_WINDOW_LENGTH)
if (block_time_samples.size() == AVG_WINDOW_LENGTH)
{
double progressDelta = 0;
double progressPerHour = 0;
qint64 timeDelta = 0;
qint64 remainingMSecs = 0;

QPair<qint64, double> sample = blockProcessTime.takeLast();
timeDelta = currentMillis - sample.first;
progressDelta = verificationProgress - sample.second;
progressPerHour = progressDelta/static_cast<double>(timeDelta)*1000*3600;
remainingMSecs = (bestHeaderHeight - count) * timeDelta / AVG_WINDOW_LENGTH;

// show progress increase per hour
ui->progressIncreasePerH->setText(QString::number(progressPerHour*100, 'f', 2)+"%");

// show expected remaining time
ui->expectedTimeLeft->setText(GUIUtil::formatNiceTimeOffset(remainingMSecs/1000));
qint64 time_delta = 0;
qint64 remaining_msecs = 0;

QPair<qint64, double> sample = block_time_samples.takeLast();
time_delta = current_millis - sample.first;

const int blocks_delta = count - sample.second;
if(blocks_delta >= 0) {

const int blocks_per_hour = static_cast<int>(blocks_delta/static_cast<double>(time_delta)*1000*3600);
remaining_msecs = (bestHeaderHeight - count) * time_delta / blocks_delta;

// show progress increase per hour
ui->blocksPerH->setText(QString::number(blocks_per_hour)+tr(" (blocks/h)"));

// show expected remaining time
ui->expectedTimeLeft->setText(GUIUtil::formatNiceTimeOffset(remaining_msecs/1000));
}
}

// show the last block date
Expand Down
2 changes: 1 addition & 1 deletion src/qt/modaloverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Q_SLOTS:
Ui::ModalOverlay *ui;
int bestHeaderHeight; //best known height (based on the headers)
QDateTime bestHeaderDate;
QVector<QPair<qint64, double> > blockProcessTime;
QVector<QPair<qint64, int> > block_time_samples;
bool layerIsVisible;
bool userClosed;
};
Expand Down

0 comments on commit 52cbfd2

Please sign in to comment.