|
|
@ -36,11 +36,68 @@ |
|
|
|
|
|
|
|
|
|
|
|
using namespace libtorrent; |
|
|
|
using namespace libtorrent; |
|
|
|
|
|
|
|
|
|
|
|
template<class T> struct Sample { |
|
|
|
namespace { |
|
|
|
Sample(const T down = 0, const T up = 0) : download(down), upload(up) {} |
|
|
|
|
|
|
|
T download; |
|
|
|
template<class T> struct Sample { |
|
|
|
T upload; |
|
|
|
Sample() |
|
|
|
}; |
|
|
|
: download() |
|
|
|
|
|
|
|
, upload() |
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sample(T download, T upload) |
|
|
|
|
|
|
|
: download(download) |
|
|
|
|
|
|
|
, upload(upload) |
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename U> |
|
|
|
|
|
|
|
explicit Sample(Sample<U> other) |
|
|
|
|
|
|
|
: download(static_cast<U>(other.download)) |
|
|
|
|
|
|
|
, upload(static_cast<U>(other.upload)) |
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T download; |
|
|
|
|
|
|
|
T upload; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T>& operator+=(Sample<T>& lhs, Sample<T> const& rhs) { |
|
|
|
|
|
|
|
lhs.download += rhs.download; |
|
|
|
|
|
|
|
lhs.upload += rhs.upload; |
|
|
|
|
|
|
|
return lhs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T>& operator-=(Sample<T>& lhs, Sample<T> const& rhs) { |
|
|
|
|
|
|
|
lhs.download -= rhs.download; |
|
|
|
|
|
|
|
lhs.upload -= rhs.upload; |
|
|
|
|
|
|
|
return lhs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T> operator+(Sample<T> const& lhs, Sample<T> const& rhs) { |
|
|
|
|
|
|
|
return Sample<T>(lhs.download + rhs.download, lhs.upload + rhs.upload); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T> operator-(Sample<T> const& lhs, Sample<T> const& rhs) { |
|
|
|
|
|
|
|
return Sample<T>(lhs.download - rhs.download, lhs.upload - rhs.upload); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T> operator*(Sample<T> const& lhs, T rhs) { |
|
|
|
|
|
|
|
return Sample<T>(lhs.download * rhs, lhs.upload * rhs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T> operator*(T lhs,Sample<T> const& rhs) { |
|
|
|
|
|
|
|
return Sample<T>(lhs * rhs.download, lhs * rhs.upload); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
Sample<T> operator/(Sample<T> const& lhs, T rhs) { |
|
|
|
|
|
|
|
return Sample<T>(lhs.download / rhs, lhs.upload / rhs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class SpeedSample { |
|
|
|
class SpeedSample { |
|
|
|
|
|
|
|
|
|
|
@ -79,16 +136,13 @@ Sample<qreal> SpeedSample::average() const |
|
|
|
if (m_speedSamples.empty()) |
|
|
|
if (m_speedSamples.empty()) |
|
|
|
return Sample<qreal>(); |
|
|
|
return Sample<qreal>(); |
|
|
|
|
|
|
|
|
|
|
|
qlonglong sumDL = 0; |
|
|
|
Sample<qlonglong> sum; |
|
|
|
qlonglong sumUL = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (const Sample<int>& s, m_speedSamples) { |
|
|
|
foreach (const Sample<int>& s, m_speedSamples) { |
|
|
|
sumDL += s.download; |
|
|
|
sum += Sample<qlonglong>(s); |
|
|
|
sumUL += s.upload; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const qreal numSamples = m_speedSamples.size(); |
|
|
|
return Sample<qreal>(sum) * (1. / m_speedSamples.size()); |
|
|
|
return Sample<qreal>(sumDL/numSamples, sumUL/numSamples); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TorrentSpeedMonitor::removeSamples(const QString &hash) |
|
|
|
void TorrentSpeedMonitor::removeSamples(const QString &hash) |
|
|
|