mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
1fd456833c
|
@ -137,13 +137,14 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
|
|||
qreal bytesPerSec = static_cast<int>(static_cast<qreal>(deltaBytes) / deltaSecs);
|
||||
|
||||
// calculate mean
|
||||
meanData[(meanIndex++) % FTW_MEAN_PERIODES] = bytesPerSec;
|
||||
meanData[meanIndex] = bytesPerSec;
|
||||
meanIndex = (meanIndex + 1) % TRANSFER_ROLLING_AVG_COUNT;
|
||||
|
||||
qreal meanBytesPerSec = 0.0;
|
||||
for(size_t i = 0; i < FTW_MEAN_PERIODES; ++i)
|
||||
for(size_t i = 0; i < TRANSFER_ROLLING_AVG_COUNT; ++i)
|
||||
meanBytesPerSec += meanData[i];
|
||||
|
||||
meanBytesPerSec /= qMin(meanIndex, static_cast<size_t>(FTW_MEAN_PERIODES));
|
||||
meanBytesPerSec /= qMin(static_cast<size_t>(meanIndex), static_cast<size_t>(TRANSFER_ROLLING_AVG_COUNT));
|
||||
|
||||
// update UI
|
||||
if(meanBytesPerSec > 0)
|
||||
|
@ -209,7 +210,7 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
|
|||
|
||||
// reset mean
|
||||
meanIndex = 0;
|
||||
for(size_t i=0; i<FTW_MEAN_PERIODES; ++i)
|
||||
for(size_t i=0; i<TRANSFER_ROLLING_AVG_COUNT; ++i)
|
||||
meanData[i] = 0.0;
|
||||
|
||||
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/grey.css"));
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "../chatlinecontent.h"
|
||||
#include "../../corestructs.h"
|
||||
|
||||
#define FTW_MEAN_PERIODES 4
|
||||
|
||||
namespace Ui {
|
||||
class FileTransferWidget;
|
||||
|
@ -66,8 +65,9 @@ private:
|
|||
QTime lastTick;
|
||||
qint64 lastBytesSent = 0;
|
||||
|
||||
qreal meanData[FTW_MEAN_PERIODES] = {0.0};
|
||||
size_t meanIndex = 0;
|
||||
static const uint8_t TRANSFER_ROLLING_AVG_COUNT = 4;
|
||||
uint8_t meanIndex = 0;
|
||||
qreal meanData[TRANSFER_ROLLING_AVG_COUNT] = {0.0};
|
||||
};
|
||||
|
||||
#endif // FILETRANSFERWIDGET_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user