tr_stat.ratio now returns TR_RATIO_INF when appropriate
This commit is contained in:
parent
802f34a245
commit
15ffb4232e
|
@ -135,12 +135,7 @@ tr_statsClose( tr_handle * handle )
|
|||
static void
|
||||
updateRatio( tr_session_stats * setme )
|
||||
{
|
||||
if( setme->downloadedBytes )
|
||||
setme->ratio = setme->uploadedBytes / (double)setme->downloadedBytes;
|
||||
else if( setme->uploadedBytes )
|
||||
setme->ratio = TR_RATIO_INF;
|
||||
else
|
||||
setme->ratio = TR_RATIO_NA;
|
||||
setme->ratio = tr_getRatio( setme->uploadedBytes, setme->downloadedBytes );
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -661,10 +661,8 @@ tr_torrentStat( tr_torrent * tor )
|
|||
|
||||
tr_bitfieldFree( availablePieces );
|
||||
}
|
||||
|
||||
s->ratio = ( s->downloadedEver || s->haveValid )
|
||||
? s->uploadedEver / (float)(MAX(s->downloadedEver,s->haveValid))
|
||||
: TR_RATIO_NA;
|
||||
|
||||
s->ratio = tr_getRatio( s->uploadedEver, MAX( s->downloadedEver, s->haveValid ) );
|
||||
|
||||
tr_torrentUnlock( tor );
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ typedef struct tr_session_stats
|
|||
{
|
||||
uint64_t uploadedBytes; /* total up */
|
||||
uint64_t downloadedBytes; /* total down */
|
||||
double ratio; /* total up / total down */
|
||||
double ratio; /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */
|
||||
uint64_t filesAdded; /* number of files added */
|
||||
uint64_t sessionCount; /* program started N times */
|
||||
uint64_t secondsActive; /* how long Transmisson's been running */
|
||||
|
@ -764,6 +764,7 @@ struct tr_stat
|
|||
|
||||
#define TR_RATIO_NA -1
|
||||
#define TR_RATIO_INF -2
|
||||
/* TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
|
||||
float ratio;
|
||||
|
||||
uint64_t startDate;
|
||||
|
|
|
@ -842,3 +842,22 @@ strlcat(char *dst, const char *src, size_t siz)
|
|||
}
|
||||
|
||||
#endif /* HAVE_STRLCAT */
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
double
|
||||
tr_getRatio( double numerator, double denominator )
|
||||
{
|
||||
double ratio;
|
||||
|
||||
if( denominator )
|
||||
ratio = numerator / denominator;
|
||||
else if( numerator )
|
||||
ratio = TR_RATIO_INF;
|
||||
else
|
||||
ratio = TR_RATIO_NA;
|
||||
|
||||
return ratio;
|
||||
}
|
||||
|
|
|
@ -150,4 +150,6 @@ size_t tr_bitfieldCountTrueBits( const tr_bitfield* );
|
|||
|
||||
tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
|
||||
|
||||
double tr_getRatio( double numerator, double denominator );
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue