def playerPoints(playerInfo):
    weeksPlayed = 0
    playerFound = nflgame.find(playerInfo[0], team = None)
    if playerFound != []:
        if playerFound[0].position == "K":
            points = fpKicker.kickerScore(playerFound[0], playerInfo[1], playerInfo[2])
        else:
            points = fpPlayer.fantasyPoints(playerFound[0], playerInfo[1], playerInfo[2], playerInfo[3])
        for i in playerInfo[2]:
            if str(i).isdigit():
                weeksPlayed = weeksPlayed + 1
        for w in byeWeekLists.byeWeeks:
            for t in w:
                curWeek = nflgame.live.current_year_and_week()[1]
                if w[-1] <= curWeek and nflgame.find(playerInfo[0], team=None)[0].team == t and w[-1] in playerInfo[2]:
                    weeksPlayed1 = weeksPlayed1 - 1
                    break
        average = points / weeksPlayed
        return average
    elif playerInfo[0] != None:
        team = nflgame.standard_team(playerInfo[0])
        if team == None:
            return float('inf')
        playerInfo[0] = team
        points = fpDefense.fpDefense(playerInfo[0], playerInfo[1], playerInfo[2])
        weeksPlayed = nflgame.live.current_year_and_week()[1]
        curWeek = nflgame.live.current_year_and_week()[1]
        for w in byeWeekLists.byeWeeks:
            for t in w:
                if w[-1] <= curWeek and t == playerInfo[0] and w[-1] in playerInfo[2]:
                    weeksPlayed = weeksPlayed - 1
        return points / weeksPlayed
    else:
        return float('inf')
def tradePlayersUI():
    if printLeagues():
        return 1
    le = raw_input('Enter the name of the league the teams are in: ').strip()
    if printTeams(le):
        return 1
    t1 = raw_input('Enter the name of the team to trade from: ').strip()
    t2 = raw_input('Enter the name of the team to trade to: ').strip()
    if printPlayers(le,t1):
        print 'Cannot trade from empty roster %s.' % t1
        return 1
    pls1=[]
    pls2=[]
    plo1=[]
    plo2=[]
    if not printPlayers(le,t2):
        promptInp = ' '
        while promptInp.lower() not in ['n','no']:
            pls1.append(raw_input('Enter player from %s to trade: '%t1).strip())
            promptInp = raw_input('Would you like to trade another player? (y/n): ' ).strip()
            while promptInp.lower() not in ['y','yes','n','no']:
                promptInp = raw_input('Invalid input.  Please try again: ').strip()
        promptInp = ' '
        while promptInp.lower() not in ['n','no']:
            pls2.append(raw_input('Enter player from %s to trade: '%t2).strip())
            promptInp = raw_input('Would you like to trade another player? (y/n): ' ).strip()
            while promptInp.lower() not in ['y','yes','n','no']:
                promptInp = raw_input('Invalid input.  Please try again: ').strip()
        pls1=list(set(pls1))            #cast as set, then as list to rid of 
        pls2=list(set(pls2))            #potential dups
    else:
        promptInp = ' '
        while promptInp.lower() not in ['n','no']:
            pls1.append(raw_input('Enter player from %s to trade: '%t1).strip())
            promptInp = raw_input('Would you like to trade another player? (y/n): ' ).strip()
            while promptInp.lower() not in ['y','yes','n','no']:
                promptInp = raw_input('Invalid input.  Please try again: ').strip()
    
    for i in pls1:
        j=nflgame.find(i,team=None)
        if j:
            plo1.append(j[0])
    for i in pls2:
        j=nflgame.find(i,team=None)
        if j:
            plo2.append(j[0])

    testVar = fbTool.tradePlayers(plo1,plo2,le,t1,t2)
    if not testVar:
        print 'successfully traded'
        print pls1
        print 'from %s to %s for'%(t1,t2)
        print pls2
    if testVar == 1:
        print 'League does not exist.'
    if testVar == 2:
        print 'Roster does not exist.'
    if testVar == 3:
        print 'Player not on roster.'
示例#3
0
def playerstats(message, player, year, details='no'):
    year = int(year)
    response = 'Here are the stats for %s in %s:\n' % (player, year)

    # calculate games and players variables
    games = nflgame.games(year)
    players = nflgame.combine(games)

    if details == 'detailed':
        # this works to calculate games but specifying the team is MUCH faster:
        # #games = nflgame.games(year, home="PIT", away="PIT")
        #games = nflgame.games(year)
        bigben = nflgame.find(player)[0]
        # bigben -> Ben Roethlisberger (QB, PIT)
        # bigben.gsis_name -> B.Roethlisberger
        # bigben.position -> QB
        # bigben.team -> PIT

        # #TODO: complete this if logic for position-based stats
        # if bigben.position == 'QB':
        # 	# QB stats
        # if bigben.position == 'RB':
        # 	# RB stats
        # if bigben.position == 'WR':
        # 	# WR stats
        # if bigben.position == 'K':
        # 	# K stats

        # right now this is QB stats (hence the passing nomenclature)
        for i, game in enumerate(games):
            if game.players.name(bigben.gsis_name):
                stats = game.players.name(bigben.gsis_name).passing_yds
                tds = game.players.name(bigben.gsis_name).passing_tds
                response += '*Week {:2}* - {:3} yds, {:2} TD\n'.format(
                    game.schedule['week'], stats, tds)

        response += '-' * 25
        #players = nflgame.combine(games)
        response += '\n*{:4} Season - {:4} yds, {:2} TD*'.format(
            year,
            players.name(bigben.gsis_name).passing_yds,
            players.name(bigben.gsis_name).passing_tds)

    # if detailed stats are not requested, provide overall stats for the season
    else:
        #games = nflgame.games(year)
        #players = nflgame.combine(games)
        my_player = nflgame.find(player)[0]
        brady = players.name(my_player.gsis_name)
        response += '%d total yds, %d total TD in %d' % (
            brady.passing_yds, brady.passing_tds, year)

        # ne = nflgame.games(2010, home="NE", away="NE")
        # players = nflgame.combine(ne)
        # brady = players.name("T.Brady")
        # response += '%d, %d' % (brady.passing_tds, brady.passing_yds)

    message.reply(response)
def find_playerid(name, team=None):
    if not nflgame.find(name, team):
        return 'No match'
    if len(nflgame.find(name, team)) > 1:
        print 'Could be either {}'.format(' or '.join(
            [str(p) for p in nflgame.find(name, team)]))
        return [p.gsis_id for p in nflgame.find(name, team)]
    else:
        return nflgame.find(name, team)[0].gsis_id
def find_playerid(name, team=None):
    if not nflgame.find(name, team):
        return 'No match'
    if len(nflgame.find(name, team)) > 1:
        print 'Could be either {}'.format(
            ' or '.join([str(p) for p in nflgame.find(name, team)]))
        return [p.gsis_id for p in nflgame.find(name, team)]
    else:
        return nflgame.find(name, team)[0].gsis_id
示例#6
0
def playerstats(message, player, year, details='no'):
	year = int(year)
	response = 'Here are the stats for %s in %s:\n' % (player, year)

	# calculate games and players variables
	games = nflgame.games(year)
	players = nflgame.combine(games)

	if details == 'detailed':
		# this works to calculate games but specifying the team is MUCH faster:
		# #games = nflgame.games(year, home="PIT", away="PIT")
		#games = nflgame.games(year)
		bigben = nflgame.find(player)[0]
		# bigben -> Ben Roethlisberger (QB, PIT)
		# bigben.gsis_name -> B.Roethlisberger
		# bigben.position -> QB
		# bigben.team -> PIT

		# #TODO: complete this if logic for position-based stats
		# if bigben.position == 'QB':
		# 	# QB stats
		# if bigben.position == 'RB':
		# 	# RB stats
		# if bigben.position == 'WR':
		# 	# WR stats
		# if bigben.position == 'K':
		# 	# K stats
		
		# right now this is QB stats (hence the passing nomenclature)
		for i, game in enumerate(games):
		    if game.players.name(bigben.gsis_name):
		        stats = game.players.name(bigben.gsis_name).passing_yds
		        tds = game.players.name(bigben.gsis_name).passing_tds
		        response += '*Week {:2}* - {:3} yds, {:2} TD\n'.format(game.schedule['week'], stats, tds)

		response += '-'*25
		#players = nflgame.combine(games)
		response += '\n*{:4} Season - {:4} yds, {:2} TD*'.format(year, players.name(bigben.gsis_name).passing_yds, players.name(bigben.gsis_name).passing_tds)

	# if detailed stats are not requested, provide overall stats for the season
	else:
		#games = nflgame.games(year)
		#players = nflgame.combine(games)
		my_player = nflgame.find(player)[0]
		brady = players.name(my_player.gsis_name)
		response += '%d total yds, %d total TD in %d' % (brady.passing_yds, brady.passing_tds, year)

		# ne = nflgame.games(2010, home="NE", away="NE")
		# players = nflgame.combine(ne)
		# brady = players.name("T.Brady")
		# response += '%d, %d' % (brady.passing_tds, brady.passing_yds)

	message.reply(response)
