Make SpeedPlotView averager time aware

Previously SpeedPlotView assumed speed is updated per second but the
default value was 1500ms and that can be further changed by the
user, this caused a lot of duplicate data in the calculation of the
graph points. Now Averager averages based on the target duration, resolution
and also takes into account when actually data has arrived.

Also improved resolution of 6-hour graph, previously it was same as 12-hour graph
This commit is contained in:
jagannatharjun
2020-12-26 21:51:23 +05:30
parent d7fb2e6403
commit c8979a6a49
3 changed files with 150 additions and 145 deletions

View File

@@ -109,16 +109,13 @@ SpeedWidget::SpeedWidget(PropertiesWidget *parent)
m_hlayout->addWidget(m_graphsButton);
m_plot = new SpeedPlotView(this);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated, this, &SpeedWidget::update);
m_layout->addLayout(m_hlayout);
m_layout->addWidget(m_plot);
loadSettings();
QTimer *localUpdateTimer = new QTimer(this);
connect(localUpdateTimer, &QTimer::timeout, this, &SpeedWidget::update);
localUpdateTimer->start(1000);
m_plot->show();
}
@@ -133,21 +130,19 @@ void SpeedWidget::update()
{
const BitTorrent::SessionStatus &btStatus = BitTorrent::Session::instance()->status();
SpeedPlotView::PointData point;
point.x = QDateTime::currentMSecsSinceEpoch() / 1000;
point.y[SpeedPlotView::UP] = btStatus.uploadRate;
point.y[SpeedPlotView::DOWN] = btStatus.downloadRate;
point.y[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate;
point.y[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate;
point.y[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate;
point.y[SpeedPlotView::OVERHEAD_DOWN] = btStatus.ipOverheadDownloadRate;
point.y[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate;
point.y[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate;
point.y[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate;
point.y[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate;
SpeedPlotView::SampleData sampleData;
sampleData[SpeedPlotView::UP] = btStatus.uploadRate;
sampleData[SpeedPlotView::DOWN] = btStatus.downloadRate;
sampleData[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate;
sampleData[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate;
sampleData[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate;
sampleData[SpeedPlotView::OVERHEAD_DOWN] = btStatus.ipOverheadDownloadRate;
sampleData[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate;
sampleData[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate;
sampleData[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate;
sampleData[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate;
m_plot->pushPoint(point);
m_plot->replot();
m_plot->pushPoint(sampleData);
}
void SpeedWidget::onPeriodChange(int period)