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 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
def kickerScore(player, year, week): points = fpPlayer.fantasyPoints(player,year,week) lf = player statistics = lf.stats(year, week) if 'kicking_xpmissed' in statistics.stats: xpMissed = statistics.stats['kicking_xpmissed'] if 'kicking_xpmade' in statistics.stats: xpMade = statistics.stats['kicking_xpmade'] if 'kicking_fgm' in statistics.stats: fgMade = statistics.stats['kicking_fgm'] if 'kicking_fgm' in statistics.stats and 'kicking_fga' in statistics.stats: fgMissed = statistics.stats['kicking_fga'] - statistics.stats['kicking_fgm'] points = points + xpMade*1 - xpMissed*1 + fgMade*3 - fgMissed*3 games = nflgame.games(year, week) plays = nflgame.combine_plays(games) allMadeFGs = plays.filter(kicking_fgm = True) for p in allMadeFGs: if p.players.playerid(lf.playerid): yards = p.kicking_fgm_yds if yards >= 40: points = points + 1 if yards >= 50: points = points + 1 return points