mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 19:40:18 -07:00
- Optimized function that transform a number of seconds to a duration(days, hours, minutes, secs)
- Improved ETA calculation to avoid overflows (Added asserts to make sure it doesn't happen)
This commit is contained in:
parent
105563ac5a
commit
21908e0a03
5 changed files with 42 additions and 30 deletions
|
@ -112,19 +112,22 @@ void bittorrent::updateETAs() {
|
|||
QTorrentHandle h = handles[i];
|
||||
if(h.is_valid()) {
|
||||
QString hash = h.hash();
|
||||
QList<long> listEtas = ETAstats.value(hash, QList<long>());
|
||||
QList<qlonglong> listEtas = ETAstats.value(hash, QList<qlonglong>());
|
||||
if(listEtas.size() == ETAS_MAX_VALUES) {
|
||||
listEtas.removeFirst();
|
||||
}
|
||||
if(h.download_payload_rate() != 0) {
|
||||
listEtas << (long)((h.total_size()-h.total_done())/(double)h.download_payload_rate());
|
||||
if(h.download_payload_rate()) {
|
||||
listEtas << (qlonglong)((h.total_size()-h.total_done())/(double)h.download_payload_rate());
|
||||
ETAstats[hash] = listEtas;
|
||||
long moy = 0;
|
||||
long val;
|
||||
unsigned int nbETAs = listEtas.size();
|
||||
Q_ASSERT(nbETAs);
|
||||
foreach(val, listEtas) {
|
||||
moy += val;
|
||||
moy += (qlonglong)((double)val/(double)nbETAs);
|
||||
Q_ASSERT(moy >= 0);
|
||||
}
|
||||
ETAs[hash] = (long) ((double)moy/(double)listEtas.size());
|
||||
ETAs[hash] = moy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue