本文整理汇总了Python中dao.Dao.merge_players方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.merge_players方法的具体用法?Python Dao.merge_players怎么用?Python Dao.merge_players使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.merge_players方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bulk_alias_merge
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import merge_players [as 别名]
def bulk_alias_merge(path, region):
config = parse_config()
username = config.get('database', 'user')
host = config.get('database', 'host')
auth_db = config.get('database', 'auth_db')
password = getpass.getpass()
mongo_client = MongoClient(host='mongodb://%s:%[email protected]%s/%s' % (username, password, host, auth_db))
dao = Dao(region, mongo_client=mongo_client)
with open(path) as f:
reader = csv.reader(f)
for row in reader:
target_alias = row[0]
db_target = dao.get_player_by_alias(target_alias)
if db_target is None:
print '%s is not a valid alias' % target_alias
continue
for source_alias in row[1:]:
source_alias = source_alias.strip()
if source_alias:
db_source = dao.get_player_by_alias(source_alias)
if db_source is None:
print '%s is not a valid alias' % source_alias
continue
print source_alias, '->', target_alias
dao.merge_players(source=db_source, target=db_target)
示例2: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import merge_players [as 别名]
#.........这里部分代码省略.........
self.assertEquals(tournament.matches, self.tournament_matches_2)
self.assertEquals(tournament.players, self.tournament_players_2)
self.assertEquals(tournament.regions, self.tournament_regions_2)
def test_get_tournament_by_id(self):
tournament_1 = self.norcal_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)
self.assertEquals(tournament_1.regions, self.tournament_regions_1)
tournament_2 = self.norcal_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.assertEquals(tournament_2.regions, self.tournament_regions_2)
self.assertIsNone(self.norcal_dao.get_tournament_by_id(ObjectId()))
def test_get_players_with_similar_alias(self):
self.assertEquals(self.norcal_dao.get_players_with_similar_alias('gar'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_with_similar_alias('GAR'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_with_similar_alias('g a r'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_with_similar_alias('garpr | gar'), [self.player_1, self.player_3])
def test_merge_players(self):
self.norcal_dao.merge_players(source=self.player_5, target=self.player_1)
tournament_1 = self.norcal_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)
self.assertEquals(tournament_1.regions, self.tournament_regions_1)
tournament_2 = self.norcal_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])
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)
示例3: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import merge_players [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)
示例4: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import merge_players [as 别名]
#.........这里部分代码省略.........
self.assertIsNone(self.norcal_dao.get_tournament_by_id(ObjectId()))
def test_get_players_with_similar_alias(self):
self.assertEquals(self.norcal_dao.get_players_with_similar_alias(
'gar'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_with_similar_alias(
'GAR'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_with_similar_alias(
'g a r'), [self.player_1, self.player_3])
self.assertEquals(self.norcal_dao.get_players_with_similar_alias(
'garpr | gar'), [self.player_1, self.player_3])
dao = self.norcal_dao
self.assertTrue(any(
player.name == "gaR" for player in dao.get_players_with_similar_alias("1 1 gar")))
self.assertTrue(any(
player.name == "gaR" for player in dao.get_players_with_similar_alias("1\t1\tgar")))
self.assertTrue(any(
player.name == "gaR" for player in dao.get_players_with_similar_alias("p1s1 gar")))
self.assertTrue(any(
player.name == "gaR" for player in dao.get_players_with_similar_alias("GOOG| gar")))
self.assertTrue(any(
player.name == "gaR" for player in dao.get_players_with_similar_alias("GOOG | gar")))
self.assertTrue(any(
player.name == "gaR" for player in dao.get_players_with_similar_alias("p1s2 GOOG| gar")))
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias(
"garpr goog youtube gar")))
# TODO: add more tests for merging players
# this is currently covered by test_get_and_insert_merge
# def test_merge_players(self):
# pass
def test_merge_players_same_player(self):
dao = self.norcal_dao
all_players = dao.get_all_players()
player_one = all_players[0]
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)