示例#7
0
def average(name, scoring):
    # takes player name, type of scoring
    # returns player average points
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return None
    player = playerlist[0]
    team = player.team
    position = player.position
    year, current_week = nflgame.live.current_year_and_week()
    bye_week = schedule.bye_week(team, year)
    wk = []
    for x in range(1, current_week):
        if x != bye_week:
            wk.append(x)
    if position == "K":
        player_points = points.total_points(points.k_points(name, year, wk))
    else:
        functionname = scoring+"_player_points"
        getpoints = getattr(points, functionname)
        player_points = points.total_points(getpoints(name, year, wk))
    weeks_played = 0
    total_points = 0
    for x in player_points:
        if player_points[x] != 0:
            total_points += player_points[x]
            weeks_played += 1
    avg = round(float(total_points)/weeks_played)
    return avg
def validate_player(player):
    """
    This method takes in a string (player) which is the name of a player that the user is trying to find. The method
    then searches for the player. If the search yields more than one result, the user will be prompted to select which
    player they would were intending.

    :param player: string, name of player the user is searching for
    :return: Player object that the user has selected
    """

    # Search for the player, record all matches
    matches = nflgame.find(player)

    # If we only found one result, return it
    if len(matches) == 1:
        return matches[0]

    # If we didn't find anything, return nothing
    elif len(matches) == 0:
        return None

    # If we made it this far, we found more than one match
    print('Found '+str(len(matches))+' matches for '+player.title()+'.')
    print('Please select from the following options.')

    # List the matches that were found in the search
    for i in range(len(matches)):
        print('('+str(i+1)+') - '+player.title()+', '+matches[i].team+', number '+str(matches[i].number))

    # Prompt the user to select which player they were looking for
    selection = int(raw_input('Enter your selection: '))
    return matches[selection-1]
def addPlayer(leagueName, rosterName, playerName, playerTeam):
    if leagueLists:
        for l in leagueLists:
            if l.leagueName == leagueName:
                for r in l.rosters:
                    if r.rosterName == rosterName:
                        teamName = nflgame.standard_team(playerTeam)
                        playerFound = nflgame.find(playerName, team=teamName)
                        if playerFound:
                            p = playerFound[0]
                            plr2Ad = player(p.player_id, p.first_name, p.last_name, p.team, p.position)
                            for k in l.rosters:
                                if k.players:
                                    for j in k.players:
                                        if plr2Ad.firstName == j.firstName and plr2Ad.lastName == j.lastName and plr2Ad.team == j.team:
                                            return 1
                            r.players.append(plr2Ad)
                            return 0
                        else:   
                            return 2
                    elif r == l.rosters[-1]:
                        return 3
            elif l is leagueLists[-1]:
                return 4
    else:
        return 4
示例#10
0
def average(name, scoring):
    # takes player name, type of scoring
    # returns player average points
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return None
    player = playerlist[0]
    team = player.team
    position = player.position
    year, current_week = nflgame.live.current_year_and_week()
    bye_week = schedule.bye_week(team, year)
    wk = []
    for x in range(1, current_week):
        if x != bye_week:
            wk.append(x)
    if position == "K":
        player_points = points.total_points(points.k_points(name, year, wk))
    else:
        functionname = scoring + "_player_points"
        getpoints = getattr(points, functionname)
        player_points = points.total_points(getpoints(name, year, wk))
    weeks_played = 0
    total_points = 0
    for x in player_points:
        if player_points[x] != 0:
            total_points += player_points[x]
            weeks_played += 1
    avg = round(float(total_points) / weeks_played)
    return avg
def get_game_data(name, team, book, year):

    if __name__ == '__main__':
        try:
            player = nflgame.find(name)[0]
        except BaseException:
            return

    if '(, )' in str(player):
        print ("Player Inactive, or Player Not Found\n\n")
        return

    print ("*" *79)
    print (player)

    data = create_csv(player)
    data.append_separator(name)

    print (str(year) + '\n')
    data.append_separator(year)
    games = nflgame.games(year, home=team, away=team)
    for game in games:
        plyr = game.players.name(player.gsis_name)
        print ('-'*79)
        print (game)
        to_csv(data, plyr, game, year, player.position)

    with open(name + '.xls', 'wb') as f:
        f.write(data.xls)
    book.add_sheet(data)
示例#12
0
def playerbio(message, player):
	response = 'Here\'s the bio for %s:\n' % player
	bigben = nflgame.find(player)[0]
	height_in_feet = '%d\' %d\"' % (int(bigben.height)/12, int(bigben.height)%12)
	response += '*Name:* %s\n*Team:* %s\n*Position:* %s\n*College:* %s\n' % (bigben.full_name, bigben.team, bigben.position, bigben.college)
	response += '*Ht/Wt:* %s, %dlbs\n*Yrs Pro:* %d\n*Profile URL:* %s' % (height_in_feet, bigben.weight, bigben.years_pro, bigben.profile_url)

	message.reply(response)
示例#13
0
 def byecheck(i):
     for w in byeWeekLists.byeWeeks:
         for t in w:
             if nflgame.find(player2info[0], team=None)[0].team == t:
                 if w[-1] in p2w:
                     twobye = QListWidgetItem("%s has a bye in week %d" % (t, w[-1]))
                     player2area.addItem(twobye)
                     p2w.remove(w[-1])
示例#14
0
 def makePlayerList2():
     for h in pl2:
         pl2.pop()
     itemsList = roster2.selectedItems()
     for i in itemsList:
         name = str(i.text())
         i2push = nflgame.find(name)
         if i2push:
             pl2.append(i2push[0])
示例#15
0
    def findPlayer(self, row):
        last, first, *_ = row.Player.split(" ")
        name = first + " " + last
        name = name.replace(",", "")
        name = name.replace(".", "")
        found = nfl.find(name, row.Team)
        if row.Position == "DST":
            return False, "Defense"
        if len(found) == 1:
            player = found[0]
            return True, player
        elif len(found) == 0:
            found = nfl.find(name)
            if len(found) == 0:
                year, current_week = nfl.live.current_year_and_week()
                # print(row.Team, row)
                try:
                    for game in nfl.games(year, home=row.Team, away=row.Team):
                        #print(game, row.Team, year)
                        try:
                            player = game.players.name(first[0] + "." + last)
                            if player != None:
                                if player.team == row.Team:
                                    return True, player
                                    break

                        except:
                            # print(row.Player)
                            quit()
                except:
                    print(row)
                    print(name)
                    raise

            else:
                if len(found) > 1:
                    for player in found:
                        if player.position == row.Position:
                            return True, player
                else:
                    return True, found[0]
        else:
            return False, 0
        return False, 0
示例#16
0
def playerbio(message, player):
    response = 'Here\'s the bio for %s:\n' % player
    bigben = nflgame.find(player)[0]
    height_in_feet = '%d\' %d\"' % (int(bigben.height) / 12,
                                    int(bigben.height) % 12)
    response += '*Name:* %s\n*Team:* %s\n*Position:* %s\n*College:* %s\n' % (
        bigben.full_name, bigben.team, bigben.position, bigben.college)
    response += '*Ht/Wt:* %s, %dlbs\n*Yrs Pro:* %d\n*Profile URL:* %s' % (
        height_in_feet, bigben.weight, bigben.years_pro, bigben.profile_url)

    message.reply(response)
