Esempio n. 1
0
    def test_from_pending_tournament_throws_exception(self):
        # we need MatchResults with aliases (instead of IDs)
        match_1 = AliasMatch(winner=self.player_1.name,
                             loser=self.player_2.name)
        match_2 = AliasMatch(winner=self.player_3.name,
                             loser=self.player_4.name)

        player_aliases = [p.name for p in self.players]
        matches = [match_1, match_2]
        alias_to_id_map = [
            AliasMapping(player_alias=self.player_1.name, player_id=None)
        ]
        pending_tournament = PendingTournament(name=self.name,
                                               type=self.type,
                                               date=self.date,
                                               regions=['norcal'],
                                               raw_id=self.raw_id,
                                               players=player_aliases,
                                               matches=matches,
                                               alias_to_id_map=alias_to_id_map)

        with self.assertRaises(Exception) as e:
            Tournament.from_pending_tournament(pending_tournament)

        self.assertTrue('Alias gar has no ID in map' in str(e.exception))
Esempio n. 2
0
    def test_from_pending_tournament(self):
        # we need MatchResults with aliases (instead of IDs)
        match_1 = AliasMatch(winner=self.player_1.name,
                             loser=self.player_2.name)
        match_2 = AliasMatch(winner=self.player_3.name,
                             loser=self.player_4.name)

        player_aliases = [p.name for p in self.players]
        matches = [match_1, match_2]
        pending_tournament = PendingTournament(
            name=self.name,
            type=self.type,
            date=self.date,
            raw_id=self.raw_id,
            regions=['norcal'],
            players=player_aliases,
            matches=matches,
            alias_to_id_map=self.alias_to_id_map)

        tournament = Tournament.from_pending_tournament(pending_tournament)

        self.assertIsNone(tournament.id)
        self.assertEqual(tournament.type, self.type)
        self.assertEqual(tournament.raw_id, self.raw_id)
        self.assertEqual(tournament.date, self.date)
        self.assertEqual(tournament.name, self.name)
        self.assertEqual(tournament.matches[0].winner, self.matches[0].winner)
        self.assertEqual(tournament.matches[0].loser, self.matches[0].loser)
        self.assertEqual(tournament.matches[1].winner, self.matches[1].winner)
        self.assertEqual(tournament.matches[1].loser, self.matches[1].loser)
        self.assertEqual(tournament.players, self.player_ids)
        self.assertEqual(tournament.regions, ['norcal'])
Esempio n. 3
0
    def test_get_matches(self):
        matches = self.scraper.get_matches()
        self.assertEquals(len(matches), 81)
        self.assertEquals(matches[0], AliasMatch(winner='Tiamat', loser='Sharkboi'))
        self.assertEquals(matches[-1], AliasMatch(winner='Shroomed', loser='GC | Silentwolf'))
        self.assertEquals(matches[-2], AliasMatch(winner='GC | Silentwolf', loser='Shroomed'))
        self.assertEquals(matches[-3], AliasMatch(winner='GC | Silentwolf', loser='MIOM | SFAT'))

        # make sure none of the matches have a None
        for m in matches:
            self.assertIsNotNone(m.winner)
            self.assertIsNotNone(m.loser)
Esempio n. 4
0
    def test_get_matches_one_grand_finals_set(self):
        self.scraper = TioScraper.from_file('test/test_scraper/data/2.tio', BRACKET_NAME)
        matches = self.scraper.get_matches()

        self.assertEquals(len(matches), 116)

        self.assertEquals(matches[0], AliasMatch(winner='spookyman', loser='razr'))

        # grand finals set 1
        self.assertEquals(matches[-1], AliasMatch(winner='GC|silent wolf', loser='MIOM|SFAT'))

        # losers finals
        self.assertEquals(matches[-2], AliasMatch(winner='MIOM|SFAT', loser='shroomed'))
Esempio n. 5
0
    def test_get_matches(self):
        matches = self.scraper.get_matches()
        self.assertEquals(len(matches), 117)

        self.assertEquals(matches[0], AliasMatch(winner='spookyman', loser='razr'))

        # grand finals set 2
        self.assertEquals(matches[-1], AliasMatch(winner='GC|silent wolf', loser='MIOM|SFAT'))

        # grand finals set 1
        self.assertEquals(matches[-2], AliasMatch(winner='MIOM|SFAT', loser='GC|silent wolf'))

        # losers finals
        self.assertEquals(matches[-3], AliasMatch(winner='MIOM|SFAT', loser='shroomed'))
Esempio n. 6
0
    def get_matches(self):
        """
        :return: the list of AliasMatch objects that represents every match
        played in the given bracket, including who won and who lost
        """

        return_matches = []
        for match in self.matches:
            winner = self.player_lookup.get(match.winner_id)
            loser = self.player_lookup.get(match.loser_id)

            if winner is None:
                print 'Error: id {} not found in player list'.format(
                    match.winner_id)
                continue

            if loser is None:
                print 'Error: id {} not found in player list'.format(
                    match.loser_id)
                continue

            return_match = AliasMatch(winner=winner.smash_tag,
                                      loser=loser.smash_tag)
            return_matches.append(return_match)

        return return_matches
Esempio n. 7
0
    def get_matches(self):
        # sometimes challonge seems to use the "group_player_ids" parameter of "participant" instead
        # of the "id" parameter of "participant" in the "matches" api.
        # not sure exactly when this happens, but the following code checks for both
        player_map = dict()
        for p in self.get_raw()['participants']:
            if p['participant'].get('name'):
                player_name = p['participant']['name'].strip()
            else:
                player_name = p['participant'].get('username',
                                                   '<unknown>').strip()
            player_map[p['participant'].get('id')] = player_name
            if p['participant'].get('group_player_ids'):
                for gpid in p['participant']['group_player_ids']:
                    player_map[gpid] = player_name

        matches = []
        for m in self.get_raw()['matches']:
            m = m['match']

            set_count = m['scores_csv']
            winner_id = m['winner_id']
            loser_id = m['loser_id']
            if winner_id is not None and loser_id is not None:
                winner = player_map[winner_id]
                loser = player_map[loser_id]
                match_result = AliasMatch(winner=winner, loser=loser)
                matches.append(match_result)
        return matches
Esempio n. 8
0
    def get_matches(self):
        player_map = dict((p.ID.text, p.Nickname.text.strip())
                          for p in self.soup.find_all('Player'))

        bracket = None
        for b in self.soup.find_all('Game'):
            if b.Name.text == self.bracket_name:
                bracket = b
                break

        if bracket is None:
            raise ValueError('Bracket name %s not found!' % self.bracket_name)

        matches = []
        grand_finals_first_set = None
        grand_finals_second_set = None
        for match in bracket.find_all('Match'):
            player_1_id = match.Player1.text
            player_2_id = match.Player2.text
            winner_id = match.Winner.text
            loser_id = player_1_id if winner_id == player_2_id else player_2_id

            try:
                winner = player_map[winner_id]
                loser = player_map[loser_id]
                match_result = AliasMatch(winner=winner, loser=loser)

                if match.IsChampionship.text == 'True':
                    grand_finals_first_set = match_result
                elif match.IsSecondChampionship.text == 'True':
                    grand_finals_second_set = match_result
                else:
                    matches.append(match_result)
            except KeyError:
                pass
                # reduce console spam for now
                # TODO: log this
                # print 'Could not find player for ids', player_1_id,
                # player_2_id

        if grand_finals_first_set is not None:
            matches.append(grand_finals_first_set)

        if grand_finals_second_set is not None:
            matches.append(grand_finals_second_set)

        return matches
Esempio n. 9
0
    def get_matches(self):
        # sometimes challonge seems to use the "group_player_ids" parameter of "participant" instead
        # of the "id" parameter of "participant" in the "matches" api.
        # not sure exactly when this happens, but the following code checks for both
        player_map = dict()
        for p in self.get_raw()['participants']:
            if p['participant'].get('name'):
                player_name = p['participant']['name'].strip()
            else:
                player_name = p['participant'].get('username',
                                                   '<unknown>').strip()
            player_map[p['participant'].get('id')] = player_name
            if p['participant'].get('group_player_ids'):
                for gpid in p['participant']['group_player_ids']:
                    player_map[gpid] = player_name

        matches = []
        for m in self.get_raw()['matches']:
            m = m['match']

            set_count = m['scores_csv']

            try:
                score1, score2 = parse.parse("{:d}-{:d}", set_count)
                if int(score1) == -1 or int(score2) == -1:
                    print('dq match skipped')
                    continue
            except Exception as ex:
                print('could not parse score : ' + str(set_count))

            winner_id = m['winner_id']
            loser_id = m['loser_id']
            if winner_id is not None and loser_id is not None:
                winner = player_map[winner_id]
                loser = player_map[loser_id]
                match_result = AliasMatch(winner=winner, loser=loser)
                matches.append(match_result)
        return matches
Esempio n. 10
0
    def setUp(self):
        self.mongo_client.drop_database(DATABASE_NAME)

        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(name='gaR',
                               aliases=['gar', 'garr'],
                               ratings={
                                   'norcal': Rating(),
                                   'texas': Rating()
                               },
                               regions=['norcal', 'texas'],
                               id=self.player_1_id)
        self.player_2 = Player(name='sfat',
                               aliases=['sfat', 'miom | sfat'],
                               ratings={'norcal': Rating()},
                               regions=['norcal'],
                               id=self.player_2_id)
        self.player_3 = Player(name='mango',
                               aliases=['mango', 'gar'],
                               ratings={'norcal': Rating(mu=2, sigma=3)},
                               regions=['socal'],
                               id=self.player_3_id)
        self.player_4 = Player(name='shroomed',
                               aliases=['shroomed'],
                               ratings={'norcal': Rating()},
                               regions=['norcal'],
                               id=self.player_4_id)
        self.player_5 = Player(name='pewpewu',
                               aliases=['pewpewu'],
                               ratings={'norcal': Rating()},
                               regions=['norcal', 'socal'],
                               id=self.player_5_id)

        self.merge_player_1 = Player(name='CLGsFaT',
                                     aliases=['clg | sfat'],
                                     ratings={'norcal': Rating()},
                                     regions=['norcal'],
                                     id=ObjectId())

        # only includes players 1-3
        self.players = [self.player_1, self.player_2, self.player_3]

        self.tournament_id_1 = ObjectId()
        self.tournament_type_1 = 'tio'
        self.tournament_raw_id_1 = ObjectId()
        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 = [
            Match(winner=self.player_1_id, loser=self.player_2_id),
            Match(winner=self.player_3_id, loser=self.player_4_id)
        ]
        self.tournament_regions_1 = ['norcal']

        # tournament 2 is earlier than tournament 1, but inserted after
        self.tournament_id_2 = ObjectId()
        self.tournament_type_2 = 'challonge'
        self.tournament_raw_id_2 = ObjectId()
        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 = [
            Match(winner=self.player_5_id, loser=self.player_2_id),
            Match(winner=self.player_3_id, loser=self.player_4_id)
        ]
        self.tournament_regions_2 = ['norcal', 'texas']

        self.tournament_1 = Tournament(id=self.tournament_id_1,
                                       name=self.tournament_name_1,
                                       type=self.tournament_type_1,
                                       date=self.tournament_date_1,
                                       regions=self.tournament_regions_1,
                                       raw_id=self.tournament_raw_id_1,
                                       players=self.tournament_players_1,
                                       matches=self.tournament_matches_1)

        self.tournament_2 = Tournament(id=self.tournament_id_2,
                                       name=self.tournament_name_2,
                                       type=self.tournament_type_2,
                                       date=self.tournament_date_2,
                                       regions=self.tournament_regions_2,
                                       raw_id=self.tournament_raw_id_2,
                                       players=self.tournament_players_2,
                                       matches=self.tournament_matches_2)

        self.tournament_ids = [self.tournament_id_1, self.tournament_id_2]
        self.tournaments = [self.tournament_1, self.tournament_2]

        self.pending_tournament_id_1 = ObjectId()
        self.pending_tournament_type_1 = 'tio'
        self.pending_tournament_raw_id_1 = ObjectId()
        self.pending_tournament_date_1 = datetime(2013, 10, 11)
        self.pending_tournament_name_1 = 'pending tournament 1'
        self.pending_tournament_players_1 = [
            self.player_1.name, self.player_2.name, self.player_3.name,
            self.player_4.name
        ]
        self.pending_tournament_matches_1 = [
            AliasMatch(winner=self.player_1.name, loser=self.player_2.name),
            AliasMatch(winner=self.player_3.name, loser=self.player_4.name)
        ]
        self.pending_tournament_regions_1 = ['norcal']

        self.pending_tournament_1 = PendingTournament(
            id=self.pending_tournament_id_1,
            name=self.pending_tournament_name_1,
            type=self.pending_tournament_type_1,
            date=self.pending_tournament_date_1,
            regions=self.pending_tournament_regions_1,
            raw_id=self.pending_tournament_raw_id_1,
            players=self.pending_tournament_players_1,
            matches=self.pending_tournament_matches_1)

        self.pending_tournaments = [self.pending_tournament_1]

        self.ranking_entry_1 = RankingEntry(rank=1,
                                            player=self.player_1_id,
                                            rating=20)
        self.ranking_entry_2 = RankingEntry(rank=2,
                                            player=self.player_2_id,
                                            rating=19)
        self.ranking_entry_3 = RankingEntry(rank=3,
                                            player=self.player_3_id,
                                            rating=17.5)
        self.ranking_entry_4 = RankingEntry(rank=3,
                                            player=self.player_4_id,
                                            rating=16.5)

        self.ranking_time_1 = datetime(2013, 4, 20)
        self.ranking_time_2 = datetime(2013, 4, 21)
        self.ranking_1 = Ranking(id=ObjectId(),
                                 region='norcal',
                                 time=self.ranking_time_1,
                                 tournaments=self.tournament_ids,
                                 ranking=[
                                     self.ranking_entry_1,
                                     self.ranking_entry_2, self.ranking_entry_3
                                 ])
        self.ranking_2 = Ranking(id=ObjectId(),
                                 region='norcal',
                                 time=self.ranking_time_2,
                                 tournaments=self.tournament_ids,
                                 ranking=[
                                     self.ranking_entry_1,
                                     self.ranking_entry_2, self.ranking_entry_4
                                 ])
        self.ranking_3 = Ranking(
            id=ObjectId(),
            region='norcal',
            time=self.ranking_time_2,
            tournaments=self.tournament_ids,
            ranking=[self.ranking_entry_1, self.ranking_entry_2])

        self.rankings = [self.ranking_1, self.ranking_2, self.ranking_3]

        self.user_id_1 = 'abc123'
        self.user_admin_regions_1 = ['norcal', 'texas']
        self.user_1 = User(id=self.user_id_1,
                           admin_regions=self.user_admin_regions_1,
                           username='******',
                           salt='nacl',
                           hashed_password='******')

        self.user_id_2 = 'asdfasdf'
        self.user_full_name_2 = 'Full Name'
        self.user_admin_regions_2 = []
        self.user_2 = User(id=self.user_id_2,
                           admin_regions=self.user_admin_regions_2,
                           username=self.user_full_name_2,
                           salt='nacl',
                           hashed_password='******')

        self.users = [self.user_1, self.user_2]

        self.region_1 = Region(id='norcal', display_name='Norcal')
        self.region_2 = Region(id='texas', display_name='Texas')

        self.regions = [self.region_1, self.region_2]

        for region in self.regions:
            Dao.insert_region(region,
                              self.mongo_client,
                              database_name=DATABASE_NAME)

        self.norcal_dao = Dao('norcal',
                              self.mongo_client,
                              database_name=DATABASE_NAME)

        for player in self.players:
            self.norcal_dao.insert_player(player)

        for tournament in self.tournaments:
            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)
Esempio n. 11
0
    def setUp(self):
        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_6_id = ObjectId()
        self.player_1 = Player(name='gar', id=self.player_1_id)
        self.player_2 = Player(name='sfat', id=self.player_2_id)
        self.player_3 = Player(name='shroomed', id=self.player_3_id)
        self.player_4 = Player(name='ppu', id=self.player_4_id)
        self.player_5 = Player(name='ss', id=self.player_5_id)
        self.player_6 = Player(name='hmw', id=self.player_6_id)
        self.match_1 = Match(winner=self.player_1_id, loser=self.player_2_id)
        self.match_2 = Match(winner=self.player_3_id, loser=self.player_4_id)
        self.match_1 = AliasMatch(winner=self.player_1.name,
                                  loser=self.player_2.name)
        self.match_2 = AliasMatch(winner=self.player_3.name,
                                  loser=self.player_4.name)

        self.alias_to_id_map = [
            AliasMapping(player_alias=self.player_1.name,
                         player_id=self.player_1_id),
            AliasMapping(player_alias=self.player_2.name,
                         player_id=self.player_2_id),
            AliasMapping(player_alias=self.player_3.name,
                         player_id=self.player_3_id),
            AliasMapping(player_alias=self.player_4.name,
                         player_id=self.player_4_id)
        ]

        self.id = ObjectId()
        self.type = 'tio'
        self.raw_id = ObjectId()
        self.date = datetime.now()
        self.name = 'tournament'
        self.players = [
            self.player_1.name, self.player_2.name, self.player_3.name,
            self.player_4.name
        ]
        self.matches = [self.match_1, self.match_2]
        self.regions = ['norcal', 'texas']
        self.url = 'http://challonge.com/test'
        self.excluded = False

        self.pending_tournament_json_dict = {
            '_id':
            self.id,
            'type':
            self.type,
            'raw_id':
            self.raw_id,
            'date':
            self.date,
            'name':
            self.name,
            'players':
            self.players,
            'matches': [m.dump(context='db') for m in self.matches],
            'regions':
            self.regions,
            'alias_to_id_map':
            [am.dump(context='db') for am in self.alias_to_id_map],
            'excluded':
            False,
            'url':
            self.url
        }
        self.pending_tournament = PendingTournament(
            id=self.id,
            name=self.name,
            type=self.type,
            date=self.date,
            regions=self.regions,
            url=self.url,
            raw_id=self.raw_id,
            players=self.players,
            matches=self.matches,
            excluded=self.excluded,
            alias_to_id_map=self.alias_to_id_map)