diff options
| -rw-r--r-- | src/downloadmanager.cpp | 31 | ||||
| -rw-r--r-- | src/downloadmanager.h | 14 | ||||
| -rw-r--r-- | src/organizer_en.ts | 124 |
3 files changed, 102 insertions, 67 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 1b097bdb..67086d01 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -942,11 +942,10 @@ void DownloadManager::resumeDownloadInt(int index) QByteArray rangeHeader = "bytes=" + QByteArray::number(info->m_ResumePos) + "-"; request.setRawHeader("Range", rangeHeader); } - std::get<0>(info->m_SpeedDiff) = 0; - std::get<1>(info->m_SpeedDiff) = 0; - std::get<2>(info->m_SpeedDiff) = 0; - std::get<3>(info->m_SpeedDiff) = 0; - std::get<4>(info->m_SpeedDiff) = 0; + info->m_DownloadLast = 0; + info->m_DownloadTimeLast = 0; + info->m_DownloadAcc = accumulator_set<int, stats<tag::rolling_mean>>(tag::rolling_window::window_size = 500); + info->m_DownloadTimeAcc = accumulator_set<int, stats<tag::rolling_mean>>(tag::rolling_window::window_size = 500); log::debug("resume at {} bytes", info->m_ResumePos); startDownload(m_NexusInterface->getAccessManager()->get(request), info, true); } @@ -1568,20 +1567,20 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) info->m_Progress.first = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal); int elapsed = info->m_StartTime.elapsed(); - std::get<0>(info->m_SpeedDiff) = bytesReceived - std::get<2>(info->m_SpeedDiff); - std::get<1>(info->m_SpeedDiff) = elapsed - std::get<3>(info->m_SpeedDiff); - std::get<2>(info->m_SpeedDiff) = bytesReceived; - std::get<3>(info->m_SpeedDiff) = elapsed; - - double calc = ((double)std::get<0>(info->m_SpeedDiff)) / (((double)(std::get<1>(info->m_SpeedDiff)) / 5000.0)); - std::get<4>(info->m_SpeedDiff) = ((calc*0.5) + (std::get<4>(info->m_SpeedDiff)*1.5)) / 2; + info->m_DownloadAcc(bytesReceived - info->m_DownloadLast); + info->m_DownloadLast = bytesReceived; + info->m_DownloadTimeAcc(elapsed - info->m_DownloadTimeLast); + info->m_DownloadTimeLast = elapsed; // calculate the download speed - const double speed = (std::get<4>(info->m_SpeedDiff) * 1000.0) / (5 * 1000); + const double speed = rolling_mean(info->m_DownloadAcc) / (rolling_mean(info->m_DownloadTimeAcc) / 1000.0);; + + const int remaining = (bytesTotal - bytesReceived) / speed * 1000; - info->m_Progress.second = QString::fromLatin1("%1% - %2") + info->m_Progress.second = tr("%1% - %2 - ~%3") .arg(info->m_Progress.first) - .arg(MOBase::localizedByteSpeed(speed)); + .arg(MOBase::localizedByteSpeed(speed)) + .arg(MOBase::localizedTimeRemaining(remaining)); TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal); emit update(index); @@ -2227,7 +2226,7 @@ void DownloadManager::managedGameChanged(MOBase::IPluginGame const *managedGame) void DownloadManager::checkDownloadTimeout() { for (int i = 0; i < m_ActiveDownloads.size(); ++i) { - if (m_ActiveDownloads[i]->m_StartTime.elapsed() - std::get<3>(m_ActiveDownloads[i]->m_SpeedDiff) > 5 * 1000 && + if (m_ActiveDownloads[i]->m_StartTime.elapsed() - m_ActiveDownloads[i]->m_DownloadTimeLast > 5 * 1000 && m_ActiveDownloads[i]->m_State == STATE_DOWNLOADING && m_ActiveDownloads[i]->m_Reply != nullptr && m_ActiveDownloads[i]->m_Reply->isOpen()) { pauseDownload(i); diff --git a/src/downloadmanager.h b/src/downloadmanager.h index ba9f4b5c..86dc17b9 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -38,6 +38,10 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QFileSystemWatcher> #include <QSettings> #include <boost/signals2.hpp> +#include <boost/accumulators/accumulators.hpp> +#include <boost/accumulators/statistics.hpp> +#include <boost/accumulators/statistics/rolling_mean.hpp> +using namespace boost::accumulators; namespace MOBase { class IPluginGame; } @@ -75,6 +79,10 @@ private: struct DownloadInfo { ~DownloadInfo() { delete m_FileInfo; } + accumulator_set<int, stats<tag::rolling_mean>> m_DownloadAcc; + accumulator_set<int, stats<tag::rolling_mean>> m_DownloadTimeAcc; + int m_DownloadLast; + int m_DownloadTimeLast; unsigned int m_DownloadID; QString m_FileName; QFile m_Output; @@ -82,7 +90,6 @@ private: QElapsedTimer m_StartTime; qint64 m_PreResumeSize; std::pair<int, QString> m_Progress; - std::tuple<int, int, int, int, int> m_SpeedDiff; bool m_HasData; DownloadState m_State; int m_CurrentUrl; @@ -126,7 +133,10 @@ private: private: static unsigned int s_NextDownloadID; private: - DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_SpeedDiff(std::tuple<int,int,int,int,int>(0,0,0,0,0)), m_HasData(false) {} + DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_HasData(false), + m_DownloadTimeLast(0), m_DownloadLast(0), + m_DownloadAcc(tag::rolling_window::window_size = 500), + m_DownloadTimeAcc(tag::rolling_window::window_size = 500) {} }; friend class DownloadManagerProxy; diff --git a/src/organizer_en.ts b/src/organizer_en.ts index ffaa1fdd..cf43861c 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -1099,231 +1099,236 @@ File %3: %4</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="972"/> - <location filename="downloadmanager.cpp" line="1031"/> + <location filename="downloadmanager.cpp" line="971"/> + <location filename="downloadmanager.cpp" line="1030"/> <source>query: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="994"/> + <location filename="downloadmanager.cpp" line="993"/> <source>Please enter the nexus mod id</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="994"/> + <location filename="downloadmanager.cpp" line="993"/> <source>Mod ID:</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1005"/> + <location filename="downloadmanager.cpp" line="1004"/> <source>Please select the source game code for %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1064"/> + <location filename="downloadmanager.cpp" line="1063"/> <source>Hashing download file '%1'</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1065"/> + <location filename="downloadmanager.cpp" line="1064"/> <source>Cancel</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1094"/> + <location filename="downloadmanager.cpp" line="1093"/> <source>VisitNexus: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1115"/> + <location filename="downloadmanager.cpp" line="1114"/> <source>Nexus ID for this Mod is unknown</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1122"/> + <location filename="downloadmanager.cpp" line="1121"/> <source>OpenFile: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1166"/> + <location filename="downloadmanager.cpp" line="1165"/> <source>OpenFileInDownloadsFolder: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1201"/> + <location filename="downloadmanager.cpp" line="1200"/> <source>get pending: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1210"/> + <location filename="downloadmanager.cpp" line="1209"/> <source>get path: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1219"/> + <location filename="downloadmanager.cpp" line="1218"/> <source>Main</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1220"/> + <location filename="downloadmanager.cpp" line="1219"/> <source>Update</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1221"/> + <location filename="downloadmanager.cpp" line="1220"/> <source>Optional</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1222"/> + <location filename="downloadmanager.cpp" line="1221"/> <source>Old</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1223"/> + <location filename="downloadmanager.cpp" line="1222"/> <source>Miscellaneous</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1224"/> + <location filename="downloadmanager.cpp" line="1223"/> <source>Deleted</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1225"/> + <location filename="downloadmanager.cpp" line="1224"/> <source>Archived</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1226"/> + <location filename="downloadmanager.cpp" line="1225"/> <source>Unknown</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1233"/> + <location filename="downloadmanager.cpp" line="1232"/> <source>display name: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1253"/> + <location filename="downloadmanager.cpp" line="1252"/> <source>file name: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1262"/> + <location filename="downloadmanager.cpp" line="1261"/> <source>file time: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1281"/> + <location filename="downloadmanager.cpp" line="1280"/> <source>file size: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1291"/> + <location filename="downloadmanager.cpp" line="1290"/> <source>progress: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1301"/> + <location filename="downloadmanager.cpp" line="1300"/> <source>state: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1311"/> + <location filename="downloadmanager.cpp" line="1310"/> <source>infocomplete: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1326"/> - <location filename="downloadmanager.cpp" line="1334"/> - <location filename="downloadmanager.cpp" line="1347"/> + <location filename="downloadmanager.cpp" line="1325"/> + <location filename="downloadmanager.cpp" line="1333"/> + <location filename="downloadmanager.cpp" line="1346"/> <source>mod id: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1355"/> + <location filename="downloadmanager.cpp" line="1354"/> <source>ishidden: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1364"/> + <location filename="downloadmanager.cpp" line="1363"/> <source>file info: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1374"/> + <location filename="downloadmanager.cpp" line="1373"/> <source>mark installed: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1419"/> + <location filename="downloadmanager.cpp" line="1418"/> <source>mark uninstalled: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1591"/> + <location filename="downloadmanager.cpp" line="1580"/> + <source>%1% - %2 - ~%3</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="downloadmanager.cpp" line="1590"/> <source>Memory allocation error (in processing progress event).</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1601"/> + <location filename="downloadmanager.cpp" line="1600"/> <source>Memory allocation error (in processing downloaded data).</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1718"/> + <location filename="downloadmanager.cpp" line="1717"/> <source>Information updated</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1720"/> - <location filename="downloadmanager.cpp" line="1738"/> + <location filename="downloadmanager.cpp" line="1719"/> + <location filename="downloadmanager.cpp" line="1737"/> <source>No matching file found on Nexus! Maybe this file is no longer available or it was renamed?</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1722"/> + <location filename="downloadmanager.cpp" line="1721"/> <source>No file on Nexus matches the selected file by name. Please manually choose the correct one.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1901"/> + <location filename="downloadmanager.cpp" line="1900"/> <source>No download server available. Please try again later.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2068"/> + <location filename="downloadmanager.cpp" line="2067"/> <source>Failed to request file info from nexus: %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2095"/> + <location filename="downloadmanager.cpp" line="2094"/> <source>Warning: Content type is: %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2100"/> + <location filename="downloadmanager.cpp" line="2099"/> <source>Download header content length: %1 downloaded file size: %2</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2102"/> + <location filename="downloadmanager.cpp" line="2101"/> <source>Download failed: %1 (%2)</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2124"/> + <location filename="downloadmanager.cpp" line="2123"/> <source>We were unable to download the file due to errors after four retries. There may be an issue with the Nexus servers.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2207"/> + <location filename="downloadmanager.cpp" line="2206"/> <source>failed to re-open %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2252"/> + <location filename="downloadmanager.cpp" line="2251"/> <source>Unable to write download to drive (return %1). Check the drive's available storage. @@ -9332,4 +9337,25 @@ On Windows XP: <translation type="unfinished"></translation> </message> </context> +<context> + <name>uibase</name> + <message> + <location filename="../../uibase/src/utility.cpp" line="1155"/> + <source>h</source> + <extracomment>Time remaining hours</extracomment> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../uibase/src/utility.cpp" line="1158"/> + <source>m</source> + <extracomment>Time remaining minutes</extracomment> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../uibase/src/utility.cpp" line="1161"/> + <source>s</source> + <extracomment>Time remaining seconds</extracomment> + <translation type="unfinished"></translation> + </message> +</context> </TS> |
