1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#!/usr/bin/python
import pytest
import rater
class Match:
def __init__(self, game_mode, rosters):
self.api_id = ""
self.game_mode = game_mode
self.rosters = rosters
self.participants = [p for r in rosters for p in r.participants]
class Roster:
def __init__(self, winner, participants):
self.api_id = ""
self.winner = winner
self.participants = participants
class Participant:
def __init__(self, skill_tier, went_afk,
trueskill_mu, trueskill_sigma,
participant_items, player):
self.api_id = ""
self.skill_tier = skill_tier
self.went_afk = went_afk
self.participant_items = [participant_items]
self.player = [player]
class ParticipantItems:
def __init__(self, trueskill_casual_mu, trueskill_casual_sigma,
trueskill_ranked_mu, trueskill_ranked_sigma,
trueskill_blitz_mu, trueskill_blitz_sigma,
trueskill_br_mu, trueskill_br_sigma):
self.api_id = ""
self.trueskill_casual_mu = trueskill_casual_mu
self.trueskill_casual_sigma = trueskill_casual_sigma
self.trueskill_ranked_mu = trueskill_ranked_mu
self.trueskill_ranked_sigma = trueskill_ranked_sigma
self.trueskill_blitz_mu = trueskill_blitz_mu
self.trueskill_blitz_sigma = trueskill_blitz_sigma
self.any_afk = False
class Player:
def __init__(self, skill_tier,
rank_points_ranked,
rank_points_blitz,
trueskill_mu, trueskill_sigma,
trueskill_casual_mu, trueskill_casual_sigma,
trueskill_ranked_mu, trueskill_ranked_sigma,
trueskill_blitz_mu, trueskill_blitz_sigma,
trueskill_br_mu, trueskill_br_sigma):
self.api_id = ""
self.skill_tier = skill_tier
self.rank_points_ranked = rank_points_ranked
self.rank_points_blitz = rank_points_blitz
self.trueskill_mu = trueskill_mu
self.trueskill_sigma = trueskill_sigma
self.trueskill_casual_mu = trueskill_casual_mu
self.trueskill_casual_sigma = trueskill_casual_sigma
self.trueskill_ranked_mu = trueskill_ranked_mu
self.trueskill_ranked_sigma = trueskill_ranked_sigma
self.trueskill_blitz_mu = trueskill_blitz_mu
self.trueskill_blitz_sigma = trueskill_blitz_sigma
class TestRater:
def test_get_trueskill_seed(self):
# test approx. by skill tier
player = Player(15, None, None,
None, None,
None, None,
None, None,
None, None,
None, None)
mu, sigma = rater.get_trueskill_seed(player)
assert 1300 < mu - sigma < 1700
# test approx. by rank points
player = Player(0, 2500, None,
None, None,
None, None,
None, None,
None, None,
None, None)
mu, sigma = rater.get_trueskill_seed(player)
assert mu - sigma == 2500
player = Player(0, 2500, 100,
None, None,
None, None,
None, None,
None, None,
None, None)
mu, sigma = rater.get_trueskill_seed(player)
assert mu - sigma == 2500
player = Player(0, 100, 2500,
None, None,
None, None,
None, None,
None, None,
None, None)
mu, sigma = rater.get_trueskill_seed(player)
assert mu - sigma == 2500
player = Player(0, None, 2500,
None, None,
None, None,
None, None,
None, None,
None, None)
mu, sigma = rater.get_trueskill_seed(player)
assert mu - sigma == 2500
def test_rate_match(self):
# new user, only skill tier
g_player = lambda: Player(15, None, None,
None, None,
None, None,
None, None,
None, None,
None, None)
g_participant_items = lambda: ParticipantItems(None, None,
None, None,
None, None,
None, None)
g_participant = lambda: Participant(0, False,
None, None,
g_participant_items(), g_player())
roster = Roster(True, [g_participant()]*3)
roster2 = Roster(False, [g_participant()]*3)
match = Match("ranked", [roster, roster2])
rater.rate_match(match)
assert match.rosters[0].participants[0].player[0].trueskill_mu is not None
assert match.rosters[0].participants[0].player[0].trueskill_ranked_mu is not None
assert match.rosters[0].participants[0].player[0].trueskill_ranked_sigma < match.rosters[0].participants[0].player[0].trueskill_ranked_mu
assert 500 < match.rosters[0].participants[0].player[0].trueskill_ranked_mu < 2500
assert match.rosters[0].participants[0].player[0].trueskill_casual_mu is None
assert match.rosters[0].participants[0].player[0].trueskill_mu > match.rosters[1].participants[0].player[0].trueskill_mu
assert match.rosters[0].participants[0].player[0].trueskill_ranked_mu > match.rosters[1].participants[0].player[0].trueskill_ranked_mu
def test_rate_match_returning(self):
# returning user
g_player = lambda: Player(None, None, None,
2000, 100,
None, None,
None, None,
None, None,
None, None)
g_participant_items = lambda: ParticipantItems(None, None,
None, None,
None, None,
None, None)
g_participant = lambda: Participant(0, False,
None, None,
g_participant_items(), g_player())
roster = Roster(True, [g_participant()]*3)
roster2 = Roster(False, [g_participant()]*3)
match = Match("ranked", [roster, roster2])
rater.rate_match(match)
assert 1800 < match.rosters[0].participants[0].player[0].trueskill_ranked_mu < 2200
def test_rate_match_afk(self):
# afk
g_player = lambda: Player(None, None, None,
None, None,
None, None,
None, None,
None, None,
None, None)
g_participant_items = lambda: ParticipantItems(None, None,
None, None,
None, None,
None, None)
g_participant = lambda: Participant(0, True,
None, None,
g_participant_items(), g_player())
roster = Roster(True, [g_participant()]*3)
roster2 = Roster(False, [g_participant()]*3)
match = Match("ranked", [roster, roster2])
rater.rate_match(match)
assert match.rosters[0].participants[0].player[0].trueskill_mu is None
assert match.rosters[0].participants[0].participant_items[0].any_afk == True
|