expand the last commit a bit so that ratio is calculated with the actual downloaded amount if amount downloaded in T is 0. This should eliminate ever showing infinity for ratio.

This commit is contained in:
Mitchell Livingston
2007-04-20 23:51:15 +00:00
parent dbc1e1619e
commit ea839e8ca9
4 changed files with 8 additions and 14 deletions
+4 -4
View File
@@ -461,14 +461,14 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
if( s->downloaded == 0 )
{
//if seeding without ever downloading, calculate ratio from total size
if( s->progress >= 1.0 )
//if some is downloaded without a downloaded value, calculate ratio from total size
if( s->progress > 0.0 )
{
s->ratio = (float)s->uploaded / (float)inf->totalSize;
s->ratio = (float)s->uploaded / ((float)inf->totalSize * s->progress);
}
else
{
s->ratio = s->uploaded == 0 ? TR_RATIO_NA : TR_RATIO_INF;
s->ratio = TR_RATIO_NA;
}
}
else
-1
View File
@@ -448,7 +448,6 @@ struct tr_stat_s
float swarmspeed;
#define TR_RATIO_NA -1
#define TR_RATIO_INF -2
float ratio;
};
+1 -2
View File
@@ -105,10 +105,9 @@
{
if (ratio == TR_RATIO_NA)
return NSLocalizedString(@"N/A", "No Ratio");
else if (ratio == TR_RATIO_INF)
return [NSString stringWithUTF8String: "\xE2\x88\x9E"];
else if (ratio < 0)
return NSLocalizedString(@"error", "Ratio invalid");
else;
if (ratio < 10.0)
return [NSString stringWithFormat: @"%.2f", ratio];
+3 -7
View File
@@ -289,9 +289,9 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
}
//check to stop for ratio
float stopRatio, ratio;
float stopRatio;
if ([self isSeeding] && (stopRatio = [self actualStopRatio]) != INVALID
&& ((ratio = [self ratio]) >= stopRatio || ratio == TR_RATIO_INF))
&& [self ratio] >= stopRatio)
{
[self stopTransfer];
fStat = tr_torrentStat(fHandle);
@@ -1256,11 +1256,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
- (NSNumber *) ratioSortKey
{
float ratio = [self ratio];
if (ratio == TR_RATIO_INF)
return [NSNumber numberWithInt: 999999999]; //this should hopefully be big enough
else
return [NSNumber numberWithFloat: [self ratio]];
return [NSNumber numberWithFloat: [self ratio]];
}
@end