Get a ranking of peers to contact for a zonefile.
    Peers are ranked by health (i.e. response ratio).

    Optionally include peers we haven't talked to yet (@with_zero_requests)
    Optionally return [(health, peer)] list instead of just [peer] list (@with_rank)

def atlas_rank_peers_by_health( peer_list=None, peer_table=None, with_zero_requests=False, with_rank=False ):
    """
    Get a ranking of peers to contact for a zonefile.
    Peers are ranked by health (i.e. response ratio).

    Optionally include peers we haven't talked to yet (@with_zero_requests)
    Optionally return [(health, peer)] list instead of just [peer] list (@with_rank)
    """

    with AtlasPeerTableLocked(peer_table) as ptbl:
        if peer_list is None:
            peer_list = ptbl.keys()[:]

        peer_health_ranking = []    # (health score, peer hostport)
        for peer_hostport in peer_list:
            reqcount = atlas_peer_get_request_count( peer_hostport, peer_table=ptbl )
            if reqcount == 0 and not with_zero_requests:
                continue

            health_score = atlas_peer_get_health( peer_hostport, peer_table=ptbl)
            peer_health_ranking.append( (health_score, peer_hostport) )
    
    # sort on health
    peer_health_ranking.sort()
    peer_health_ranking.reverse()

    if not with_rank:
        return [peer_hp for _, peer_hp in peer_health_ranking]
    else:
        # include the score.
        return peer_health_ranking