From 5310a3cc1dae2ca3956f6530f1a07cd5ee24710f Mon Sep 17 00:00:00 2001 From: Eran Date: Wed, 14 May 2014 16:57:14 +0300 Subject: [PATCH] better time prediction --- src/mirall/progressdispatcher.h | 6 +++--- src/mirall/utility.cpp | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mirall/progressdispatcher.h b/src/mirall/progressdispatcher.h index 198b03910..64baabf26 100644 --- a/src/mirall/progressdispatcher.h +++ b/src/mirall/progressdispatcher.h @@ -47,13 +47,13 @@ namespace Progress struct EtaEstimate { EtaEstimate() : _startedTime(QDateTime::currentMSecsSinceEpoch()), _agvEtaMSecs(0),_effectivProgressPerSec(0),_sampleCount(1) {} - static const int MAX_AVG_DIVIDER=120; + static const int MAX_AVG_DIVIDER=60; static const int INITAL_WAIT_TIME=5; quint64 _startedTime ; quint64 _agvEtaMSecs; quint64 _effectivProgressPerSec; - quint16 _sampleCount; + float _sampleCount; /** * reset the estiamte. @@ -73,7 +73,7 @@ namespace Progress quint64 elapsedTime = QDateTime::currentMSecsSinceEpoch() - this->_startedTime ; //don't start until you have some good data to process, prevents jittring estiamtes at the start of the syncing process if(total != 0 && completed != 0 && elapsedTime > INITAL_WAIT_TIME ) { - if(_sampleCount < MAX_AVG_DIVIDER) { _sampleCount++; } + if(_sampleCount < MAX_AVG_DIVIDER) { _sampleCount+=0.01f; } // (elapsedTime-1) is an hack to avoid float "rounding" issue (ie. 0.99999999999999999999....) _agvEtaMSecs = _agvEtaMSecs + (((static_cast(total) / completed) * elapsedTime) - (elapsedTime-1)) - this->getEtaEstimate(); _effectivProgressPerSec = ( total - completed ) / (1+this->getEtaEstimate()/1000); diff --git a/src/mirall/utility.cpp b/src/mirall/utility.cpp index f4a58e073..4557edfdf 100644 --- a/src/mirall/utility.cpp +++ b/src/mirall/utility.cpp @@ -454,14 +454,17 @@ qint64 Utility::qDateTimeToTime_t(const QDateTime& t) QString Utility::timeToDescriptiveString(quint64 msecs) { - QList > timeMapping = QList >(); - timeMapping.append(QPair("years",86400*365)); - timeMapping.append(QPair("months",86400*30)); - timeMapping.append(QPair("days",86400)); - timeMapping.append(QPair("hours",3600)); - timeMapping.append(QPair("minutes",60)); - timeMapping.append(QPair("seconds",1)); + //TODO change to initializers list when possible. + static QList > timeMapping = QList >() << + QPair("years",86400*365) << + QPair("months",86400*30) << + QPair("days",86400) << + QPair("hours",3600) << + QPair("minutes",60) << + QPair("seconds",1); + + return timeToDescriptiveString(timeMapping, msecs, 1); }