示例#1
0
def getPlayerMostNegativePasses():
    #Empty dictionary
    players = {}
    #Open json with player info
    data = openFileJson('./player_info.json')

    #For every player
    for playerid, playerdata in data.items():
        #Initialize count to 0
        players[playerid] = 0
        #For every yard they passed
        for yards in playerdata['PassYards']:
            #If they passed for negative yards
            if yards != None and yards < 0:
                #Increment their count in dictionary
                players[playerid] = players[playerid] + 1

    #Get most number of negative yards passed
    highest_count = players[max(players, key=players.get)]
    #Empty list
    player_list = []
    #For every player in dictionary
    for k in players:
        #If their count is equal to highest number of negative rushed passed
        if players[k] == highest_count:
            #Save their name and count
            tup = (data[k]['Name'], players[k])
            player_list.append(tup)
    return player_list
示例#2
0
def getAvgNumPlays():
    #Initialize counters
    count = 0
    plays = 0

    #Opens file containing file paths from game_data
    with open('files.txt') as f:
        #Read every file path (for every game)
        for line in f:
            #Truncates empty character at end of line
            line = line[:27]

            #Gets file data
            data = openFileJson(line)
            #Increment number of games
            count = count + 1

            # pull out the game id and game data
            for gameid, gamedata in data.items():
                if gameid != 'nextupdate':
                    # go straight for the drives
                    for driveid, drivedata in gamedata['drives'].items():
                        if driveid != 'crntdrv':
                            #Adds number of plays in game to total
                            plays = plays + drivedata['numplays']
    #Return mean
    return round(plays / count)
示例#3
0
def getWinLossRatio(team):
    #Open json with team info
    data = openFileJson('./team_info.json')

    #Calculate ratio
    ratio = data[team]['wins'] / data[team]['losses']
    return ratio
示例#4
0
def getTeamMostPenalties():
    #Empty list
    team = []
    #Open json with team info
    data = openFileJson('./team_info.json')

    #Most amount of penalties out of all teams
    most = data[max(data, key=lambda x: data[x]['penalties'])]['penalties']

    #For every team
    for t, tdata in data.items():
        #If they have the most amount of penalties
        if tdata['penalties'] == most:
            #Save team & number of penalties
            tup = (t, most)
            team.append(tup)
    return team
示例#5
0
def getPlayerMostDroppedPasses():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Most number of dropped passes
    max_val = data[max(
        data, key=lambda x: data[x]['DroppedPasses'])]['DroppedPasses']

    #For every player
    for player, playerdata in data.items():
        #If they dropped as many passes as the most dropped
        if playerdata['DroppedPasses'] == max_val:
            #Save player name and number of dropped passes
            tup = (playerdata['Name'], max_val)
            players.append(tup)
    return players
示例#6
0
def getMostMissedFieldGoals():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Most number of missed field goals
    max_val = data[max(
        data, key=lambda x: data[x]['MissedFieldGoals'])]['MissedFieldGoals']

    #For every player
    for player, playerdata in data.items():
        #If they missed as many field goals as the most missed
        if playerdata['MissedFieldGoals'] == max_val:
            #Save player name & field goals missed
            tup = (playerdata['Name'], max_val)
            players.append(tup)
    return players
示例#7
0
def getMostMadeFieldGoals():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Set minimum number of field goals to find the most
    most = 0
    #For every player
    for player, playerdata in data.items():
        #If the number of made field goals is greater than or equal to previous most
        if len(playerdata['MadeFieldGoals']) >= most:
            #Update most number of field goals
            most = len(playerdata['MadeFieldGoals'])
            #Save player name & number of field goals made
            tup = (playerdata['Name'], most)
            players.append(tup)
    #Remove players from list who have less successful field goals than the most number of field goals made
    players = list(filter(lambda x: x[1] == most, players))
    return players
示例#8
0
def getPlayersWithMostTeams():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Get player-id with most teams
    max_key = max(data, key=lambda x: len(set(data[x]['Teams'])))
    #Most number of teams a player has played for
    size = len(data[max_key]['Teams'])

    #For every player and their data
    for playerid, playerdata in data.items():
        #If they have played for the most number of teams
        if len(playerdata['Teams']) == size:
            #Pair their name and number of teams played for
            tup = (playerdata['Name'], size)
            #And put in list
            players.append(tup)
    return players
示例#9
0
def getHighestWinLossRatio():
    #Empty list
    teams = []
    #Open json with team info
    data = openFileJson('./team_info.json')

    #Team with best win/loss ratio
    max_key = max(data, key=lambda x: data[x]['wins'] / data[x]['losses'])
    #Best win/loss ratio
    max_wlr = data[max_key]['wins'] / data[max_key]['losses']

    #For every team
    for t, tdata in data.items():
        #Compute win/loss ratio
        ratio = tdata['wins'] / tdata['losses']
        #If ratio is the highest win/loss ratio
        if ratio == max_wlr:
            #Save team & ratio
            tup = (t, ratio)
            teams.append(tup)
    return teams
