PDA

View Full Version : Not Bug exactly: Computation of Connection time remaining


bsdman
August 20th, 2006, 06:48 PM
I posted it on the Gnutella forums. Forgive the referral, I just didn't want to type it again:

http://www.gnutellaforums.com/showthread.php?t=60210

Any comments are appreciated.

Judge Zargabaath
August 20th, 2007, 05:05 PM
This is what was said: (not by me) Or something close i dunno how to do code properly

I have read some of the code, and as I understand it, my suggestion could be implemented by changing the DownloadDataLine class in the com.limegroup.gnutella.gui.download package as follows:



/* Beginning on line 786 */
// If we have a valid rate (can't compute if rate is 0),
// then determine how much time (in seconds) is remaining.
if ( _speed > 0) {
double kbLeft = ((_size/1024.0) -
(_amountRead/1024.0));
_timeLeft = newTimeRemaining((int)(kbLeft / _speed));
}


And then, add a new private method to do the rolling average, along with some member data:


// This member data is for the rolling average.
private final int N = 10; // the number of times to save, adjust at leasure
private boolean full = false; // to only use the average when we have N #s
private int index = 0; // the index for the element to replace in times[]
private int times[] = new int[N]; // the list of times
/**
* This method calculates the new time remaining based on a rolling average.
* @author bsdman
*/
private int newTimeRemaining(int anotherTime)
{
times[index++] = anotherTime;
if(index == N)
{
index = 0;
full = true;
}
if(!full)
return anotherTime; // since we can't average yet
// otherwise, take the average
// TODO this average could probably be written more efficeiently
long total = 0;
for(int i = 0; i < N; i++)
total += times[i];
return (int)(total/N);
}


Just to save time for people with slow connections ;) Change it back to what it is if you get the chance

bsdman
August 21st, 2007, 03:36 AM
Thanks for the repeat of the message.

Perhaps this has already been acted upon. In the version of Limewire I just updated to, my code isn't in it, but the download times are not screwy anymore. Good work.