Changeset 4482


Ignore:
Timestamp:
Jan 4, 2008, 7:13:30 PM (14 years ago)
Author:
charles
Message:

tr_stat.ratio now returns TR_RATIO_INF when appropriate

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/stats.c

    r4404 r4482  
    136136updateRatio( tr_session_stats * setme )
    137137{
    138     if( setme->downloadedBytes )
    139         setme->ratio = setme->uploadedBytes / (double)setme->downloadedBytes;
    140     else if( setme->uploadedBytes )
    141         setme->ratio = TR_RATIO_INF;
    142     else
    143         setme->ratio = TR_RATIO_NA;
     138    setme->ratio = tr_getRatio( setme->uploadedBytes, setme->downloadedBytes );
    144139}
    145140
  • trunk/libtransmission/torrent.c

    r4427 r4482  
    662662        tr_bitfieldFree( availablePieces );
    663663    }
    664    
    665     s->ratio = ( s->downloadedEver || s->haveValid )
    666       ? s->uploadedEver / (float)(MAX(s->downloadedEver,s->haveValid))
    667       : TR_RATIO_NA;
     664
     665    s->ratio = tr_getRatio( s->uploadedEver, MAX( s->downloadedEver, s->haveValid ) );
    668666   
    669667    tr_torrentUnlock( tor );
  • trunk/libtransmission/transmission.h

    r4404 r4482  
    134134    uint64_t uploadedBytes;   /* total up */
    135135    uint64_t downloadedBytes; /* total down */
    136     double ratio;             /* total up / total down */
     136    double ratio;             /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */
    137137    uint64_t filesAdded;      /* number of files added */
    138138    uint64_t sessionCount;    /* program started N times */
     
    765765#define TR_RATIO_NA  -1
    766766#define TR_RATIO_INF -2
     767    /* TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
    767768    float               ratio;
    768769   
  • trunk/libtransmission/utils.c

    r4480 r4482  
    843843
    844844#endif /* HAVE_STRLCAT */
     845
     846/***
     847****
     848***/
     849
     850double
     851tr_getRatio( double numerator, double denominator )
     852{
     853    double ratio;
     854
     855    if( denominator )
     856        ratio = numerator / denominator;
     857    else if( numerator )
     858        ratio = TR_RATIO_INF;
     859    else
     860        ratio = TR_RATIO_NA;
     861
     862    return ratio;
     863}
  • trunk/libtransmission/utils.h

    r4404 r4482  
    151151tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
    152152
     153double tr_getRatio( double numerator, double denominator );
     154
    153155#endif
Note: See TracChangeset for help on using the changeset viewer.