示例#17
0
def generatePlayerDataFile(player_name='todd gurley', years=range(2009, 2018)):

    poss_players = [p for p in nflgame.find(player_name) if p.position == 'RB']
    if not poss_players:
        print 'could not find ', player_name, ' in nfl database.'
        exit(1)
    if len(poss_players) > 1:
        print 'found multiple ', player_name, '\'s!'
        exit(2)
    player = poss_players[0]
    # print dir(player)
    playerid = player.playerid

    # this list will be used as a constructor to the DataFrame
    # perhaps there is a slicker way to construct a DataFrame?
    datalist = []
    for year in years:
        print 'reading {} season...'.format(year)
        for week in range(1, 18):
            # print 'looking at week ', week
            weekly_games = nflgame.games_gen(year, week)
            try:
                # use combine_play_stats() to get play-level information
                weekly_player_stats = nflgame.combine_game_stats(weekly_games)
            except TypeError:
                print str(year), ' not in database.'
                break
            for pstat in weekly_player_stats.rushing().filter(
                    playerid=playerid):
                base_pts = getBasePoints(bro_league, pstat)
                datalist.append({
                    'year':
                    year,
                    'week':
                    week,
                    'fantasy_points':
                    base_pts,
                    'rushing_attempts':
                    pstat.rushing_att,
                    'receptions':
                    pstat.receiving_rec,
                    'yards':
                    pstat.rushing_yds + pstat.receiving_yds,
                    'tds':
                    pstat.rushing_td + pstat.receiving_td,
                    '2pc':
                    pstat.rushing_twoptm + pstat.receiving_twoptm
                    # 'playerid':pstat.playerid
                })

                df = pd.DataFrame(datalist)
                df.to_csv(playerFilename(player_name) + '.csv')
示例#18
0
def flex_stats(name, year):
    player = nflgame.find(name)
    for week in range(17):
        games = nflgame.games(int(year), int(week + 1))
        players = nflgame.combine_game_stats(games)
        for p in players:
            if str(name) == str(p):
                fp = fps(p.receiving_rec, p.rushing_yds, p.rushing_tds,
                         p.receiving_yds, p.receiving_tds)
                general_msg(int(week + 1), float(fp))
                rush_msg(p.rushing_att, p.rushing_yds, p.rushing_tds)
                rec_msg(p.receiving_tar, p.receiving_rec, p.receiving_yds,
                        p.receiving_tds)
示例#19
0
 def generate():
     games = nflgame.games(int(year), week=1)
     players = nflgame.combine_game_stats(games)
     player = nflgame.find(name, team=team)[0]
     for x in players:
         if x.player:
             if x.player.full_name:
                 if x.player.full_name == player.full_name:
                     p = addStats(player.__dict__, x, player.position)
                     if p is not None:
                         p = fillBlanks(p)
                         yield makeResponse([p])
                     break
示例#20
0
def validate_player(player):
    matches = nflgame.find(player)
    if len(matches) == 1:
        return matches[0]
    elif len(matches) == 0:
        return None
    print('Found ' + str(len(matches)) + ' matches for ' + player.title() +
          '.')
    print('Please select from the following options.')
    for i in range(len(matches)):
        print('(' + str(i + 1) + ') - ' + player.title() + ', ' +
              matches[i].team + ', number ' + str(matches[i].number))
    selection = int(raw_input('Enter your selection: '))
    return matches[selection - 1]
示例#21
0
def get_player_nfl_object(name, position):
    if name in EXCEPTIONS.keys():
        name = EXCEPTIONS[name]
    if name in POSITION_ERRORS.keys():
        position = POSITION_ERRORS[name]
    elif position == "DST" or position == "K":
        return "N/A"
    matches = nfl.find(name)
    if len(matches) == 1:
      return matches[0]
    else:
      for p in matches:
          if position == p.position:
              return p
示例#22
0
 def byecheck(i):
     if player1info[0] == "BUF":
         for r in p1w:
             if r == 7:
                 onebye = QListWidgetItem("%s has a bye in week %d" % ("BUF", 7))
                 player1area.addItem(onebye)
                 p1w.remove(7)
     else:
     
         for w in byeWeekLists.byeWeeks:
             for t in w:
                 if nflgame.find(player1info[0], team=None)[0].team == t:
                     if w[-1] in p1w:
                         onebye = QListWidgetItem("%s has a bye in week %d" % (t, w[-1]))
                         player1area.addItem(onebye)
                         p1w[:] = (value for value in p1w if value != w[-1])
                         print p1w
示例#23
0
 def but2():
     if not list3.currentItem():
         QMessageBox.critical(window,'error','No player selected')
     else:
         ln = list1.currentItem().text()
         rn = list2.currentItem().text()
         pn = str(list3.currentItem().text())
         te = QMessageBox.question(window,'???','Are you sure you want to delete this player?',QMessageBox.Yes|QMessageBox.No,QMessageBox.No)
         if te == QMessageBox.Yes:
             if pn[-1]==')':
                 pn=pn[:-3]
             ret = fbTool.removePlayer(nflgame.find(pn,team=None),str(ln),str(rn))
             if ret:
                 QMessageBox.critical(window,'error','SOMETHING BROKE!')
             else:
                 poplist3(list2.currentItem())
         mainMenu.updateTree()
示例#24
0
def player_stats(name, year, wk):
    # takes player's full name, year of game(s), week of game(s)
    # returns stats based on player's position
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    player = playerlist[0]
    player_id = player.gsis_id
    player_position = player.position
    team = player.team
    if player_position == 'RB' or player_position == 'WR' or player_position == 'TE' or player_position == 'QB':
        output = main_stats(player_id, year, wk, team)
    elif player_position == "K":
        output = k_stats(player_id, year, wk, team)
    else:
        output = False
    return output
示例#25
0
def player_stats(name, year, wk):
    # takes player's full name, year of game(s), week of game(s)
    # returns stats based on player's position
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    player = playerlist[0]
    player_id = player.gsis_id
    player_position = player.position
    team = player.team
    if player_position == 'RB' or player_position == 'WR' or player_position == 'TE' or player_position == 'QB':
        output = main_stats(player_id, year, wk, team)
    elif player_position == "K":
        output = k_stats(player_id, year, wk, team)
    else:
        output = False
    return output
示例#26
0
def k_stats(name, year, wk):
    # takes players full name, year of game, week of game(s)
    # applies for all kickers
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    else:
        player = playerlist[0]
        stats = {'fgmade':0, 'fga':0, 'xpmade':0, 'xpa':0}
        games = nflgame.games(year, week=wk)
        gameplayers = nflgame.combine_game_stats(games)
        for p in gameplayers:
            if p.name == player.gsis_name:
                stats['fgmade']+=p.kicking_fgm
                stats['fga']+=p.kicking_fga
                stats['xpmade']+=p.kicking_xpmade
                stats['xpa']+=p.kicking_xpa
        return stats
示例#27
0
def get_stats(name, year, wks):
    # gets stats for a player
    # note: weeks must be defined as a list
    playersearch = nflgame.find(name, team=None)
    if playersearch == []:
        return False
    player = playersearch[0]
    byeweek = schedule.bye_week(player.team, year)
    player_stats = {}
    try:
        wks.remove(byeweek)
    except ValueError:
        wks=wks
    for x in range(0, len(wks)):
        dictprop = 'Week '+str(wks[x])
        player_stats[dictprop]=(stats.player_stats(name, year, wks[x]))
        player_stats[dictprop]['week']=wks[x]
        player_stats[dictprop]['bye_week'] = False
    return player_stats
