← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2599: More accurate indexing time left calculation

 

------------------------------------------------------------
revno: 2599
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2011-08-22 20:49:16 +0200
message:
  More accurate indexing time left calculation
modified:
  changelog.txt
  dcpp/HashManager.cpp
  dcpp/HashManager.h
  win32/HashProgressDlg.cpp
  win32/HashProgressDlg.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2011-08-20 14:45:57 +0000
+++ changelog.txt	2011-08-22 18:49:16 +0000
@@ -42,6 +42,7 @@
 * Update boost to version 1.47
 * COM initialization fix for the Windows UPnP mapper (thanks bigmuscle)
 * Show country codes next to country names (poy)
+* [L#425667] More accurate indexing time left calculation (poy)
 
 -- 0.782 2011-03-05 --
 * Prevent a remote crash triggered via malformed user commands (poy)

=== modified file 'dcpp/HashManager.cpp'
--- dcpp/HashManager.cpp	2011-04-24 11:27:49 +0000
+++ dcpp/HashManager.cpp	2011-08-22 18:49:16 +0000
@@ -507,7 +507,7 @@
 	}
 }
 
-void HashManager::Hasher::getStats(string& curFile, int64_t& bytesLeft, size_t& filesLeft) {
+void HashManager::Hasher::getStats(string& curFile, uint64_t& bytesLeft, size_t& filesLeft) const {
 	Lock l(cs);
 	curFile = currentFile;
 	filesLeft = w.size();

=== modified file 'dcpp/HashManager.h'
--- dcpp/HashManager.h	2011-04-13 19:16:51 +0000
+++ dcpp/HashManager.h	2011-08-22 18:49:16 +0000
@@ -75,7 +75,7 @@
 	}
 	void addTree(const TigerTree& tree) { Lock l(cs); store.addTree(tree); }
 
-	void getStats(string& curFile, int64_t& bytesLeft, size_t& filesLeft) {
+	void getStats(string& curFile, uint64_t& bytesLeft, size_t& filesLeft) const {
 		hasher.getStats(curFile, bytesLeft, filesLeft);
 	}
 
@@ -121,7 +121,7 @@
 		void stopHashing(const string& baseDir);
 		virtual int run();
 		bool fastHash(const string& fname, uint8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32);
-		void getStats(string& curFile, int64_t& bytesLeft, size_t& filesLeft);
+		void getStats(string& curFile, uint64_t& bytesLeft, size_t& filesLeft) const;
 		void shutdown() { stop = true; if(paused) s.signal(); s.signal(); }
 		void scheduleRebuild() { rebuild = true; if(paused) s.signal(); s.signal(); }
 

=== modified file 'win32/HashProgressDlg.cpp'
--- win32/HashProgressDlg.cpp	2011-08-20 15:26:22 +0000
+++ win32/HashProgressDlg.cpp	2011-08-22 18:49:16 +0000
@@ -35,6 +35,8 @@
 using dwt::Label;
 using dwt::ProgressBar;
 
+namespace { const int progressBarMax = 10000; }
+
 HashProgressDlg::HashProgressDlg(dwt::Widget* parent, bool aAutoClose) :
 GridDialog(parent, 657, DS_CONTEXTHELP),
 file(0),
@@ -77,7 +79,7 @@
 	}
 
 	progress = grid->addChild(ProgressBar::Seed());
-	progress->setRange(0, 10000);
+	progress->setRange(0, progressBarMax);
 
 	{
 		GridPtr cur = grid->addChild(Grid::Seed(1, 2));
@@ -114,11 +116,12 @@
 
 bool HashProgressDlg::updateStats() {
 	string path;
-	int64_t bytes = 0;
+	uint64_t bytes = 0;
 	size_t files = 0;
 	uint64_t tick = GET_TICK();
 
 	HashManager::getInstance()->getStats(path, bytes, files);
+
 	if(bytes > startBytes)
 		startBytes = bytes;
 
@@ -130,42 +133,36 @@
 		return true;
 	}
 
-	double diff = tick - startTime;
+	file->setText(files ? Text::toT(path) : T_("Done"));
+
+	double timeDiff = tick - startTime;
+
 	bool paused = HashManager::getInstance()->isHashingPaused();
-	if(diff < 1000 || files == 0 || bytes == 0 || paused) {
+	if(timeDiff < 1000 || files == 0 || bytes == 0 || paused) {
 		stat->setText(str(TF_("-.-- files/h, %1% files left") % (uint32_t)files));
 		speed->setText(str(TF_("-.-- B/s, %1% left") % Text::toT(Util::formatBytes(bytes))));
 		if(paused) {
 			left->setText(T_("Paused"));
 		} else {
-			left->setText(T_("-:--:-- left"));
-		}
-	} else {
-		double filestat = (((double)(startFiles - files)) * 60 * 60 * 1000) / diff;
-		double speedStat = (((double)(startBytes - bytes)) * 1000) / diff;
-
-		stat->setText(str(TF_("%1% files/h, %2% files left") % filestat % (uint32_t)files));
-		speed->setText(str(TF_("%1%/s, %2% left") % Text::toT(Util::formatBytes((int64_t)speedStat)) % Text::toT(Util::formatBytes(bytes))));
-
-		if(filestat == 0 || speedStat == 0) {
-			left->setText(T_("-:--:-- left"));
-		} else {
-			double fs = files * 60 * 60 / filestat;
-			double ss = bytes / speedStat;
-			left->setText(str(TF_("%1% left") % Text::toT(Util::formatSeconds((int64_t)(fs + ss) / 2))));
-		}
-	}
-
-	if(files == 0) {
-		file->setText(T_("Done"));
-	} else {
-		file->setText(Text::toT(path));
-	}
-
-	if(startFiles == 0 || startBytes == 0) {
-		progress->setPosition(0);
-	} else {
-		progress->setPosition((int)(10000 * ((0.5 * (startFiles - files)/startFiles) + 0.5 * (startBytes - bytes) / startBytes)));
+			left->setText(str(TF_("%1% left") % T_("-:--:--")));
+			progress->setPosition(0);
+		}
+
+	} else {
+		auto fileDiff = startFiles - files;
+		auto byteDiff = startBytes - bytes;
+
+		double fileStat = static_cast<double>(fileDiff) * 60. * 60. * 1000. / timeDiff;
+		double speedStat = static_cast<double>(byteDiff) * 1000. / timeDiff;
+
+		stat->setText(str(TF_("%1% files/h, %2% files left") % fileStat % static_cast<uint32_t>(files)));
+		speed->setText(str(TF_("%1%/s, %2% left") % Text::toT(Util::formatBytes(speedStat)) % Text::toT(Util::formatBytes(bytes))));
+
+		double timeLeft = speedStat ? static_cast<double>(bytes) / speedStat : fileStat ? static_cast<double>(files) * 60. * 60. / fileStat : 0;
+		left->setText(str(TF_("%1% left") % (timeLeft ? Text::toT(Util::formatSeconds(timeLeft)) : T_("-:--:--"))));
+
+		progress->setPosition(progressBarMax * (startBytes ? static_cast<double>(byteDiff / startBytes) :
+			startFiles ? static_cast<double>(fileDiff / startFiles) : 0));
 	}
 
 	return true;

=== modified file 'win32/HashProgressDlg.h'
--- win32/HashProgressDlg.h	2011-01-02 17:12:02 +0000
+++ win32/HashProgressDlg.h	2011-08-22 18:49:16 +0000
@@ -36,7 +36,7 @@
 	ButtonPtr pauseResume;
 
 	bool autoClose;
-	int64_t startBytes;
+	uint64_t startBytes;
 	size_t startFiles;
 	uint64_t startTime;