mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-28 07:54:49 +03:00
better time prediction
This commit is contained in:
parent
1509c4ffba
commit
5310a3cc1d
2 changed files with 13 additions and 10 deletions
|
@ -47,13 +47,13 @@ namespace Progress
|
||||||
struct EtaEstimate {
|
struct EtaEstimate {
|
||||||
EtaEstimate() : _startedTime(QDateTime::currentMSecsSinceEpoch()), _agvEtaMSecs(0),_effectivProgressPerSec(0),_sampleCount(1) {}
|
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;
|
static const int INITAL_WAIT_TIME=5;
|
||||||
|
|
||||||
quint64 _startedTime ;
|
quint64 _startedTime ;
|
||||||
quint64 _agvEtaMSecs;
|
quint64 _agvEtaMSecs;
|
||||||
quint64 _effectivProgressPerSec;
|
quint64 _effectivProgressPerSec;
|
||||||
quint16 _sampleCount;
|
float _sampleCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reset the estiamte.
|
* reset the estiamte.
|
||||||
|
@ -73,7 +73,7 @@ namespace Progress
|
||||||
quint64 elapsedTime = QDateTime::currentMSecsSinceEpoch() - this->_startedTime ;
|
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
|
//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(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....)
|
// (elapsedTime-1) is an hack to avoid float "rounding" issue (ie. 0.99999999999999999999....)
|
||||||
_agvEtaMSecs = _agvEtaMSecs + (((static_cast<float>(total) / completed) * elapsedTime) - (elapsedTime-1)) - this->getEtaEstimate();
|
_agvEtaMSecs = _agvEtaMSecs + (((static_cast<float>(total) / completed) * elapsedTime) - (elapsedTime-1)) - this->getEtaEstimate();
|
||||||
_effectivProgressPerSec = ( total - completed ) / (1+this->getEtaEstimate()/1000);
|
_effectivProgressPerSec = ( total - completed ) / (1+this->getEtaEstimate()/1000);
|
||||||
|
|
|
@ -454,14 +454,17 @@ qint64 Utility::qDateTimeToTime_t(const QDateTime& t)
|
||||||
|
|
||||||
QString Utility::timeToDescriptiveString(quint64 msecs)
|
QString Utility::timeToDescriptiveString(quint64 msecs)
|
||||||
{
|
{
|
||||||
QList<QPair<QString,quint32> > timeMapping = QList<QPair<QString,quint32> >();
|
//TODO change to initializers list when possible.
|
||||||
timeMapping.append(QPair<QString,quint32>("years",86400*365));
|
static QList<QPair<QString,quint32> > timeMapping = QList<QPair<QString,quint32> >() <<
|
||||||
timeMapping.append(QPair<QString,quint32>("months",86400*30));
|
QPair<QString,quint32>("years",86400*365) <<
|
||||||
timeMapping.append(QPair<QString,quint32>("days",86400));
|
QPair<QString,quint32>("months",86400*30) <<
|
||||||
timeMapping.append(QPair<QString,quint32>("hours",3600));
|
QPair<QString,quint32>("days",86400) <<
|
||||||
timeMapping.append(QPair<QString,quint32>("minutes",60));
|
QPair<QString,quint32>("hours",3600) <<
|
||||||
timeMapping.append(QPair<QString,quint32>("seconds",1));
|
QPair<QString,quint32>("minutes",60) <<
|
||||||
|
QPair<QString,quint32>("seconds",1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return timeToDescriptiveString(timeMapping, msecs, 1);
|
return timeToDescriptiveString(timeMapping, msecs, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue