本文整理汇总了Python中dao.Dao.get_player_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.get_player_by_id方法的具体用法?Python Dao.get_player_by_id怎么用?Python Dao.get_player_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.get_player_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def post(self, region):
dao = Dao(region, mongo_client=mongo_client)
requesting_user = get_user_from_access_token(request.headers, dao)
if not requesting_user.admin_regions: #wow, such auth
return "user is not an admin", 403
args = merges_put_parser.parse_args() #parse args
try:
base_player_id = ObjectId(args['base_player_id'])
to_be_merged_player_id = ObjectId(args['to_be_merged_player_id'])
except:
return "invalid ids, that wasn't an ObjectID", 400
# the above should validate that we have real objectIDs
# now lets validate that both of those players exist
if not dao.get_player_by_id(base_player_id):
return "base_player not found", 400
if not dao.get_player_by_id(to_be_merged_player_id):
return "to_be_merged_player not found", 400
#get curr time
now = datetime.now()
#create a new merge object
the_merge = Merge(requesting_user.id, base_player_id, to_be_merged_player_id, now)
#store it in the dao
merge_id = dao.insert_pending_merge(the_merge)
string_rep = str(merge_id)
return_dict = {'id': string_rep}
return return_dict, 200
示例2: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def delete(self, region, id, region_to_change):
dao = Dao(region, mongo_client=mongo_client)
user = get_user_from_access_token(request.headers, dao)
if not is_user_admin_for_region(user, region_to_change):
return 'Permission denied', 403
player = dao.get_player_by_id(ObjectId(id))
if region_to_change in player.regions:
player.regions.remove(region_to_change)
dao.update_player(player)
return_dict = dao.get_player_by_id(player.id).get_json_dict()
convert_object_id(return_dict)
return return_dict
示例3: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def get(self, region):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not user.admin_regions:
return "user is not an admin", 403
return_dict = {}
return_dict['merges'] = [m.dump(context='web')
for m in dao.get_all_merges()]
for merge in return_dict['merges']:
# TODO: store names in merge object
source_player = dao.get_player_by_id(merge['source_player_obj_id'])
target_player = dao.get_player_by_id(merge['target_player_obj_id'])
if source_player is not None and target_player is not None:
merge['source_player_name'] = source_player.name
merge['target_player_name'] = target_player.name
merge['requester_name'] = user.username
return return_dict
示例4: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def put(self, region, id, region_to_change):
dao = Dao(region, mongo_client=mongo_client)
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not is_user_admin_for_region(user, region_to_change):
return 'Permission denied', 403
player = dao.get_player_by_id(ObjectId(id))
if not region_to_change in player.regions:
player.regions.append(region_to_change)
dao.update_player(player)
return_dict = dao.get_player_by_id(player.id).get_json_dict()
convert_object_id(return_dict)
return return_dict
示例5: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def post(self, region, id):
print "finalize tournament post"
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
pending_tournament = None
try:
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
except:
return 'Invalid ObjectID', 400
if not pending_tournament:
return 'No pending tournament found with that id.', 400
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not is_user_admin_for_regions(user, pending_tournament.regions):
return 'Permission denied', 403
# Make sure multiple player aliases don't map to a single player ID.
player_ids = set()
for mapping in pending_tournament.alias_to_id_map:
if mapping.player_id is not None:
if mapping.player_id in player_ids:
return "Player id %s is already mapped" % mapping.player_id, 400
else:
player_ids.add(mapping.player_id)
new_player_names = []
for mapping in pending_tournament.alias_to_id_map:
if mapping.player_id is None:
new_player_names.append(mapping.player_alias)
for player_name in new_player_names:
player = M.Player.create_with_default_values(player_name, region)
player_id = dao.insert_player(player)
pending_tournament.set_alias_id_mapping(player_name, player_id)
# validate players in this tournament
for mapping in pending_tournament.alias_to_id_map:
try:
player_id = mapping.player_id
# TODO: reduce queries to DB by batching
player = dao.get_player_by_id(player_id)
if player.merged:
return "Player {} has already been merged".format(player.name), 400
except:
return "Not all player ids are valid", 400
try:
dao.update_pending_tournament(pending_tournament)
tournament = M.Tournament.from_pending_tournament(
pending_tournament)
tournament_id = dao.insert_tournament(tournament)
dao.delete_pending_tournament(pending_tournament)
return {"success": True, "tournament_id": str(tournament_id)}
except ValueError as e:
print e
return 'Not all player aliases in this pending tournament have been mapped to player ids.', 400
except:
return 'Dao threw an error somewhere', 400
示例6: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
player = dao.get_player_by_id(ObjectId(id))
return_dict = player.get_json_dict()
convert_object_id(return_dict)
return return_dict
示例7: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def post(self, region):
dao = Dao(region, mongo_client=mongo_client)
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not user.admin_regions: #wow, such auth -- fixed, now we actually do more auth checking later
return "user is not an admin", 403
args = merges_put_parser.parse_args() #parse args
try:
base_player_id = ObjectId(args['base_player_id'])
to_be_merged_player_id = ObjectId(args['to_be_merged_player_id'])
except:
return "invalid ids, that wasn't an ObjectID", 400
# the above should validate that we have real objectIDs
# now lets validate that both of those players exist
player1 = dao.get_player_by_id(base_player_id)
if not player1:
return "base_player not found", 400
player2 = dao.get_player_by_id(to_be_merged_player_id)
if not player2:
return "to_be_merged_player not found", 400
if not is_user_admin_for_regions(user, player1.regions):
return "Permission denied", 403
if not is_user_admin_for_regions(user, player2.regions):
return "Permission denied", 403
#get curr time
now = datetime.now()
#create a new merge object
the_merge = Merge(requesting_user.id, base_player_id, to_be_merged_player_id, now)
#store it in the dao
merge_id = dao.insert_pending_merge(the_merge)
string_rep = str(merge_id)
return_dict = {'id': string_rep}
return return_dict, 200
示例8: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def put(self, region):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not user.admin_regions:
return "user is not an admin", 403
args = merges_put_parser.parse_args()
try:
print args
source_player_id = ObjectId(args['source_player_id'])
target_player_id = ObjectId(args['target_player_id'])
except:
return "invalid ids, that wasn't an ObjectID", 400
# the above should validate that we have real objectIDs
# now lets validate that both of those players exist
player1 = dao.get_player_by_id(source_player_id)
player2 = dao.get_player_by_id(target_player_id)
if not player1:
return "source_player not found", 400
if not player2:
return "target_player not found", 400
if not is_user_admin_for_regions(user, player1.regions):
return "Permission denied", 403
if not is_user_admin_for_regions(user, player2.regions):
return "Permission denied", 403
# get curr time
now = datetime.now()
the_merge = M.Merge(requester_user_id=user.id,
source_player_obj_id=source_player_id,
target_player_obj_id=target_player_id,
time=now,
id=ObjectId())
try:
dao.insert_merge(the_merge)
return_dict = {'status': "success", 'id': str(the_merge.id)}
return return_dict, 200
except Exception as e:
print 'error merging players: ' + str(e)
return 'error merging players: ' + str(e), 400
示例9: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
def delete(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
try:
player = dao.get_player_by_id(ObjectId(id))
except:
return 'Invalid ObjectID', 400
if not player:
return "No player found with that region/id.", 404
if not is_user_admin_for_regions(user, player.regions):
return 'Permission denied', 403
if dao.get_all_tournaments(players=[player]):
return 'Player still has matches', 400
dao.delete_player(player)
return {"success": True}
示例10: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [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
示例11: TestRankings
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
#.........这里部分代码省略.........
type=self.tournament_type_1,
raw=self.tournament_raw_1,
date=self.tournament_date_1,
name=self.tournament_name_1,
players=self.tournament_players_1,
matches=self.tournament_matches_1,
regions=self.tournament_regions_1,
id=self.tournament_id_1)
self.tournament_2 = Tournament(
type=self.tournament_type_2,
raw=self.tournament_raw_2,
date=self.tournament_date_2,
name=self.tournament_name_2,
players=self.tournament_players_2,
matches=self.tournament_matches_2,
regions=self.tournament_regions_2,
id=self.tournament_id_2)
self.tournament_ids = [self.tournament_id_1, self.tournament_id_2]
self.tournaments = [self.tournament_1, self.tournament_2]
for player in self.players:
self.dao.insert_player(player)
for tournament in self.tournaments:
self.dao.insert_tournament(tournament)
# all tournaments are within the active range and will be included
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)
示例12: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
#.........这里部分代码省略.........
self.norcal_dao.insert_tournament(tournament)
for pending_tournament in self.pending_tournaments:
self.norcal_dao.insert_pending_tournament(pending_tournament)
for ranking in self.rankings:
self.norcal_dao.insert_ranking(ranking)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_init_with_invalid_region(self):
# create a dao with an existing region
Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
# create a dao with a new region
with self.assertRaises(RegionNotFoundException):
Dao('newregion', self.mongo_client, database_name=DATABASE_NAME)
def test_get_all_regions(self):
# add another region
region = Region('newregion', 'New Region')
Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)
regions = Dao.get_all_regions(self.mongo_client, database_name=DATABASE_NAME)
self.assertEquals(len(regions), 3)
self.assertEquals(regions[0], region)
self.assertEquals(regions[1], self.region_1)
self.assertEquals(regions[2], self.region_2)
def test_get_player_by_id(self):
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_2_id), self.player_2)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_3_id), self.player_3)
self.assertIsNone(self.norcal_dao.get_player_by_id(ObjectId()))
def test_get_player_by_alias(self):
self.assertEquals(self.norcal_dao.get_player_by_alias('gar'), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_alias('GAR'), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_alias('garr'), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_alias('sfat'), self.player_2)
self.assertEquals(self.norcal_dao.get_player_by_alias('miom | sfat'), self.player_2)
self.assertIsNone(self.norcal_dao.get_player_by_alias('mango'))
self.assertIsNone(self.norcal_dao.get_player_by_alias('miom|sfat'))
self.assertIsNone(self.norcal_dao.get_player_by_alias(''))
def test_get_players_by_alias_from_all_regions(self):
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('gar'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('GAR'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('garr'), [self.player_1])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('sfat'), [self.player_2])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('miom | sfat'), [self.player_2])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('mango'), [self.player_3])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('miom|sfat'), [])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(''), [])
def test_get_player_id_map_from_player_aliases(self):
aliases = ['GAR', 'sfat', 'asdf', 'mango']
expected_map = [
{'player_alias': 'GAR', 'player_id': self.player_1_id},
{'player_alias': 'sfat', 'player_id': self.player_2_id},
示例13: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
#.........这里部分代码省略.........
self.ranking_time_2 = datetime(2013, 4, 21)
self.ranking_1 = Ranking(self.ranking_time_1, self.tournament_ids,
[self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_3])
self.ranking_2 = Ranking(self.ranking_time_2, self.tournament_ids,
[self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_4])
self.rankings = [self.ranking_1, self.ranking_2]
for player in self.players:
self.dao.add_player(player)
for tournament in self.tournaments:
self.dao.insert_tournament(tournament)
for ranking in self.rankings:
self.dao.insert_ranking(ranking)
def test_init_with_invalid_region(self):
print Dao.get_all_regions(mongo_client=self.mongo_client)
# create a dao with an existing region
Dao(self.region, mongo_client=self.mongo_client, new=False)
# create a dao with a new region
with self.assertRaises(RegionNotFoundException):
Dao('newregion', mongo_client=self.mongo_client, new=False)
def test_get_all_regions(self):
# add another region
region = 'newregion'
Dao(region, mongo_client=self.mongo_client, new=True)
self.assertEquals(set(Dao.get_all_regions(mongo_client=self.mongo_client)), set([self.region, region]))
def test_get_player_by_id(self):
self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
self.assertEquals(self.dao.get_player_by_id(self.player_2_id), self.player_2)
self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)
self.assertIsNone(self.dao.get_player_by_id(ObjectId()))
def test_get_player_by_alias(self):
self.assertEquals(self.dao.get_player_by_alias('gar'), self.player_1)
self.assertEquals(self.dao.get_player_by_alias('GAR'), self.player_1)
self.assertEquals(self.dao.get_player_by_alias('garr'), self.player_1)
self.assertEquals(self.dao.get_player_by_alias('sfat'), self.player_2)
self.assertEquals(self.dao.get_player_by_alias('miom | sfat'), self.player_2)
self.assertEquals(self.dao.get_player_by_alias('mango'), self.player_3)
self.assertIsNone(self.dao.get_player_by_alias('miom|sfat'))
self.assertIsNone(self.dao.get_player_by_alias(''))
def test_get_all_players(self):
self.assertEquals(self.dao.get_all_players(), [self.player_1, self.player_3, self.player_2])
def test_add_player_duplicate(self):
with self.assertRaises(DuplicateKeyError):
self.dao.add_player(self.player_1)
def test_delete_player(self):
self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
self.assertEquals(self.dao.get_player_by_id(self.player_2_id), self.player_2)
self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)
self.dao.delete_player(self.player_2)
self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
self.assertIsNone(self.dao.get_player_by_id(self.player_2_id))
self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)
示例14: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
#.........这里部分代码省略.........
for ranking in self.rankings:
self.norcal_dao.insert_ranking(ranking)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_init_with_invalid_region(self):
# create a dao with an existing region
Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
# create a dao with a non existant region, should return none
self.assertIsNone(Dao('newregion', self.mongo_client,
database_name=DATABASE_NAME))
def test_get_all_regions(self):
# add another region
region = Region(id='newregion', display_name='New Region')
Dao.insert_region(region, self.mongo_client,
database_name=DATABASE_NAME)
regions = Dao.get_all_regions(
self.mongo_client, database_name=DATABASE_NAME)
self.assertEquals(len(regions), 3)
self.assertEquals(regions[0], region)
self.assertEquals(regions[1], self.region_1)
self.assertEquals(regions[2], self.region_2)
def test_get_player_by_id(self):
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_2_id), self.player_2)
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_3_id), self.player_3)
self.assertIsNone(self.norcal_dao.get_player_by_id(ObjectId()))
def test_get_player_by_alias(self):
self.assertEquals(
self.norcal_dao.get_player_by_alias('gar'), self.player_1)
self.assertEquals(
self.norcal_dao.get_player_by_alias('GAR'), self.player_1)
self.assertEquals(
self.norcal_dao.get_player_by_alias('garr'), self.player_1)
self.assertEquals(
self.norcal_dao.get_player_by_alias('sfat'), self.player_2)
self.assertEquals(self.norcal_dao.get_player_by_alias(
'miom | sfat'), self.player_2)
self.assertIsNone(self.norcal_dao.get_player_by_alias('mango'))
self.assertIsNone(self.norcal_dao.get_player_by_alias('miom|sfat'))
self.assertIsNone(self.norcal_dao.get_player_by_alias(''))
def test_get_players_by_alias_from_all_regions(self):
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(
'gar'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(
'GAR'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(
'garr'), [self.player_1])
self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(
示例15: TestRankings
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_player_by_id [as 别名]
class TestRankings(unittest.TestCase):
def setUp(self):
self.region = 'test'
self.mongo_client = mongomock.MongoClient()
self.dao = Dao(self.region, mongo_client=self.mongo_client, new=True)
self.player_1_id = ObjectId()
self.player_2_id = ObjectId()
self.player_3_id = ObjectId()
self.player_4_id = ObjectId()
self.player_5_id = ObjectId()
self.player_1 = Player('gaR', ['gar', 'garr'], TrueskillRating(), False, id=self.player_1_id)
self.player_2 = Player('sfat', ['sfat', 'miom | sfat'], TrueskillRating(), False, id=self.player_2_id)
self.player_3 = Player('mango', ['mango'],
TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3)),
True, id=self.player_3_id)
self.player_4 = Player('shroomed', ['shroomed'], TrueskillRating(), False, id=self.player_4_id)
self.player_5 = Player('pewpewu', ['pewpewu'], TrueskillRating(), False, id=self.player_5_id)
self.players = [self.player_1, self.player_2, self.player_3, self.player_4, self.player_5]
self.tournament_id_1 = ObjectId()
self.tournament_type_1 = 'tio'
self.tournament_raw_1 = 'raw1'
self.tournament_date_1 = datetime(2013, 10, 16)
self.tournament_name_1 = 'tournament 1'
self.tournament_players_1 = [self.player_1_id, self.player_2_id, self.player_3_id, self.player_4_id]
self.tournament_matches_1 = [
MatchResult(winner=self.player_1_id, loser=self.player_2_id),
MatchResult(winner=self.player_3_id, loser=self.player_4_id)
]
# tournament 2 is earlier than tournament 1, but inserted after
self.tournament_id_2 = ObjectId()
self.tournament_type_2 = 'challonge'
self.tournament_raw_2 = 'raw2'
self.tournament_date_2 = datetime(2013, 10, 10)
self.tournament_name_2 = 'tournament 2'
self.tournament_players_2 = [self.player_5_id, self.player_2_id, self.player_3_id, self.player_4_id]
self.tournament_matches_2 = [
MatchResult(winner=self.player_5_id, loser=self.player_2_id),
MatchResult(winner=self.player_3_id, loser=self.player_4_id)
]
self.tournament_1 = Tournament(self.tournament_type_1,
self.tournament_raw_1,
self.tournament_date_1,
self.tournament_name_1,
self.tournament_players_1,
self.tournament_matches_1,
id=self.tournament_id_1)
self.tournament_2 = Tournament(self.tournament_type_2,
self.tournament_raw_2,
self.tournament_date_2,
self.tournament_name_2,
self.tournament_players_2,
self.tournament_matches_2,
id=self.tournament_id_2)
self.tournament_ids = [self.tournament_id_1, self.tournament_id_2]
self.tournaments = [self.tournament_1, self.tournament_2]
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,
#.........这里部分代码省略.........