def translate_peers_into_health(peer_info_dicts):
 upload_only = 0
 finished = 0
 unfinished_able_dl = 0
 interest_in_us = 0
 for p_info in peer_info_dicts:
  upload_only_b = False
  if p_info['upload_only']:
   upload_only += 1
   upload_only_b = True
  if p_info['uinterested']:
   interest_in_us += 1
  if (p_info['completed'] == 1):
   finished += 1
  else:
   unfinished_able_dl += (1 if upload_only_b else 0)
 num_seeders = max(upload_only, finished)
 num_leech = max(interest_in_us, min(unfinished_able_dl, (len(peer_info_dicts) - finished)))
 return (num_seeders, num_leech)

def translate_peers_into_health ( peer_info_dicts ) : upload_only = 0 finished = 0 unfinished_able_dl = 0 interest_in_us = 0 for p_info in peer_info_dicts : upload_only_b = False if p_info [ 'upload_only' ] : upload_only += 1 upload_only_b = True if p_info [ 'uinterested' ] : interest_in_us += 1 if ( p_info [ 'completed' ] == 1 ) : finished += 1 else : unfinished_able_dl += ( 1 if upload_only_b else 0 ) num_seeders = max ( upload_only , finished ) num_leech = max ( interest_in_us , min ( unfinished_able_dl , ( len ( peer_info_dicts ) - finished ) ) ) return ( num_seeders , num_leech )
peer_info_dicts is a peer_info dictionary from libtorrentdownloadimpl .