Find the maximally interesting pairs of players to match up
    First, sort the ratings by uncertainty.
    Then, take the ten highest players with the highest uncertainty
    For each of them, call them `p1`
    Sort all the models by their distance from p1's rating and take the 20
    nearest rated models. ('candidate_p2s')
    Choose pairings, (p1, p2), randomly from this list.

    `top_n` will pair the top n models by uncertainty.
    `per_n` will give each of the top_n models this many opponents
    `ignore_before` is the model number to `filter` off, i.e., the early models.
    Returns a list of *model numbers*, not model ids.

def suggest_pairs(top_n=10, per_n=3, ignore_before=300):
    """ Find the maximally interesting pairs of players to match up
    First, sort the ratings by uncertainty.
    Then, take the ten highest players with the highest uncertainty
    For each of them, call them `p1`
    Sort all the models by their distance from p1's rating and take the 20
    nearest rated models. ('candidate_p2s')
    Choose pairings, (p1, p2), randomly from this list.

    `top_n` will pair the top n models by uncertainty.
    `per_n` will give each of the top_n models this many opponents
    `ignore_before` is the model number to `filter` off, i.e., the early models.
    Returns a list of *model numbers*, not model ids.
    """
    db = sqlite3.connect("ratings.db")
    data = db.execute("select model_winner, model_loser from wins").fetchall()
    bucket_ids = [id[0] for id in db.execute(
        "select id from models where bucket = ?", (fsdb.models_dir(),)).fetchall()]
    bucket_ids.sort()
    data = [d for d in data if d[0] in bucket_ids and d[1] in bucket_ids]

    ratings = [(model_num_for(k), v[0], v[1]) for k, v in compute_ratings(data).items()]
    ratings.sort()
    ratings = ratings[ignore_before:]  # Filter off the first 100 models, which improve too fast.

    ratings.sort(key=lambda r: r[2], reverse=True)

    res = []
    for p1 in ratings[:top_n]:
        candidate_p2s = sorted(ratings, key=lambda p2_tup: abs(p1[1] - p2_tup[1]))[1:20]
        choices = random.sample(candidate_p2s, per_n)
        print("Pairing {}, sigma {:.2f} (Rating {:.2f})".format(p1[0], p1[2], p1[1]))
        for p2 in choices:
            res.append([p1[0], p2[0]])
            print("   {}, ratings delta {:.2f}".format(p2[0], abs(p1[1] - p2[1])))
    return res