avoid divide-by-0 in stats
This commit is contained in:
parent
6b5f1839aa
commit
bf3bd6bd5d
|
@ -140,7 +140,7 @@ tr_getSessionStats( const tr_handle * handle,
|
||||||
{
|
{
|
||||||
const struct tr_stats_handle * stats = handle->sessionStats;
|
const struct tr_stats_handle * stats = handle->sessionStats;
|
||||||
*setme = stats->single;
|
*setme = stats->single;
|
||||||
setme->ratio = (double)setme->uploadedMiB / (double)setme->downloadedMiB;
|
setme->ratio = setme->downloadedMiB ? (double)setme->uploadedMiB / (double)setme->downloadedMiB : TR_RATIO_NA;
|
||||||
setme->secondsActive += (time(NULL) - stats->startTime );
|
setme->secondsActive += (time(NULL) - stats->startTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ tr_getCumulativeSessionStats( const tr_handle * handle,
|
||||||
{
|
{
|
||||||
const struct tr_stats_handle * stats = handle->sessionStats;
|
const struct tr_stats_handle * stats = handle->sessionStats;
|
||||||
*setme = stats->cumulative;
|
*setme = stats->cumulative;
|
||||||
setme->ratio = (double)setme->uploadedMiB / (double)setme->downloadedMiB;
|
setme->ratio = setme->downloadedMiB ? (double)setme->uploadedMiB / (double)setme->downloadedMiB : TR_RATIO_NA;
|
||||||
setme->secondsActive += (time(NULL) - stats->startTime );
|
setme->secondsActive += (time(NULL) - stats->startTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,11 @@ tr_handle * fLib;
|
||||||
stringByAppendingString: NSLocalizedString(@" total", "stats total")]];
|
stringByAppendingString: NSLocalizedString(@" total", "stats total")]];
|
||||||
|
|
||||||
[fRatioField setStringValue: [NSString stringForRatio: statsSession.ratio]];
|
[fRatioField setStringValue: [NSString stringForRatio: statsSession.ratio]];
|
||||||
[fRatioAllField setStringValue: [[NSString stringForRatio: statsAll.ratio]
|
|
||||||
stringByAppendingString: NSLocalizedString(@" total", "stats total")]];
|
NSString * totalRatioString = statsAll.ratio != TR_RATIO_NA
|
||||||
|
? [[NSString stringForRatio: statsAll.ratio] stringByAppendingString: NSLocalizedString(@" total", "stats total")]
|
||||||
|
: NSLocalizedString(@"Total N/A", "stats total");
|
||||||
|
[fRatioAllField setStringValue: totalRatioString];
|
||||||
|
|
||||||
[fTimeField setStringValue: [self timeString: statsSession.secondsActive]];
|
[fTimeField setStringValue: [self timeString: statsSession.secondsActive]];
|
||||||
[fTimeAllField setStringValue: [[self timeString: statsAll.secondsActive]
|
[fTimeAllField setStringValue: [[self timeString: statsAll.secondsActive]
|
||||||
|
|
Loading…
Reference in New Issue