示例#28
0
def printPts():
    leagueName=getLeagueName(0)
    teamName=getTeamName(leagueName)
    weekNum=int(raw_input('Please enter a week number: '))
    points=[]
    it=0
    plfound=False
    tfound=False
    year=int(raw_input('Enter a year (2009-2015):').rstrip())
    for i in fbTool.leagueLists:
        if i.leagueName == leagueName:
            lfound=True
            for j in i.rosters:
                if j.rosterName == teamName:
                    tfound=True
                    if j.players:
                        print 'Calculating points for %s on week %d...'%(teamName,weekNum)
                        for k in j.players:
                            if k.position != 'LE' and k.position != 'RE' and k.position != 'OLB' and k.position != 'CB' and k.position != 'MLB' and k.position != 'DT' and k.position != 'DB' and k.position != 'DE' and k.position != 'FS' and k.position != 'SS':
                                playersName=k.firstName+' '+k.lastName
                                plyToApp = nflgame.find(playersName,k.team)[0]
                                if k.position == 'K':
                                    points.append(fpKicker.kickerScore(plyToApp,year,weekNum))
                                else:
                                    points.append(fpPlayer.fantasyPoints(plyToApp,year,weekNum))
                        print 'PlayerID       First Name       Last Name           NFLTeam    Points'
                        for k in j.players:
                            if k.position != 'LE' and k.position != 'RE' and k.position != 'OLB' and k.position != 'CB' and k.position != 'MLB' and k.position != 'DT' and k.position != 'DB' and k.position != 'DE' and k.position != 'FS' and k.position != 'SS':
                                print '{:14s} {:16s} {:19s} {:10s} {:9f} '.format(str(k.player_id),k.firstName,k.lastName,k.team,points[it])
                                it = it+1
                        dpoints=0
                        for l in j.defense:
                            dpoints = dpoints+fpDefense.fpDefense(l,year,weekNum)
                        p=sum(points)
                        print 'total offensive points: %f'%p
                        print 'total defensive points: %f'%dpoints
                        print 'total points: %f'%(p+dpoints)
                    else:
                        print 'Team is empty'
                elif j==i.rosters[-1] and not tfound: 
                    print 'Team %s not found'%teamName
        elif i==fbTool.leagueLists[-1] and not lfound:
            print 'League %s not found' %leagueName
示例#29
0
def bye_week_player(name, year):
    # takes team symbol and year of bye week
    # returns bye week, 0 if no result, does not work for bye weeks that have not yet happened
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    player = playerlist[0]
    team = player.team
    gameweeks = []
    for x in range(1, 18):
        games = nflgame.games(year, week=x, home=None, away=None, kind='REG', started=False)
        if games == []:
            return None
        weekteams = []
        for i in games:
            weekteams.append(i.home)
            weekteams.append(i.away)
        if team not in weekteams and weekteams != []:
            return x
    return None
示例#30
0
def qb_stats(name, year, wk):
    # takes players full name, year of game, week of game(s)
    # applies for all quarterbacks
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    else:
        player = playerlist[0]
        stats = {'rushing_yds':0, 'rushing_tds':0, 'passing_yds':0, 'passing_tds':0, 'passing_ints':0, 'fumbles':0}
        games = nflgame.games(year, week=wk)
        gameplayers = nflgame.combine_game_stats(games)
        for p in gameplayers:
            if p.name == player.gsis_name:
                stats['passing_yds']+=p.passing_yds
                stats['passing_tds']+=p.passing_tds
                stats['passing_ints']+=p.passing_ints
                stats['rushing_yds']+=p.rushing_yds
                stats['rushing_tds']+=p.rushing_tds
                stats['fumbles']+=p.fumbles_tot
        return stats
示例#31
0
def flex_stats(name, year, wk):
    # takes players full name, year of game, week of game(s)
    # applies for all players that can play in the flex (RB, WR, TE)
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    else:
        player = playerlist[0]
        stats = {'rushing_yds':0, 'rushing_tds':0, 'receiving_yds':0, 'receiving_tds':0, 'fumbles':0, 'puntret_tds':0, 'kickret_tds':0}
        games = nflgame.games(year, week=wk)
        gameplayers = nflgame.combine_game_stats(games)
        for p in gameplayers:
            if p.name == player.gsis_name:
                stats['rushing_yds']+=p.rushing_yds
                stats['rushing_tds']+=p.rushing_tds
                stats['receiving_yds']+=p.receiving_yds
                stats['receiving_tds']+=p.receiving_tds
                stats['fumbles']+=p.fumbles_tot
                stats['puntret_tds']+=p.puntret_tds
                stats['kickret_tds']+=p.kickret_tds
        return stats
示例#32
0
def computeScore(player, week, year):
	playerObject = nflgame.find(player)
	stats = playerObject[0].stats(year, week)
	score = 0
	score += (stats.passing_yds * .04)
	score += (stats.rushing_yds * .1)
	score += (stats.passing_tds * 4)
	score += (stats.rushing_tds * 6)
	score += (stats.passing_int * -2)
	score += (stats.receiving_yds * .1)
	score += (stats.receiving_tds * 6)
	score += (stats.receiving_rec * .5)
	score += (stats.kickret_tds * 6)
	score += (stats.puntret_tds * 6)
	score += (stats.fumbles * -2)
	score += (stats.fumbles_rec_tds * 6)
	score += (stats.receiving_twopta * 2)
	score += (stats.rushing_twopta * 2)
	score += (stats.passing_twopta * 2)
	# print stats.passing_yds
	# print stats.passing_tds
	return score
示例#33
0
def remPlayerUI():
    if printLeagues():
        return 1
    ln = raw_input('Please enter the name of the league the team to remove from is in: ').strip()
    if printTeams(ln):
        return 1
    rn = raw_input('Please enter the name of the team to remove from: ').strip()
    if printPlayers(ln,rn):
        return 1
    pn = raw_input('Please enter the name of the player to remove: ').strip()
    invar=' '
    while invar.lower() not in ['y','yes','n','no']:
        invar=raw_input('Are you sure you want to do this? (y/n): ').strip()
        if invar.lower() in ['y','yes']:
            invar = raw_input('Would you like to save before doing so?(y/n): ')
            if invar.lower() in ['y','yes']:
                saveFileUI()
            if invar.lower() in ['n','no']:
                print 'IF YOU SAY SO.....'
                invar = 'y'
            if invar.lower() not in ['y','yes','n','no']:
                print 'Invalid input. Please try again...'
            else:
                testVar = fbTool.removePlayer(nflgame.find(pn,team=None),ln,rn)
                if testVar == 1:
                    print 'LEAGUE DOESN\'T EXIST!'
                elif testVar == 2:
                    print 'ROSTER DOESN\'T EXIST!'
                elif testVar == 3:
                    print 'PLAYER NOT ROSTERED ON TEAM!'
                elif not testVar:
                    print '%s was removed from %s.' %(pn,rn)
        if invar.lower() in ['n','no']:
            print 'I DIDN\'T THINK SO!'
        if invar.lower() not in ['y','yes','n','no']:
            print 'Invalid input.  Please try again...'
示例#34
0
    def get_id_from_name(self, ptp):
        #receives tuple of form (player name, team, positions) or string of form 'First Last, Team Position' then filters
        if type(ptp) == tuple:
            name, team, pos = ptp
        else:
            name, team, pos = filter_ptp(ptp)
        print(name, team, pos)
        #Chad Johnson
        if name == 'Chad Ochocinco':
            return '00-0020397'
        #Roosevelt Nix-Jones
        if name == 'Roosevelt Nix':
            return '00-0030741'
        #Mike Vick
        if name == 'Michael Vick':
            return '00-0020245'
        #Dan Herron
        if name == 'Daniel Herron':
            return '00-0029588'
        #Steve Johnson
        if name == 'Stevie Johnson':
            return '00-0026364'
        #Anthony Dixon
        if name == 'Boobie Dixon':
            return '00-0027772'
        #Stephen Hauschka
        if name == 'Steven Hauschka':
            return '00-0025944'
        #Rob Kelley
        if name == 'Robert Kelley':
            return "00-0032371"
        #WR/RB
        if name == 'Danny Woodhead':
            return '00-0026019'

        if pos != 'D/ST':
            player = nflgame.find(name)
            if len(player) == 1:

                player = player[0]
                print('*', player.full_name, player.position, player.team,
                      player.player_id)
                return player.player_id
            elif len(player) > 1:
                #For case of multiple players with same name
                player = nflleague.functions.find(name,
                                                  self.season,
                                                  players=self.player_game)
                if player != None and (player.position == ''
                                       or player.position == pos):
                    print('**', player.full_name, player.position, player.team,
                          player.player_id)
                    return player.player_id
                else:
                    #For case of two active players with same name.  i.e. Brandon Marshall
                    player = nflleague.functions.find(name,
                                                      self.season,
                                                      pos=pos,
                                                      players=self.player_game)
                    if player != None:
                        print('***', player.full_name, player.position,
                              player.team, player.player_id)
                        return player.player_id
            return None
        elif pos == 'D/ST':
            return nflleague.standard_nfl_abv(name)
        return None
示例#35
0
def getPlayerID(name,team):
    # Find the player
    player = nflgame.find(name,team)[0]
    return player.gsis_id 
