本文整理汇总了Python中dao.Dao.get_latest_ranking方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.get_latest_ranking方法的具体用法?Python Dao.get_latest_ranking怎么用?Python Dao.get_latest_ranking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.get_latest_ranking方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
def get(self, region):
dao = Dao(region, mongo_client=mongo_client)
return_dict = dao.get_latest_ranking().get_json_dict()
del return_dict['_id']
return_dict['time'] = str(return_dict['time'])
return_dict['tournaments'] = [str(t) for t in return_dict['tournaments']]
ranking_list = []
for r in return_dict['ranking']:
player = dao.get_player_by_id(r['player'])
if player:
r['name'] = player.name
r['id'] = str(r.pop('player'))
ranking_list.append(r)
return_dict['ranking'] = ranking_list
return return_dict
示例2: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
def get(self, region):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
return_dict = dao.get_latest_ranking().dump(context='web')
if not return_dict:
return 'Dao couldnt give us rankings', 400
ranking_list = []
for r in return_dict['ranking']:
player = dao.get_player_by_id(ObjectId(r['player']))
if player:
r['name'] = player.name
r['id'] = str(r.pop('player'))
ranking_list.append(r)
ranking_criteria = dao.get_region_ranking_criteria(region)
return_dict['ranking'] = ranking_list
return_dict['ranking_criteria'] = ranking_criteria
return return_dict
示例3: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
def get(self, region):
dao = Dao(region, mongo_client=mongo_client)
args = rankings_get_parser.parse_args()
if args['generateNew'] is not None and args['generateNew'] == 'true':
rankings.generate_ranking(dao)
return_dict = dao.get_latest_ranking().get_json_dict()
del return_dict['_id']
return_dict['time'] = str(return_dict['time'])
return_dict['tournaments'] = [str(t) for t in return_dict['tournaments']]
ranking_list = []
for r in return_dict['ranking']:
player = dao.get_player_by_id(r['player'])
if player:
r['name'] = player.name
r['id'] = str(r.pop('player'))
ranking_list.append(r)
return_dict['ranking'] = ranking_list
return return_dict
示例4: TestRankings
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
def test_generate_rankings(self):
now = datetime(2013, 10, 17)
# assert rankings before they get reset
self.assertEquals(self.dao.get_player_by_id(self.player_1_id).ratings, self.player_1.ratings)
self.assertEquals(self.dao.get_player_by_id(self.player_2_id).ratings, self.player_2.ratings)
self.assertEquals(self.dao.get_player_by_id(self.player_3_id).ratings, self.player_3.ratings)
self.assertEquals(self.dao.get_player_by_id(self.player_4_id).ratings, self.player_4.ratings)
self.assertEquals(self.dao.get_player_by_id(self.player_5_id).ratings, self.player_5.ratings)
rankings.generate_ranking(self.dao, now=now, day_limit=30, num_tourneys=1)
# assert rankings after ranking calculation
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['norcal'].mu,
28.458, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['norcal'].sigma,
7.201, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).ratings['norcal'].mu,
18.043, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).ratings['norcal'].sigma,
6.464, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].mu,
2, delta=delta) #changing this b/c of new in regionon only stuff, lol
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].sigma,
3, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).ratings['norcal'].mu,
25, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).ratings['norcal'].sigma,
8.333, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).ratings['norcal'].mu,
29.396, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).ratings['norcal'].sigma,
7.171, delta=delta)
# player 1's rating for other regions should not have changed
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['texas'].mu,
25, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['texas'].sigma,
8.333, delta=delta)
ranking = self.dao.get_latest_ranking()
self.assertEquals(ranking.region, self.region_id)
self.assertEquals(ranking.time, now)
self.assertEquals(set(ranking.tournaments), set(self.tournament_ids))
ranking_list = ranking.ranking
# the ranking should not have any excluded players
self.assertEquals(len(ranking_list), 3)
entry = ranking_list[0]
self.assertEquals(entry.rank, 1)
self.assertEquals(entry.player, self.player_5_id)
self.assertAlmostEquals(entry.rating, 7.881, delta=delta)
entry = ranking_list[1]
self.assertEquals(entry.rank, 2)
self.assertEquals(entry.player, self.player_1_id)
self.assertAlmostEquals(entry.rating, 6.857, delta=delta)
entry = ranking_list[2]
self.assertEquals(entry.rank, 3)
self.assertEquals(entry.player, self.player_2_id)
self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
'''
entry = ranking_list[3]
self.assertEquals(entry.rank, 4)
self.assertEquals(entry.player, self.player_3_id)
self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
'''
# players that only played in the first tournament will be excluded for inactivity
def test_generate_rankings_excluded_for_inactivity(self):
now = datetime(2013, 11, 25)
rankings.generate_ranking(self.dao, now=now, day_limit=45, num_tourneys=1)
ranking = self.dao.get_latest_ranking()
ranking_list = ranking.ranking
self.assertEquals(len(ranking_list), 2)
entry = ranking_list[0]
self.assertEquals(entry.rank, 1)
self.assertEquals(entry.player, self.player_1_id)
self.assertAlmostEquals(entry.rating, 6.857, delta=delta)
'''
entry = ranking_list[1]
self.assertEquals(entry.rank, 2)
self.assertEquals(entry.player, self.player_5_id)
self.assertAlmostEquals(entry.rating, -.800, delta=delta, msg="" + str(entry.player))
'''
entry = ranking_list[1]
self.assertEquals(entry.rank, 2)
self.assertEquals(entry.player, self.player_2_id)
self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
示例5: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
self.assertEquals(len(tournament_2.matches), len(self.tournament_matches_1))
self.assertEquals(tournament_2.matches[0], self.tournament_matches_1[0])
self.assertEquals(tournament_2.matches[1], self.tournament_matches_1[1])
self.assertEquals(tournament_2.regions, self.tournament_regions_2)
merged_player_aliases = set(['gar', 'garr', 'pewpewu'])
merged_player_regions = set(['norcal', 'texas', 'socal'])
merged_player = self.norcal_dao.get_player_by_id(self.player_1_id)
self.assertEquals(merged_player.id, self.player_1_id)
self.assertEquals(merged_player.name, self.player_1.name)
self.assertEquals(set(merged_player.aliases), merged_player_aliases)
self.assertEquals(set(merged_player.regions), merged_player_regions)
self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_5_id))
def test_merge_players_none(self):
with self.assertRaises(TypeError):
self.norcal_dao.merge_players()
with self.assertRaises(TypeError):
self.norcal_dao.merge_players(source=self.player_1)
with self.assertRaises(TypeError):
self.norcal_dao.merge_players(target=self.player_1)
def test_merge_players_same_player(self):
with self.assertRaises(ValueError):
self.norcal_dao.merge_players(source=self.player_1, target=self.player_1)
# TODO
def test_merge_players_same_player_in_single_match(self):
pass
def test_get_latest_ranking(self):
latest_ranking = self.norcal_dao.get_latest_ranking()
self.assertEquals(latest_ranking.time, self.ranking_time_2)
self.assertEquals(latest_ranking.tournaments, self.tournament_ids)
rankings = latest_ranking.ranking
self.assertEquals(len(rankings), 3)
self.assertEquals(rankings[0], self.ranking_entry_1)
self.assertEquals(rankings[1], self.ranking_entry_2)
self.assertEquals(rankings[2], self.ranking_entry_4)
def test_get_or_create_user_by_id_new_user(self):
users = self.norcal_dao.get_all_users()
self.assertEquals(len(users), 2)
new_id = 'lol'
user = self.norcal_dao.get_or_create_user_by_id(new_id)
users = self.norcal_dao.get_all_users()
self.assertEquals(len(users), 3)
self.assertEquals(user.id, new_id)
self.assertEquals(user.full_name, '')
self.assertEquals(user.admin_regions, [])
# make sure none of the old users have been modified
user = users[0]
self.assertEquals(user.id, self.user_id_1)
self.assertEquals(user.full_name, '')
self.assertEquals(user.admin_regions, self.user_admin_regions_1)
示例6: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
self.assertEquals(tournament_2.matches, self.tournament_matches_2)
self.assertEquals(tournament_2.players, self.tournament_players_2)
def test_get_all_tournaments_containing_players(self):
players = [self.player_5]
tournaments = self.dao.get_all_tournaments(players=players)
self.assertEquals(len(tournaments), 1)
tournament = tournaments[0]
self.assertEquals(tournament.id, self.tournament_id_2)
self.assertEquals(tournament.type, self.tournament_type_2)
self.assertEquals(tournament.raw, self.tournament_raw_2)
self.assertEquals(tournament.date, self.tournament_date_2)
self.assertEquals(tournament.name, self.tournament_name_2)
self.assertEquals(tournament.matches, self.tournament_matches_2)
self.assertEquals(tournament.players, self.tournament_players_2)
def test_get_tournament_by_id(self):
tournament_1 = self.dao.get_tournament_by_id(self.tournament_id_1)
self.assertEquals(tournament_1.id, self.tournament_id_1)
self.assertEquals(tournament_1.type, self.tournament_type_1)
self.assertEquals(tournament_1.raw, self.tournament_raw_1)
self.assertEquals(tournament_1.date, self.tournament_date_1)
self.assertEquals(tournament_1.name, self.tournament_name_1)
self.assertEquals(tournament_1.matches, self.tournament_matches_1)
self.assertEquals(tournament_1.players, self.tournament_players_1)
tournament_2 = self.dao.get_tournament_by_id(self.tournament_id_2)
self.assertEquals(tournament_2.id, self.tournament_id_2)
self.assertEquals(tournament_2.type, self.tournament_type_2)
self.assertEquals(tournament_2.raw, self.tournament_raw_2)
self.assertEquals(tournament_2.date, self.tournament_date_2)
self.assertEquals(tournament_2.name, self.tournament_name_2)
self.assertEquals(tournament_2.matches, self.tournament_matches_2)
self.assertEquals(tournament_2.players, self.tournament_players_2)
self.assertIsNone(self.dao.get_tournament_by_id(ObjectId()))
def test_merge_players(self):
self.dao.merge_players(source=self.player_5, target=self.player_1)
tournament_1 = self.dao.get_tournament_by_id(self.tournament_id_1)
self.assertEquals(tournament_1.id, self.tournament_id_1)
self.assertEquals(tournament_1.type, self.tournament_type_1)
self.assertEquals(tournament_1.raw, self.tournament_raw_1)
self.assertEquals(tournament_1.date, self.tournament_date_1)
self.assertEquals(tournament_1.name, self.tournament_name_1)
self.assertEquals(tournament_1.matches, self.tournament_matches_1)
self.assertEquals(tournament_1.players, self.tournament_players_1)
tournament_2 = self.dao.get_tournament_by_id(self.tournament_id_2)
self.assertEquals(tournament_2.id, self.tournament_id_2)
self.assertEquals(tournament_2.type, self.tournament_type_2)
self.assertEquals(tournament_2.raw, self.tournament_raw_2)
self.assertEquals(tournament_2.date, self.tournament_date_2)
self.assertEquals(tournament_2.name, self.tournament_name_2)
self.assertEquals(set(tournament_2.players), set(self.tournament_players_1))
self.assertEquals(len(tournament_2.matches), len(self.tournament_matches_1))
self.assertEquals(tournament_2.matches[0], self.tournament_matches_1[0])
self.assertEquals(tournament_2.matches[1], self.tournament_matches_1[1])
merged_player_aliases = ['gar', 'garr', 'pewpewu']
merged_player = self.dao.get_player_by_id(self.player_1_id)
self.assertEquals(merged_player.id, self.player_1_id)
self.assertEquals(merged_player.name, self.player_1.name)
self.assertEquals(merged_player.aliases, merged_player_aliases)
self.assertIsNone(self.dao.get_player_by_id(self.player_5_id))
def test_merge_players_none(self):
with self.assertRaises(TypeError):
self.dao.merge_players()
with self.assertRaises(TypeError):
self.dao.merge_players(source=self.player_1)
with self.assertRaises(TypeError):
self.dao.merge_players(target=self.player_1)
def test_merge_players_same_player(self):
with self.assertRaises(ValueError):
self.dao.merge_players(source=self.player_1, target=self.player_1)
# TODO
def test_merge_players_same_player_in_single_match(self):
pass
def test_get_latest_ranking(self):
latest_ranking = self.dao.get_latest_ranking()
self.assertEquals(latest_ranking.time, self.ranking_time_2)
self.assertEquals(latest_ranking.tournaments, self.tournament_ids)
rankings = latest_ranking.ranking
self.assertEquals(len(rankings), 3)
self.assertEquals(rankings[0], self.ranking_entry_1)
self.assertEquals(rankings[1], self.ranking_entry_2)
self.assertEquals(rankings[2], self.ranking_entry_4)
示例7: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
user = dao.get_all_users()[0]
now = datetime.today()
the_merge = Merge(requester_user_id=user.id,
source_player_obj_id=player_one.id,
target_player_obj_id=player_one.id,
time=now,
id=ObjectId())
with self.assertRaises(ValueError):
self.norcal_dao.merge_players(the_merge)
def test_merge_players_in_same_tourney(self):
dao = self.norcal_dao
all_players = dao.get_all_players()
player_one = all_players[0]
player_two = all_players[1]
self.assertEqual(player_one.name, u'gaR')
self.assertEqual(player_two.name, u'sfat')
user = dao.get_all_users()[0]
now = datetime.today()
orig_id = ObjectId()
the_merge = Merge(requester_user_id=user.id,
source_player_obj_id=player_one.id,
target_player_obj_id=player_one.id,
time=now,
id=orig_id)
with self.assertRaises(ValueError):
self.norcal_dao.merge_players(the_merge)
def test_get_latest_ranking(self):
latest_ranking = self.norcal_dao.get_latest_ranking()
self.assertEquals(latest_ranking.time, self.ranking_time_2)
self.assertEquals(latest_ranking.tournaments, self.tournament_ids)
rankings = latest_ranking.ranking
print rankings
self.assertEquals(len(rankings), 3)
self.assertEquals(rankings[0], self.ranking_entry_1)
self.assertEquals(rankings[1], self.ranking_entry_2)
self.assertEquals(rankings[2], self.ranking_entry_4)
def test_get_all_users(self):
users = self.norcal_dao.get_all_users()
self.assertEquals(len(users), 3)
user = users[0]
self.assertEquals(user.id, self.user_id_1)
self.assertEquals(user.username, 'user1')
self.assertEquals(user.admin_regions, self.user_admin_regions_1)
user = users[1]
self.assertEquals(user.id, self.user_id_2)
self.assertEquals(user.username, self.user_full_name_2)
self.assertEquals(user.admin_regions, self.user_admin_regions_2)
user = users[2]
self.assertEqual(user.id, self.superadmin_id)
self.assertEqual(user.username, self.superadmin_full_name)
self.assertEqual(user.admin_regions, self.superadmin_admin_regions)
示例8: TestServer
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
# spot check first and last match
match = json_data['matches'][0]
db_match = tournament.matches[0]
self.assertEquals(len(match.keys()), 4)
self.assertEquals(match['winner_id'], str(db_match.winner))
self.assertEquals(match['winner_name'], self.norcal_dao.get_player_by_id(ObjectId(match['winner_id'])).name)
self.assertEquals(match['loser_id'], str(db_match.loser))
self.assertEquals(match['loser_name'], self.norcal_dao.get_player_by_id(ObjectId(match['loser_id'])).name)
match = json_data['matches'][-1]
db_match = tournament.matches[-1]
self.assertEquals(len(match.keys()), 4)
self.assertEquals(match['winner_id'], str(db_match.winner))
self.assertEquals(match['winner_name'], self.norcal_dao.get_player_by_id(ObjectId(match['winner_id'])).name)
self.assertEquals(match['loser_id'], str(db_match.loser))
self.assertEquals(match['loser_name'], self.norcal_dao.get_player_by_id(ObjectId(match['loser_id'])).name)
# sanity tests for another region
tournament = self.texas_dao.get_all_tournaments()[0]
data = self.app.get('/texas/tournaments/' + str(tournament.id)).data
json_data = json.loads(data)
self.assertEquals(len(json_data.keys()), 6)
self.assertEquals(json_data['id'], str(tournament.id))
self.assertEquals(json_data['name'], 'FX Biweekly 6')
self.assertEquals(json_data['type'], 'tio')
self.assertEquals(json_data['date'], str(tournament.date))
self.assertEquals(len(json_data['players']), len(tournament.players))
self.assertEquals(len(json_data['matches']), len(tournament.matches))
def test_get_rankings(self):
data = self.app.get('/norcal/rankings').data
json_data = json.loads(data)
db_ranking = self.norcal_dao.get_latest_ranking()
self.assertEquals(len(json_data.keys()), 3)
self.assertEquals(json_data['time'], str(db_ranking.time))
self.assertEquals(json_data['tournaments'], [str(t) for t in db_ranking.tournaments])
self.assertEquals(len(json_data['ranking']), len(db_ranking.ranking))
# spot check first and last ranking entries
ranking_entry = json_data['ranking'][0]
db_ranking_entry = db_ranking.ranking[0]
self.assertEquals(len(ranking_entry.keys()), 4)
self.assertEquals(ranking_entry['rank'], db_ranking_entry.rank)
self.assertEquals(ranking_entry['id'], str(db_ranking_entry.player))
self.assertEquals(ranking_entry['name'], self.norcal_dao.get_player_by_id(db_ranking_entry.player).name)
self.assertTrue(ranking_entry['rating'] > 33.2)
ranking_entry = json_data['ranking'][-1]
db_ranking_entry = db_ranking.ranking[-1]
self.assertEquals(len(ranking_entry.keys()), 4)
self.assertEquals(ranking_entry['rank'], db_ranking_entry.rank)
self.assertEquals(ranking_entry['id'], str(db_ranking_entry.player))
self.assertEquals(ranking_entry['name'], self.norcal_dao.get_player_by_id(db_ranking_entry.player).name)
self.assertTrue(ranking_entry['rating'] > -3.86)
# TODO write this test, or delete the endpoint
def test_get_rankings_generate_new(self):
pass
def test_get_matches(self):
player = self.norcal_dao.get_player_by_alias('gar')
data = self.app.get('/norcal/matches/' + str(player.id)).data
json_data = json.loads(data)
self.assertEquals(len(json_data.keys()), 4)
示例9: TestServer
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
tournament = self.norcal_dao.get_tournament_by_id(tournament.id)
self.assertEquals(tournament.regions, [])
self.assertEquals(len(json_data.keys()), 7)
self.assertEquals(json_data['regions'], [])
@patch('server.get_user_from_access_token')
def test_delete_tournament_region_does_not_exist(self, mock_get_user_from_access_token):
mock_get_user_from_access_token.return_value = self.user
tournament = self.norcal_dao.get_all_tournaments(regions=['norcal'])[0]
self.assertEquals(tournament.regions, ['norcal'])
response = self.app.delete('/norcal/tournaments/' + str(tournament.id) + '/region/nyc')
json_data = json.loads(response.data)
tournament = self.norcal_dao.get_tournament_by_id(tournament.id)
self.assertEquals(tournament.regions, ['norcal'])
self.assertEquals(len(json_data.keys()), 7)
self.assertEquals(json_data['regions'], ['norcal'])
@patch('server.get_user_from_access_token')
def test_delete_tournament_region_invalid_permissions(self, mock_get_user_from_access_token):
mock_get_user_from_access_token.return_value = self.user
tournament = self.norcal_dao.get_all_tournaments(regions=['norcal'])[0]
response = self.app.delete('/norcal/tournaments/' + str(tournament.id) + '/region/texas')
self.assertEquals(response.status_code, 403)
self.assertEquals(response.data, '"Permission denied"')
def test_get_rankings(self):
data = self.app.get('/norcal/rankings').data
json_data = json.loads(data)
db_ranking = self.norcal_dao.get_latest_ranking()
self.assertEquals(len(json_data.keys()), 4)
self.assertEquals(json_data['time'], str(db_ranking.time))
self.assertEquals(json_data['tournaments'], [str(t) for t in db_ranking.tournaments])
self.assertEquals(json_data['region'], self.norcal_dao.region_id)
self.assertEquals(len(json_data['ranking']), len(db_ranking.ranking))
# spot check first and last ranking entries
ranking_entry = json_data['ranking'][0]
db_ranking_entry = db_ranking.ranking[0]
self.assertEquals(len(ranking_entry.keys()), 4)
self.assertEquals(ranking_entry['rank'], db_ranking_entry.rank)
self.assertEquals(ranking_entry['id'], str(db_ranking_entry.player))
self.assertEquals(ranking_entry['name'], self.norcal_dao.get_player_by_id(db_ranking_entry.player).name)
self.assertTrue(ranking_entry['rating'] > 33.2)
ranking_entry = json_data['ranking'][-1]
db_ranking_entry = db_ranking.ranking[-1]
self.assertEquals(len(ranking_entry.keys()), 4)
self.assertEquals(ranking_entry['rank'], db_ranking_entry.rank)
self.assertEquals(ranking_entry['id'], str(db_ranking_entry.player))
self.assertEquals(ranking_entry['name'], self.norcal_dao.get_player_by_id(db_ranking_entry.player).name)
self.assertTrue(ranking_entry['rating'] > -3.86)
def test_get_rankings_ignore_invalid_player_id(self):
# delete a player that exists in the rankings
db_ranking = self.norcal_dao.get_latest_ranking()
player_to_delete = self.norcal_dao.get_player_by_id(db_ranking.ranking[1].player)
self.norcal_dao.delete_player(player_to_delete)
data = self.app.get('/norcal/rankings').data
json_data = json.loads(data)
db_ranking = self.norcal_dao.get_latest_ranking()
示例10: TestRankings
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_latest_ranking [as 别名]
#.........这里部分代码省略.........
for player in self.players:
self.dao.add_player(player)
for tournament in self.tournaments:
self.dao.insert_tournament(tournament)
# all tournaments are within the active range and will be included
@patch('rankings.datetime', spec=True)
def test_generate_rankings(self, mock_datetime):
now = datetime(2013, 10, 17)
mock_datetime.now.return_value = now
# assert rankings before they get reset
self.assertEquals(self.dao.get_player_by_id(self.player_1_id).rating, self.player_1.rating)
self.assertEquals(self.dao.get_player_by_id(self.player_2_id).rating, self.player_2.rating)
self.assertEquals(self.dao.get_player_by_id(self.player_3_id).rating, self.player_3.rating)
self.assertEquals(self.dao.get_player_by_id(self.player_4_id).rating, self.player_4.rating)
self.assertEquals(self.dao.get_player_by_id(self.player_5_id).rating, self.player_5.rating)
rankings.generate_ranking(self.dao)
# assert rankings after ranking calculation
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).rating.trueskill_rating.mu,
28.458, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).rating.trueskill_rating.sigma,
7.201, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).rating.trueskill_rating.mu,
18.043, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).rating.trueskill_rating.sigma,
6.464, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).rating.trueskill_rating.mu,
31.230, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).rating.trueskill_rating.sigma,
6.523, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).rating.trueskill_rating.mu,
18.770, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).rating.trueskill_rating.sigma,
6.523, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).rating.trueskill_rating.mu,
29.396, delta=delta)
self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).rating.trueskill_rating.sigma,
7.171, delta=delta)
ranking = self.dao.get_latest_ranking()
self.assertEquals(ranking.time, now)
self.assertEquals(set(ranking.tournaments), set(self.tournament_ids))
ranking_list = ranking.ranking
# the ranking should not have any excluded players
self.assertEquals(len(ranking_list), 4)
entry = ranking_list[0]
self.assertEquals(entry.rank, 1)
self.assertEquals(entry.player, self.player_5_id)
self.assertAlmostEquals(entry.rating, 7.881, delta=delta)
entry = ranking_list[1]
self.assertEquals(entry.rank, 2)
self.assertEquals(entry.player, self.player_1_id)
self.assertAlmostEquals(entry.rating, 6.857, delta=delta)
entry = ranking_list[2]
self.assertEquals(entry.rank, 3)
self.assertEquals(entry.player, self.player_4_id)
self.assertAlmostEquals(entry.rating, -.800, delta=delta)
entry = ranking_list[3]
self.assertEquals(entry.rank, 4)
self.assertEquals(entry.player, self.player_2_id)
self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
# players that only played in the first tournament will be excluded for inactivity
@patch('rankings.datetime', spec=True)
def test_generate_rankings_excluded_for_inactivity(self, mock_datetime):
now = datetime(2013, 11, 25)
mock_datetime.now.return_value = now
rankings.generate_ranking(self.dao)
ranking = self.dao.get_latest_ranking()
ranking_list = ranking.ranking
self.assertEquals(len(ranking_list), 3)
entry = ranking_list[0]
self.assertEquals(entry.rank, 1)
self.assertEquals(entry.player, self.player_1_id)
self.assertAlmostEquals(entry.rating, 6.857, delta=delta)
entry = ranking_list[1]
self.assertEquals(entry.rank, 2)
self.assertEquals(entry.player, self.player_4_id)
self.assertAlmostEquals(entry.rating, -.800, delta=delta)
entry = ranking_list[2]
self.assertEquals(entry.rank, 3)
self.assertEquals(entry.player, self.player_2_id)
self.assertAlmostEquals(entry.rating, -1.349, delta=delta)