Python Trueskill - Using Dictionaries
I'm trying out the Trueskill package from Python and have the basics worked out, For a two player match up I can do alice = Rating() bob = Rating() alice, bob = rate_1vs1(alice, b
Solution 1:
I did similar thing for applying to a TV show: https://gist.github.com/sublee/4967876
defaultdict
and groupby
may help you to achieve what you want:
from collections import defaultdict
from itertools import groupby
from pprint import pprint
from trueskill import Rating, rate
results = [(1, 'alice', 2),
(1, 'bob', 1),
(1, 'eve', 3),
(2, 'alice', 1),
(2, 'eve', 1),
(3, 'bob', 1),
(3, 'carol', 2),
(3, 'alice', 3),
(3, 'ted', 4),
(3, 'eve', 5)]
ratings = defaultdict(Rating)
for game_id, result in groupby(results, lambda x: x[0]):
result = list(result)
rating_groups = [(ratings[name],) for game_id, name, rank in result]
ranks = [rank for game_id, name, rank in result]
transformed_groups = rate(rating_groups, ranks=ranks)
for x, (game_id, name, rank) inenumerate(result):
ratings[name], = transformed_groups[x]
pprint(dict(ratings))
The result I got:
{'alice': trueskill.Rating(mu=23.967, sigma=4.088),
'bob': trueskill.Rating(mu=36.119, sigma=5.434),
'carol': trueskill.Rating(mu=29.226, sigma=5.342),
'eve': trueskill.Rating(mu=16.740, sigma=4.438),
'ted': trueskill.Rating(mu=21.013, sigma=5.150)}
Post a Comment for "Python Trueskill - Using Dictionaries"