示例#36
0
文件: nfl.py 项目: brandonroeder/nfl
					hits.append(player)
					return hits

def switchpossession(possession):
  switchpos= possession
  if switchpos==game1.home:
    switchpos= game1.away
    return switchpos
  else:
    switchpos=game1.home
    return switchpos


first= Drive(game1.home, "case keenum","pass", "andre johnson", 34, 0,0,1)

player1=nflgame.find(first.player1)
for p in player1:
	player=p

receiver=nflgame.find(first.receiver)
for p in receiver:
	receiver=p


if first.playType=="pass":
	type=" passed"
	print str(player) +type + " the ball to " + str(receiver)+ " for " +str(first.yardage) + " yards."
else:
	type=" ran"
	print str(player)+type+ " the ball for "+ str(first.yardage)+ " yards."
def get_player_object(player_info):
    name, team = player_info.split(", ")
    for p in nfl.find(name):
        if team == p.team:
            player = p
    return player
示例#38
0
def player_team(name):
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    player = playerlist[0]
    return player.team
示例#39
0
 def confirm():
     player1area.clear()
     player2area.clear()
     #Player One stuff
     player1info = []
     points1 = 0
     player1 = str(input1.text()).strip()
     if not nflgame.find(player1, team=None) and player1 != "BUF":
         onenoexist = QListWidgetItem("Player does not exist")
         player1area.addItem(onenoexist)
     else:
         player1info.append(player1)
         def handleActivated():
             int(input12.currentText())
         input12.activated['QString'].connect(handleActivated)
         player1year = int(input12.currentText())
         player1info.append(player1year)
         player1week = str(input13.text()).strip()
         p1w = map(int, player1week.split())
         oneonlyweek = QListWidgetItem("You have not entered any weeks")
         if len(p1w)==0:
             player1area.addItem(oneonlyweek)
         else:
             def currentweek(i):
                 onenotcurrent = QListWidgetItem("Week %d hasn't occurred yet" % p1w[i])
                 if len(p1w) > 0:
                     if p1w[i]>(nflgame.live.current_year_and_week()[1]) and (p1w[i]>0 and p1w[i]<18):
                         if i == len(p1w)-1:
                             player1area.addItem(onenotcurrent)
                             p1w.remove(p1w[i])
                         else:
                             player1area.addItem(onenotcurrent)
                             p1w.remove(p1w[i])
                             if len(p1w)>0:
                                 currentweek(i)
                     else:
                         if i < len(p1w)-1:
                             currentweek(i+1)
             def existweek(i):
                 weeknoexist1 = QListWidgetItem("Week %d does not exist" % p1w[i])
                 if len(p1w) == 0:
                     player1area.addItem(oneonlyweek)
                 else:
                     if p1w[i]<1 or p1w[i]>17:
                         if i == len(p1w)-1:
                             player1area.addItem(weeknoexist1)
                             p1w.remove(p1w[i])
                         else:
                             player1area.addItem(weeknoexist1)
                             p1w.remove(p1w[i])
                             existweek(i)
                     else:
                         if i < len(p1w)-1:
                             existweek(i+1)
             i=0
             existweek(i)
             if len(p1w)>0:
                 currentweek(0)
             
             def byecheck(i):
                 if player1info[0] == "BUF":
                     for r in p1w:
                         if r == 7:
                             onebye = QListWidgetItem("%s has a bye in week %d" % ("BUF", 7))
                             player1area.addItem(onebye)
                             p1w.remove(7)
                 else:
                 
                     for w in byeWeekLists.byeWeeks:
                         for t in w:
                             if nflgame.find(player1info[0], team=None)[0].team == t:
                                 if w[-1] in p1w:
                                     onebye = QListWidgetItem("%s has a bye in week %d" % (t, w[-1]))
                                     player1area.addItem(onebye)
                                     p1w[:] = (value for value in p1w if value != w[-1])
                                     print p1w
             if len(p1w)>0:
                 byecheck(0)
             if len(p1w)==0:
                 onenomoreweeks = QListWidgetItem("You have not entered any more weeks")
                 player1area.addItem(onenomoreweeks)
             if len(p1w) > 0:
                 p1wset = list(set(p1w))
                 player1info.append(p1wset)
                 print "ok"
                 print p1wset
                 p1g = str(ginput1.currentText())
                 player1info.append(p1g)
                 if player1info[0] == "BUF":
                     points1 = fpDefense.fpDefense(player1info[0],player1info[1],player1info[2])
                     item1 = QListWidgetItem("%f" % float(points1))
                     player1area.addItem(item1)
                 else:
                     points1 = fbPlayerPoints.playerPoints(player1info)
                     item1 = QListWidgetItem("%f" % float(points1))
                     if points1 == float('inf'):
                         onenoexist = QListWidgetItem("Player does not exist")
                         player1area.addItem(onenoexist)
                     else:
                         player1found = nflgame.find(player1info[0], team = None)
                         player1area.addItem(item1)
                         p1 = player1found[0]
                         m1 = p1.stats(player1info[1],player1info[2],player1info[3])
                         if 'kicking_xpmade' in m1.stats and 'kicking_xpmissed' in m1.stats:
                             p1xpmade = m1.stats['kicking_xpmade']
                             p1xpm = m1.stats['kicking_xpmissed']
                             p1xpmadein = QListWidgetItem("Extra points made: %d/%d" % (int(p1xpmade),int(p1xpmade + p1xpm)))
                             player1area.addItem(p1xpmadein)
                         if 'kicking_fgm' in m1.stats and 'kicking_fga' in m1.stats :
                             p1fgmade = m1.stats['kicking_fgm']
                             p1fga = m1.stats['kicking_fga']
                             p1fgmadein = QListWidgetItem("Field goals made: %d/%d" % (int(p1fgmade),int(p1fga)))
                             player1area.addItem(p1fgmadein)
                         
                         if p1.position == "K":
                             for w in player1info[2]:
                                 games = nflgame.games(player1info[1], w)
                                 plays = nflgame.combine_plays(games)
                                 allMadeFGs = plays.filter(kicking_fgm = True)
                                 player1area.addItem("Field goals made in week " + str(w) + ":")
                                 for p in allMadeFGs:
                                     if p.players.playerid(p1.playerid):
                                         yards = p.kicking_fgm_yds
                                         player1area.addItem(str(yards) + " ")
                         if 'passing_yds' in m1.stats:
                             p1passyds = m1.stats['passing_yds']
                             p1passydsin = QListWidgetItem("Passing yards: %d" % int(p1passyds))
                             player1area.addItem(p1passydsin)
                         if 'passing_twoptm' in m1.stats:
                             p1tpm = m1.stats['passing_twoptm']
                             p1tpmin = QListWidgetItem("Two-pt conversions made: %d" % int(p1tpm))
                             player1area.addItem(p1tpmin)
                         if 'passing_ints' in m1.stats:
                             p1passints = m1.stats['passing_ints']
                             p1passintsin = QListWidgetItem("Passing ints: %d" % int(p1passints))
                             player1area.addItem(p1passintsin)
                         if 'passing_tds' in m1.stats:
                             p1passtds = m1.stats['passing_tds']
                             p1passtdsin = QListWidgetItem("Passing TDs: %d" % int(p1passtds))
                             player1area.addItem(p1passtdsin)
                         if 'rushing_tds' in m1.stats:
                             p1rushtds = m1.stats['rushing_tds']
                             p1rushtdsin = QListWidgetItem("Rushing TDs: %d" % int(p1rushtds))
                             player1area.addItem(p1rushtdsin)
                         if 'rushing_yds' in m1.stats:
                             p1rushyds = m1.stats['rushing_yds']
                             p1rushydsin = QListWidgetItem("Rushing yards: %d" % int(p1rushyds))
                             player1area.addItem(p1rushydsin)
                         if 'receiving_yds' in m1.stats:
                             p1recyds = m1.stats['receiving_yds']
                             p1recydsin = QListWidgetItem("Receiving yards: %d" % int(p1recyds))
                             player1area.addItem(p1recydsin)
                         if 'receiving_tds' in m1.stats:
                             p1rectds = m1.stats['receiving_tds']
                             p1rectdsin = QListWidgetItem("Receiving TDs: %d" % int(p1rectds))
                             player1area.addItem(p1rectdsin)
                         if 'receiving_twoptm' in m1.stats:
                             p1rectpm = m1.stats['receiving_twoptm']
                             p1rectpmin = QListWidgetItem("Receiving two-pt conversions made: %d" % int(p1rectpm))
                             player1area.addItem(p1rectpmin)
                         if 'fumbles_lost' in m1.stats:
                             p1fum = m1.stats['fumbles_lost']
                             p1fumin = QListWidgetItem("Fumbles lost: %d" % int(p1fum))
                             player1area.addItem(p1fumin)
                         if 'rushing_twoptm' in m1.stats:
                             p1rushtpm = m1.stats['rushing_twoptm']
                             p1rushtpmin = QListWidgetItem("Rushing two-pt conversions made: %d" % int(p1rushtpm))
                             player1area.addItem(p1rushtpmin)
             #Player Two stuff
     player2info = []
     points2 = 0
     player2 = str(input2.text()).strip()
     if not nflgame.find(player2, team=None):
         twonoexist = QListWidgetItem("Player does not exist")
         player2area.addItem(twonoexist)
     else:
         player2info.append(player2)
         def handleActivated():
             int(input22.currentText())
         input22.activated['QString'].connect(handleActivated)
         player2year = int(input22.currentText())
         player2info.append(player2year)
         player2week = str(input23.text()).strip()
         p2w = map(int, player2week.split())
         twoonlyweek = QListWidgetItem("You have not entered any weeks")
         if len(p2w)==0:
             player2area.addItem(twoonlyweek)
         else:
             def currentweek(i):
                 twonotcurrent = QListWidgetItem("Week %d hasn't occurred yet" % p2w[i])
                 if len(p2w) > 0:
                     if p2w[i]>(nflgame.live.current_year_and_week()[1]) and (p2w[i]>0 and p2w[i]<18):
                         if i == len(p2w)-1:
                             player2area.addItem(twonotcurrent)
                             p2w.remove(p2w[i])
                         else:
                             player2area.addItem(twonotcurrent)
                             p2w.remove(p2w[i])
                             if len(p2w)>0:
                                 currentweek(i)
                     else:
                         if i < len(p2w)-1:
                             currentweek(i+1)
             def existweek(i):
                 weeknoexist2 = QListWidgetItem("Week %d does not exist" % p2w[i])
                 if len(p2w) == 0:
                     player2area.addItem(twoonlyweek)
                 else:
                     if p2w[i]<1 or p2w[i]>17:
                         if i == len(p2w)-1:
                             player2area.addItem(weeknoexist2)
                             p2w.remove(p2w[i])
                         else:
                             player2area.addItem(weeknoexist2)
                             p2w.remove(p2w[i])
                             existweek(i)
                     else:
                         if i < len(p2w)-1:
                             existweek(i+1)
             i=0
             existweek(i)
             if len(p2w)>0:
                 currentweek(0)
             
             def byecheck(i):
                 for w in byeWeekLists.byeWeeks:
                     for t in w:
                         if nflgame.find(player2info[0], team=None)[0].team == t:
                             if w[-1] in p2w:
                                 twobye = QListWidgetItem("%s has a bye in week %d" % (t, w[-1]))
                                 player2area.addItem(twobye)
                                 p2w.remove(w[-1])
             if len(p2w)>0:
                 byecheck(0)
             if len(p2w)==0:
                 twonomoreweeks = QListWidgetItem("You have not entered any more weeks")
                 player2area.addItem(twonomoreweeks)
             if len(p2w) > 0:
                 p2wset = list(set(p2w))
                 player2info.append(p2wset)
                 points2 = fbPlayerPoints.playerPoints(player2info)
                 item2 = QListWidgetItem("%f" % float(points2))
                 if points2 == float('inf'):
                     twonoexist = QListWidgetItem("Player does not exist")
                     player2area.addItem(twonoexist)
                 else:
                     player2found = nflgame.find(player2info[0], team = None)
                     player2area.addItem(item2)
                     p2 = player2found[0]
                     m2 = p2.stats(player2info[1],player2info[2])
                     if 'kicking_xpmade' in m2.stats and 'kicking_xpmissed' in m2.stats:
                         p2xpmade = m2.stats['kicking_xpmade']
                         p2xpm = m2.stats['kicking_xpmissed']
                         p2xpmadein = QListWidgetItem("Extra points made: %d/%d" % (int(p2xpmade),int(p2xpmade + p2xpm)))
                         player2area.addItem(p2xpmadein)
                     if 'kicking_fgm' in m2.stats and 'kicking_fga' in m2.stats :
                         p2fgmade = m2.stats['kicking_fgm']
                         p2fga = m2.stats['kicking_fga']
                         p2fgmadein = QListWidgetItem("Field goals made: %d/%d" % (int(p2fgmade),int(p2fga)))
                         player2area.addItem(p2fgmadein)
                     if p2.position == "K":
                         for w in player2info[2]:
                             games = nflgame.games(player2info[1], w)
                             plays = nflgame.combine_plays(games)
                             allMadeFGs = plays.filter(kicking_fgm = True)
                             player2area.addItem("Field goals made in week " + str(w) + ":")
                             for p in allMadeFGs:
                                 if p.players.playerid(p2.playerid):
                                     yards = p.kicking_fgm_yds
                                     player2area.addItem(str(yards) + " ")
                     if 'passing_yds' in m2.stats:
                         p2passyds = m2.stats['passing_yds']
                         p2passydsin = QListWidgetItem("Passing yards: %d" % int(p2passyds))
                         player2area.addItem(p2passydsin)
                     if 'passing_twoptm' in m2.stats:
                         p2tpm = m2.stats['passing_twoptm']
                         p2tpmin = QListWidgetItem("Two-pt conversions made: %d" % int(p2tpm))
                         player2area.addItem(p2tpmin)
                     if 'passing_ints' in m2.stats:
                         p2passints = m2.stats['passing_ints']
                         p2passintsin = QListWidgetItem("Passing ints: %d" % int(p2passints))
                         player2area.addItem(p2passintsin)
                     if 'passing_tds' in m2.stats:
                         p2passtds = m2.stats['passing_tds']
                         p2passtdsin = QListWidgetItem("Passing TDs: %d" % int(p2passtds))
                         player2area.addItem(p2passtdsin)
                     if 'rushing_tds' in m2.stats:
                         p2rushtds = m2.stats['rushing_tds']
                         p2rushtdsin = QListWidgetItem("Rushing TDs: %d" % int(p2rushtds))
                         player2area.addItem(p2rushtdsin)
                     if 'rushing_yds' in m2.stats:
                         p2rushyds = m2.stats['rushing_yds']
                         p2rushydsin = QListWidgetItem("Rushing yards: %d" % int(p2rushyds))
                         player2area.addItem(p2rushydsin)
                     if 'receiving_yds' in m2.stats:
                         p2recyds = m2.stats['receiving_yds']
                         p2recydsin = QListWidgetItem("Receiving yards: %d" % int(p2recyds))
                         player2area.addItem(p2recydsin)
                     if 'receiving_tds' in m2.stats:
                         p2rectds = m2.stats['receiving_tds']
                         p2rectdsin = QListWidgetItem("Receiving TDs: %d" % int(p2rectds))
                         player2area.addItem(p2rectdsin)
                     if 'receiving_twoptm' in m2.stats:
                         p2rectpm = m2.stats['receiving_twoptm']
                         p2rectpmin = QListWidgetItem("Receiving two-pt conversions made: %d" % int(p2rectpm))
                         player2area.addItem(p2rectpmin)
                     if 'fumbles_lost' in m2.stats:
                         p2fum = m2.stats['fumbles_lost']
                         p2fumin = QListWidgetItem("Fumbles lost: %d" % int(p2fum))
                         player2area.addItem(p2fumin)
                     if 'rushing_twoptm' in m2.stats:
                         p2rushtpm = m2.stats['rushing_twoptm']
                         p2rushtpmin = QListWidgetItem("Rushing two-pt conversions made: %d" % int(p2rushtpm))
                         player2area.addItem(p2rushtpmin)
示例#40
0
def findFL(firstName,lastName,team):        ##finds nflgame.player object
    n=firstName + ' ' + lastName            ##by first/last name and team
    return nflgame.find(n,team)
示例#41
0
def prediction(name, scoring):
    # takes player name, type of scoring
    # returns fantasy point prediction for next week
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return None
    player = playerlist[0]
    team = player.team
    position = player.position
    if position == "K":
        return average(name, scoring)
    year, current_week = nflgame.live.current_year_and_week()
    opponent = schedule.opponent(team, year, current_week)
    if opponent == None:
        return "Bye Week"
    bye_week = schedule.bye_week(team, year)
    wk = []
    for x in range(1, current_week):
        if x != bye_week:
            wk.append(x)
    total_weeks = []
    for x in range(1, current_week):
        total_weeks.append(x)
    functionname = scoring + "_player_points"
    getpoints = getattr(points, functionname)
    player_points = points.total_points(getpoints(name, year, wk))
    weeks_played = 0
    for x in player_points:
        if player_points[x] != 0:
            weeks_played += 1
    total_player_stats = stats.player_stats(name, year, wk)
    total_opponent_stats = stats.defense_team_stats(opponent, year,
                                                    total_weeks)
    total_team_stats = stats.offense_team_stats(team, year, total_weeks)
    opponent_weeks_played = len(total_weeks)
    if schedule.bye_week(opponent, year) < current_week:
        opponent_weeks_played -= 1
    if position == "QB":
        # calculate passing yds
        player_avg_passing_yds = float(
            total_player_stats['passing_yds']) / weeks_played
        opponent_avg_passing_yds = float(
            total_opponent_stats['passing_yds_allowed']
        ) / opponent_weeks_played
        prediction_passing_yds = round(
            (player_avg_passing_yds + opponent_avg_passing_yds) / 2)
        # calculate passing tds
        player_avg_passing_tds = float(
            total_player_stats['passing_tds']) / weeks_played
        opponent_avg_passing_tds = float(
            total_opponent_stats['passing_tds_allowed']
        ) / opponent_weeks_played
        prediction_passing_tds = round(
            (player_avg_passing_tds + opponent_avg_passing_tds) / 2)
        # calculate rushing yds
        player_avg_rushing_yds = float(
            total_player_stats['rushing_yds']) / weeks_played
        player_rushing_yds_pct = float(
            total_player_stats['rushing_yds']
        ) / total_team_stats[
            'rushing_yds']  # percentage of total yds the player contributes
        opponent_avg_rushing_yds = float(
            total_opponent_stats['rushing_yds_allowed']
        ) / opponent_weeks_played
        prediction_rushing_yds = round(
            player_rushing_yds_pct *
            (player_avg_rushing_yds + opponent_avg_rushing_yds) / 2)
        # calculate rushing tds
        player_avg_rushing_tds = float(
            total_player_stats['rushing_yds']) / weeks_played
        player_rushing_tds_pct = float(
            total_player_stats['rushing_tds']
        ) / total_team_stats[
            'rushing_tds']  # percentage of total tds the player contributes
        opponent_avg_rushing_tds = float(
            total_opponent_stats['rushing_tds_allowed']
        ) / opponent_weeks_played
        prediction_rushing_tds = round(
            player_rushing_tds_pct *
            (player_avg_rushing_tds + opponent_avg_rushing_tds) / 2)
        # calculate total points
        prediction_total_points = prediction_passing_yds * .04 + prediction_passing_tds * 4 + prediction_rushing_yds * .1 + prediction_rushing_tds * 6
        # return predictions
        return {
            'passing_yds': prediction_passing_yds,
            'passing_tds': prediction_passing_tds,
            'rushing_yds': prediction_rushing_yds,
            'rushing_tds': prediction_rushing_tds,
            'points': prediction_total_points
        }
    elif position == "RB":
        # calculate rushing yds
        player_avg_rushing_yds = float(
            total_player_stats['rushing_yds']) / weeks_played
        player_rushing_yds_pct = float(
            total_player_stats['rushing_yds']
        ) / total_team_stats[
            'rushing_yds']  # percentage of total yds the player contributes
        opponent_avg_rushing_yds = float(
            total_opponent_stats['rushing_yds_allowed']
        ) / opponent_weeks_played
        prediction_rushing_yds = round(
            player_rushing_yds_pct *
            (player_avg_rushing_yds + opponent_avg_rushing_yds) / 2)
        # calculate rushing tds
        player_avg_rushing_tds = float(
            total_player_stats['rushing_tds']) / weeks_played
        player_rushing_tds_pct = float(
            total_player_stats['rushing_tds']
        ) / total_team_stats[
            'rushing_tds']  # percentage of total tds the player contributes
        opponent_avg_rushing_tds = float(
            total_opponent_stats['rushing_tds_allowed']
        ) / opponent_weeks_played
        prediction_rushing_tds = round(
            player_rushing_tds_pct *
            (player_avg_rushing_tds + opponent_avg_rushing_tds) / 2)
        # percentages are generally very low for good players
        if (prediction_rushing_tds == 0 and player_rushing_tds_pct > .35
            ) or weeks_played - player_avg_rushing_tds < 4:
            prediction_rushing_tds += 1.0
        # calculate receiving yds
        player_avg_receiving_yds = float(
            total_player_stats['receiving_yds']) / weeks_played
        player_receiving_yds_pct = float(
            total_player_stats['receiving_yds']
        ) / total_team_stats[
            'passing_yds']  # percentage of total yds the player contributes
        opponent_avg_receiving_yds = float(
            total_opponent_stats['passing_yds_allowed']
        ) / opponent_weeks_played
        prediction_receiving_yds = round(
            player_receiving_yds_pct *
            (player_avg_receiving_yds + opponent_avg_receiving_yds) / 2)
        # calculate receiving tds
        player_avg_receiving_tds = float(
            total_player_stats['receiving_tds']) / weeks_played
        player_receiving_tds_pct = float(
            total_player_stats['receiving_tds']
        ) / total_team_stats[
            'passing_tds']  # percentage of total tds the player contributes
        opponent_avg_receiving_tds = float(
            total_opponent_stats['passing_tds_allowed']
        ) / opponent_weeks_played
        prediction_receiving_tds = round(
            player_receiving_tds_pct *
            (player_avg_receiving_tds + opponent_avg_receiving_tds) / 2)
        # percentages are generally very low for good players
        if (prediction_receiving_tds == 0 and player_receiving_tds_pct > .25
            ) or weeks_played - player_avg_receiving_tds < 4:
            prediction_receiving_tds += 1.0
        # calculate total points
        prediction_total_points = prediction_rushing_yds * .1 + prediction_rushing_tds * 6 + prediction_receiving_yds * .1 + prediction_receiving_tds * 6
        # return predictions
        return {
            'rushing_yds': prediction_rushing_yds,
            'rushing_tds': prediction_rushing_tds,
            'receiving_yds': prediction_receiving_yds,
            'receiving_tds': prediction_receiving_tds,
            'points': prediction_total_points
        }
    elif position == "WR" or position == "TE":
        # calculate receiving yds
        player_avg_receiving_yds = float(
            total_player_stats['receiving_yds']) / weeks_played
        player_receiving_yds_pct = float(
            total_player_stats['receiving_yds']
        ) / total_team_stats[
            'passing_yds']  # percentage of total yds the player contributes
        opponent_avg_receiving_yds = float(
            total_opponent_stats['passing_yds_allowed']
        ) / opponent_weeks_played
        prediction_receiving_yds = round(
            player_receiving_yds_pct *
            (player_avg_receiving_yds + opponent_avg_receiving_yds) / 2)
        # calculate receiving tds
        player_avg_receiving_tds = float(
            total_player_stats['receiving_tds']) / weeks_played
        player_receiving_tds_pct = float(
            total_player_stats['receiving_tds']
        ) / total_team_stats[
            'passing_tds']  # percentage of total tds the player contributes
        opponent_avg_receiving_tds = float(
            total_opponent_stats['passing_tds_allowed']
        ) / opponent_weeks_played
        prediction_receiving_tds = round(
            player_receiving_tds_pct *
            (player_avg_receiving_tds + opponent_avg_receiving_tds) / 2)
        # percentages are generally very low for good players
        if (prediction_receiving_tds == 0 and player_receiving_tds_pct > .25
            ) or weeks_played - player_avg_receiving_tds < 4:
            prediction_receiving_tds += 1
        # calculate total points
        prediction_total_points = prediction_receiving_yds * .1 + prediction_receiving_tds * 6
        # return predictions
        return {
            'receiving_yds': prediction_receiving_yds,
            'receiving_tds': prediction_receiving_tds,
            'points': prediction_total_points
        }
    else:
        return
示例#42
0
def prediction(name, scoring):
    # takes player name, type of scoring
    # returns fantasy point prediction for next week
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return None
    player = playerlist[0]
    team = player.team
    position = player.position
    if position == "K":
        return average(name, scoring)
    year, current_week = nflgame.live.current_year_and_week()
    opponent = schedule.opponent(team, year, current_week)
    if opponent == None:
        return "Bye Week"
    bye_week = schedule.bye_week(team, year)
    wk = []
    for x in range(1, current_week):
        if x != bye_week:
            wk.append(x)
    total_weeks = []
    for x in range(1, current_week):
        total_weeks.append(x)
    functionname = scoring+"_player_points"
    getpoints = getattr(points, functionname)
    player_points = points.total_points(getpoints(name, year, wk))
    weeks_played = 0
    for x in player_points:
        if player_points[x] != 0:
            weeks_played += 1
    total_player_stats = stats.player_stats(name, year, wk)
    total_opponent_stats = stats.defense_team_stats(opponent, year, total_weeks)
    total_team_stats = stats.offense_team_stats(team, year, total_weeks)
    opponent_weeks_played = len(total_weeks)
    if schedule.bye_week(opponent, year) < current_week:
        opponent_weeks_played-=1
    if position == "QB":
        # calculate passing yds
        player_avg_passing_yds = float(total_player_stats['passing_yds'])/weeks_played
        opponent_avg_passing_yds = float(total_opponent_stats['passing_yds_allowed'])/opponent_weeks_played
        prediction_passing_yds = round((player_avg_passing_yds+opponent_avg_passing_yds)/2)
        # calculate passing tds
        player_avg_passing_tds = float(total_player_stats['passing_tds'])/weeks_played
        opponent_avg_passing_tds = float(total_opponent_stats['passing_tds_allowed'])/opponent_weeks_played
        prediction_passing_tds = round((player_avg_passing_tds+opponent_avg_passing_tds)/2)
        # calculate rushing yds
        player_avg_rushing_yds = float(total_player_stats['rushing_yds'])/weeks_played
        player_rushing_yds_pct = float(total_player_stats['rushing_yds'])/total_team_stats['rushing_yds'] # percentage of total yds the player contributes
        opponent_avg_rushing_yds = float(total_opponent_stats['rushing_yds_allowed'])/opponent_weeks_played
        prediction_rushing_yds = round(player_rushing_yds_pct*(player_avg_rushing_yds+opponent_avg_rushing_yds)/2)
        # calculate rushing tds
        player_avg_rushing_tds = float(total_player_stats['rushing_yds'])/weeks_played
        player_rushing_tds_pct = float(total_player_stats['rushing_tds'])/total_team_stats['rushing_tds'] # percentage of total tds the player contributes
        opponent_avg_rushing_tds = float(total_opponent_stats['rushing_tds_allowed'])/opponent_weeks_played
        prediction_rushing_tds = round(player_rushing_tds_pct*(player_avg_rushing_tds+opponent_avg_rushing_tds)/2)
        # calculate total points
        prediction_total_points = prediction_passing_yds*.04 + prediction_passing_tds*4 + prediction_rushing_yds*.1 + prediction_rushing_tds*6
        # return predictions
        return {'passing_yds':prediction_passing_yds, 'passing_tds':prediction_passing_tds, 'rushing_yds':prediction_rushing_yds, 'rushing_tds':prediction_rushing_tds, 'points':prediction_total_points}
    elif position == "RB":
        # calculate rushing yds
        player_avg_rushing_yds = float(total_player_stats['rushing_yds'])/weeks_played
        player_rushing_yds_pct = float(total_player_stats['rushing_yds'])/total_team_stats['rushing_yds'] # percentage of total yds the player contributes
        opponent_avg_rushing_yds = float(total_opponent_stats['rushing_yds_allowed'])/opponent_weeks_played
        prediction_rushing_yds = round(player_rushing_yds_pct*(player_avg_rushing_yds+opponent_avg_rushing_yds)/2)
        # calculate rushing tds
        player_avg_rushing_tds = float(total_player_stats['rushing_tds'])/weeks_played
        player_rushing_tds_pct = float(total_player_stats['rushing_tds'])/total_team_stats['rushing_tds'] # percentage of total tds the player contributes
        opponent_avg_rushing_tds = float(total_opponent_stats['rushing_tds_allowed'])/opponent_weeks_played
        prediction_rushing_tds = round(player_rushing_tds_pct*(player_avg_rushing_tds+opponent_avg_rushing_tds)/2)
        # percentages are generally very low for good players
        if (prediction_rushing_tds == 0 and player_rushing_tds_pct > .35) or weeks_played-player_avg_rushing_tds<4:
            prediction_rushing_tds += 1.0
        # calculate receiving yds
        player_avg_receiving_yds = float(total_player_stats['receiving_yds'])/weeks_played
        player_receiving_yds_pct = float(total_player_stats['receiving_yds'])/total_team_stats['passing_yds'] # percentage of total yds the player contributes
        opponent_avg_receiving_yds = float(total_opponent_stats['passing_yds_allowed'])/opponent_weeks_played
        prediction_receiving_yds = round(player_receiving_yds_pct*(player_avg_receiving_yds+opponent_avg_receiving_yds)/2)
        # calculate receiving tds
        player_avg_receiving_tds = float(total_player_stats['receiving_tds'])/weeks_played
        player_receiving_tds_pct = float(total_player_stats['receiving_tds'])/total_team_stats['passing_tds'] # percentage of total tds the player contributes
        opponent_avg_receiving_tds = float(total_opponent_stats['passing_tds_allowed'])/opponent_weeks_played
        prediction_receiving_tds = round(player_receiving_tds_pct*(player_avg_receiving_tds+opponent_avg_receiving_tds)/2)
        # percentages are generally very low for good players
        if (prediction_receiving_tds == 0 and player_receiving_tds_pct > .25) or weeks_played-player_avg_receiving_tds<4:
            prediction_receiving_tds += 1.0
        # calculate total points
        prediction_total_points = prediction_rushing_yds*.1 + prediction_rushing_tds*6 + prediction_receiving_yds*.1 + prediction_receiving_tds*6
        # return predictions
        return {'rushing_yds':prediction_rushing_yds, 'rushing_tds':prediction_rushing_tds, 'receiving_yds':prediction_receiving_yds, 'receiving_tds':prediction_receiving_tds, 'points':prediction_total_points}
    elif position == "WR" or position == "TE":
        # calculate receiving yds
        player_avg_receiving_yds = float(total_player_stats['receiving_yds'])/weeks_played
        player_receiving_yds_pct = float(total_player_stats['receiving_yds'])/total_team_stats['passing_yds'] # percentage of total yds the player contributes
        opponent_avg_receiving_yds = float(total_opponent_stats['passing_yds_allowed'])/opponent_weeks_played
        prediction_receiving_yds = round(player_receiving_yds_pct*(player_avg_receiving_yds+opponent_avg_receiving_yds)/2)
        # calculate receiving tds
        player_avg_receiving_tds = float(total_player_stats['receiving_tds'])/weeks_played
        player_receiving_tds_pct = float(total_player_stats['receiving_tds'])/total_team_stats['passing_tds'] # percentage of total tds the player contributes
        opponent_avg_receiving_tds = float(total_opponent_stats['passing_tds_allowed'])/opponent_weeks_played
        prediction_receiving_tds = round(player_receiving_tds_pct*(player_avg_receiving_tds+opponent_avg_receiving_tds)/2)
        # percentages are generally very low for good players
        if (prediction_receiving_tds == 0 and player_receiving_tds_pct > .25) or weeks_played-player_avg_receiving_tds<4:
            prediction_receiving_tds += 1
        # calculate total points
        prediction_total_points = prediction_receiving_yds*.1 + prediction_receiving_tds*6
        # return predictions
        return {'receiving_yds':prediction_receiving_yds, 'receiving_tds':prediction_receiving_tds, 'points':prediction_total_points}
    else:
        return
示例#43
0
def player_team(name):
    playerlist = nflgame.find(name, team=None)
    if playerlist == []:
        return False
    player = playerlist[0]
    return player.team
示例#44
0
def fetch_player(name):
    return nflgame.find(name)