示例#10
0
def getLongestFieldGoal():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Sets minimum distance for furthest field goal
    furthest = 0
    #For every player
    for player, playerdata in data.items():
        #For every yard they kicked a successful field goal
        for yard in playerdata['MadeFieldGoals']:
            #If current yard is greater than or equal to previous furthest field goal
            if yard and yard >= furthest:
                #Update furthest field goal
                furthest = yard
                #Save player name & yards of furthest field goal
                tup = (playerdata['Name'], furthest)
                players.append(tup)
    #Remove every player in list whose field goal is less than furthest
    players = list(filter(lambda x: x[1] == furthest, players))
    return players
示例#11
0
def getPlayerMostNegativeRush():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Set maximum for negative yards rushed
    lowest = 0
    #For every player
    for playerid, playerdata in data.items():
        #For every yard they rushed
        for yards in playerdata['RushYards']:
            #If current yard is less than current lowest
            if yards != None and yards <= lowest:
                #Update lowest yards rushed to current negative yards
                lowest = yards
                #Save player's name and yards rushed
                tup = (playerdata['Name'], lowest)
                players.append(tup)
    #Remove players who did not rush for the most negative yards
    players = list(filter(lambda x: x[1] == lowest, players))
    return players
示例#12
0
def getPlayersWithMostTeamsInSingleYear():
    #Empty list
    players = []
    #Open json with player info
    data = openFileJson('./player_info.json')

    #Set minimum size for teams played for in a year
    size = 1
    #For every player
    for playerid, playerdata in data.items():
        #For every year they played
        for year, yeardata in playerdata['TeamInfo'].items():
            #If they played for more teams than anyone else
            if len(yeardata) > size:
                #Update most number of teams played for
                size = len(yeardata)
                #Save their name, number of teams played for & in which year
                tup = (playerdata['Name'], size, year)
                players.append(tup)
    #Remove players that have played for less teams than the max
    players = list(filter(lambda x: x[1] == size, players))
    return players
示例#13
0
def writePlayerInfo():
    #Empty dictionary
    players = {}

    #Opens a file for writing
    g = open("player_info.json", "w")

    #Opens file containing file paths from game_data
    with open('files.txt') as f:
        #Read every file path (for every game)
        for line in f:
            #Truncates empty character at end of line
            line = line[:27]

            #Gets file data
            data = openFileJson(line)

            #Old season
            oldseason = 2009
            #Get current season year
            year = getSeason(line)
            newseason = False
            #If new season
            if oldseason != year:
                newseason = True
                oldseason = year

            # pull out the game id and game data
            for gameid, gamedata in data.items():
                if gameid != 'nextupdate':
                    # go straight for the drives
                    for driveid, drivedata in gamedata['drives'].items():
                        if driveid != 'crntdrv':
                            #For every play
                            for playid, playdata in drivedata['plays'].items():
                                #For every player in the play
                                for playerid, playerdata in playdata[
                                        'players'].items():
                                    #For stats in player during play
                                    for info in playerdata:
                                        #Ignore when playerid is 0
                                        if playerid != '0':
                                            #If player is not in dictionary
                                            if playerid not in players:
                                                #Make player-id a key and empty ditionary as value
                                                players[playerid] = {}
                                                #Add name
                                                players[playerid][
                                                    'Name'] = info[
                                                        'playerName']
                                                #Add team they are playing for
                                                players[playerid]['Teams'] = []
                                                players[playerid][
                                                    'Teams'].append(
                                                        info['clubcode'])
                                                #Create key with empty dictionary as value
                                                players[playerid][
                                                    'TeamInfo'] = {}
                                                #Create list for current year
                                                players[playerid]['TeamInfo'][
                                                    year] = []
                                                #Add team they are playing for in current year
                                                players[playerid]['TeamInfo'][
                                                    year].append(
                                                        info['clubcode'])
                                                #Creating empty dictionaries
                                                players[playerid][
                                                    'RushYards'] = []
                                                players[playerid][
                                                    'PassYards'] = []
                                                players[playerid][
                                                    'MadeFieldGoals'] = []
                                                #Create a count initialized to 0
                                                players[playerid][
                                                    'MissedFieldGoals'] = 0
                                                players[playerid][
                                                    'DroppedPasses'] = 0
                                                #If player rushed
                                                if info['statId'] == 10:
                                                    players[playerid][
                                                        'RushYards'].append(
                                                            info['yards'])
                                                #If player passed the ball
                                                if info['statId'] == 15:
                                                    players[playerid][
                                                        'PassYards'].append(
                                                            info['yards'])
                                                #If player made a field goal
                                                if info['statId'] == 70:
                                                    players[playerid][
                                                        'MadeFieldGoals'].append(
                                                            info['yards'])
                                                #If player missed a field goal
                                                if info['statId'] == 69:
                                                    players[playerid][
                                                        'MissedFieldGoals'] = players[
                                                            playerid][
                                                                'MissedFieldGoals'] + 1
                                                #If player dropped a passed ball
                                                if info['statId'] == 115 and 'pass' in playdata[
                                                        'desc'] and 'dropped' in playdata[
                                                            'desc']:
                                                    players[playerid][
                                                        'DroppedPasses'] = players[
                                                            playerid][
                                                                'DroppedPasses'] + 1
                                            #If player already in dicitionary
                                            else:
                                                #If player is playing for new team
                                                if info['clubcode'] not in players[
                                                        playerid]['Teams']:
                                                    players[playerid][
                                                        'Teams'].append(
                                                            info['clubcode'])
                                                #If its a new season create list for season year
                                                if newseason:
                                                    players[playerid][
                                                        'TeamInfo'][year] = []
                                                #If playing for new team in same year
                                                if info['clubcode'] not in players[
                                                        playerid]['TeamInfo'][
                                                            year]:
                                                    players[playerid][
                                                        'TeamInfo'][
                                                            year].append(info[
                                                                'clubcode'])
                                                #If player rushed
                                                if info['statId'] == 10:
                                                    players[playerid][
                                                        'RushYards'].append(
                                                            info['yards'])
                                                #If player passed the ball
                                                if info['statId'] == 15:
                                                    players[playerid][
                                                        'PassYards'].append(
                                                            info['yards'])
                                                #If player made a field goal
                                                if info['statId'] == 70:
                                                    players[playerid][
                                                        'MadeFieldGoals'].append(
                                                            info['yards'])
                                                #If player missed a field goal
                                                if info['statId'] == 69:
                                                    players[playerid][
                                                        'MissedFieldGoals'] = players[
                                                            playerid][
                                                                'MissedFieldGoals'] + 1
                                                #If player dropped a passed ball
                                                if info['statId'] == 115 and 'pass' in playdata[
                                                        'desc'] and 'dropped' in playdata[
                                                            'desc']:
                                                    players[playerid][
                                                        'DroppedPasses'] = players[
                                                            playerid][
                                                                'DroppedPasses'] + 1
    #Writes all game IDs
    g.write(json.dumps(players))
