def append(self):
        self._parse()

        players_in_game = self.dbobj.query_dict("SELECT pbg.*, p.full_name FROM player_by_game pbg INNER JOIN player p ON p.id = pbg.player_id WHERE pbg.game_id = %s" % (self.gamedata['id']))
        query = self.dbobj.query_dict("SELECT * FROM player_cbssports_by_game WHERE game_id = %s" % (self.gamedata['id']))

        for row in query:
            player_id = self._matchWithResolvedPlayer(row['cbssports_player_id'], row['full_name'], row['team_id'], self.gamedata['id'])
            if player_id > 0:
                player_data = {
                    'player_id': player_id,
                    'game_id': row['game_id'],
                    'jersey_number': row['jersey_number'],
                    'position': row['position']
                }
                self.dbobj.insert_or_update('player_by_game',[player_data])
            if player_id == 0:
                player_list = [(line['player_id'], line['full_name']) for line in players_in_game if line['team_id'] == row['team_id']]
                player_id = find_player.FindPlayer(self.dbobj).matchPlayerByNameApproximate(row['full_name'], player_list)
                if player_id > 0:
                    # Append cbssports player id to an existing player
                    player_data = {
                        'id': player_id,
                        'cbssports_player_id': row['cbssports_player_id']
                    }
                    self.dbobj.insert_or_update('player', [player_data])

                    player_data = {
                        'player_id': player_id,
                        'game_id': row['game_id'],
                        'team_id': row['team_id'],
                        'jersey_number': row['jersey_number'],
                        'position': row['position']
                    }
                    self.dbobj.insert_or_update('player_by_game',[player_data])
Beispiel #2
0
    def append(self):
        self._parse()
        players = self.dbobj.query_dict("""
            SELECT 
                p.id,
                p.full_name,
                pbg.team_id
            FROM player_by_game pbg 
                INNER JOIN player p ON p.id = pbg.player_id
            WHERE
                pbg.game_id = %s
        """ % (self.gamedata['id']))

        for row in self.data:
            team_id = row['team_id']
            player_name = row['full_name']
            espn_player_id = row['espn_player_id']

            player_list = [(line['id'], line['full_name']) for line in players
                           if line['team_id'] == long(team_id)]
            player_id = find_player.FindPlayer(
                self.dbobj).matchPlayerByNameApproximate(
                    player_name, player_list)
            if player_id > 0:
                append_data = {
                    'game_id': self.gamedata['id'],
                    'espn_player_id': espn_player_id,
                    'player_id': player_id,
                    'url': 'unknown'
                }
                self.dbobj.insert_or_update('player_espn_by_game',
                                            [append_data])
Beispiel #3
0
    def append(self):
        data = self._parse()
        players = self.dbobj.query_dict("""
            SELECT 
                p.id,
                p.full_name,
                pbg.team_id
            FROM player_by_game pbg 
                INNER JOIN player p ON p.id = pbg.player_id
            WHERE
                pbg.game_id = %s
        """ % (self.game['id']))

        for line in data:
            # Match by statsnbacom_player_id
            resolved_player = self.dbobj.query_dict("SELECT id FROM player WHERE statsnbacom_player_id = %s" % (line['statsnbacom_player_id']))
            if resolved_player:
                player_id = resolved_player[0]['id']
            else:
                # Approximate match
                player_list = [(player['id'], player['full_name']) for player in players if player['team_id'] == line['team_id']]
                player_id = find_player.FindPlayer(self.dbobj).matchPlayerByNameApproximate(line['statsnbacom_player_name'], player_list)

            if player_id > 0:
                append_data = {'game_id': self.game['id'], 'statsnbacom_player_id': line['statsnbacom_player_id'], 'player_id': player_id}
                self.dbobj.insert_or_update('player_statsnbacom_by_game', [append_data])
Beispiel #4
0
    def __init__(self, filename, gamedata, dbobj):
        self.qry = dbobj
        self.dbobj = dbobj
        self.game = gamedata
        self.filename = filename
        self.find_player = find_player.FindPlayer(dbobj)

        self.home_players = self._getHomePlayers()
        self.away_players = self._getAwayPlayers()
Beispiel #5
0
    def __init__(self, filename, gamedata, dbobj):
        self.xml = open(LOGDIR_SOURCE + filename, 'r').read()
        self.qry = dbobj
        self.dbobj = dbobj
        self.game = gamedata
        self.filename = filename
        self.find_player = find_player.FindPlayer(dbobj)

        self.home_players = self._getHomePlayers()
        self.away_players = self._getAwayPlayers()
Beispiel #6
0
    def __init__(self, filename, gamedata, dbobj):
        self.filename = filename
        self.gamedata = gamedata
        self.away_team = self.gamedata['away_team_id']
        self.home_team = self.gamedata['home_team_id']
        self.game_name = self.gamedata['abbrev']
        self.game_id = self.gamedata['id']
        self.date_played = self.gamedata['date_played']
        self.db = dbobj
        self.find_player = find_player.FindPlayer(dbobj)

        # Save the players for each team in this variable -- speed is slow when relying solely on find_player module
        self.players_home = []
        self.players_away = []
        self.players = []
        self.known_plays = []

        self.plays = ''
    def _resolvePlayers(self, shots):
        fpobj = find_player.FindPlayer(self.dbobj)
        home_players = fpobj._transformPlayersToTuples(
            self._getPlayers(self.game['home_team_id']))
        away_players = fpobj._transformPlayersToTuples(
            self._getPlayers(self.game['away_team_id']))

        data = []
        for shot in shots:
            if shot['team_id'] == self.game['home_team_id']:
                player_list = home_players
            elif shot['team_id'] == self.game['away_team_id']:
                player_list = away_players
            else:
                player_list = []

            shot['player_id'] = fpobj.matchPlayerByNameApproximate(
                shot['player_name'], player_list)
            data.append(shot)

        return data