示例#14
0
def getPenalties(team):
    data = openFileJson('./team_info.json')

    pens = data[team]['penalties']
    return pens
示例#15
0
def writeTeamInfo():
    teams = {}

    #Opens a file for writing
    g = open("team_info.json", "w")

    #Corrected team abbreviations
    abbr = openFileJson('./team_abbrev.json')

    #Opens file containing file paths from game_data
    with open('files.txt') as f:
        #Read every file path
        for line in f:
            #Truncates empty character at end of line
            line = line[:27]

            #Gets file data
            data = openFileJson(line)

            # pull out the game id and game data
            for gameid, gamedata in data.items():
                if gameid != 'nextupdate':
                    #Get home and away teams
                    home = gamedata['home']['abbr']
                    away = gamedata['away']['abbr']
                    #Check for correct abbreviation
                    home = abbr[home]
                    away = abbr[away]

                    #If home team not in dictionary, add them & initialize values
                    if home not in teams:
                        teams[home] = {}
                        teams[home]['penalties'] = 0
                        teams[home]['penalty yards'] = 0
                        teams[home]['wins'] = 0
                        teams[home]['losses'] = 0
                    #Add to penalty counters of home team
                    teams[home]['penalties'] = teams[home][
                        'penalties'] + gamedata['home']['stats']['team']['pen']
                    teams[home]['penalty yards'] = teams[home][
                        'penalty yards'] + gamedata['home']['stats']['team'][
                            'penyds']
                    #If away team not in dictionary, add them & initialize values
                    if away not in teams:
                        teams[away] = {}
                        teams[away]['penalties'] = 0
                        teams[away]['penalty yards'] = 0
                        teams[away]['wins'] = 0
                        teams[away]['losses'] = 0
                    #Add to penalty counters of away team
                    teams[away]['penalties'] = teams[away][
                        'penalties'] + gamedata['away']['stats']['team']['pen']
                    teams[away]['penalty yards'] = teams[away][
                        'penalty yards'] + gamedata['away']['stats']['team'][
                            'penyds']

                    #Update counts for which teams won and loss
                    if gamedata['home']['score']['T'] > gamedata['away'][
                            'score']['T']:
                        teams[home]['wins'] = teams[home]['wins'] + 1
                        teams[away]['losses'] = teams[away]['losses'] + 1
                    elif gamedata['home']['score']['T'] < gamedata['away'][
                            'score']['T']:
                        teams[away]['wins'] = teams[away]['wins'] + 1
                        teams[home]['losses'] = teams[home]['losses'] + 1
    #Writes all game IDs
    g.write(json.dumps(teams))
示例#16
0
    #process_folder_images(folder)

    #Open given image
    im = Image.open(image)

    #Convert to RGBA
    im = im.convert('RGBA')

    #Get dimensions
    width, height = im.size
    im = resize(im, int(width * size_change))
    width, height = im.size

    #Open json with player info
    data = openFileJson('./color_data.json')

    #Create new image to draw on
    bg = Image.new("RGBA", (width * size, height * size), "black")

    #No previous color because loop has not started
    prev_color = None

    #For every y in original image
    for y in range(height):

        #Update pixel for new image
        y2 = y * size

        #For every x in original image
        for x in range(width):