Example #1
0
def stats_to_csv():
    cmd = 'stat (every statistic from a game), stat_p (statistics of every player from an entire season) and both'

    print("\nCommands to use: " + cmd)

    choice = input("\nType in the command you want to use: ")
    choice = choice.lower()

    year = input("Year: ")
    __year__ = f'{year}'

    if choice == "stat":
        games.players.csv('player-stats.csv')

    elif choice == "stat_p":
        nflgame.combine(nflgame.games(__year__)).csv('season_stats.csv')

    elif choice == "both":
        games.players.csv('player-stats.csv')

        nflgame.combine(nflgame.games(__year__)).csv('season_stats.csv')

    else:
        print("\nNot a valid command!")
        print("\nUse " + cmd)
Example #2
0
def away_rushing_tds_in_year(year, player, team):
    avg = 0.0
    away_games = nflgame.games(year, home=team)
    players = nflgame.combine(away_games)
    this_player = players.name(player)
    avg += this_player.rushing_tds
    print year, this_player, this_player.rushing_tds, (avg / 8)
Example #3
0
def home_passing_tds_in_year(year, player, team):
    avg = 0.0
    home_games = nflgame.games(year, home=team)
    players = nflgame.combine(home_games)
    this_player = players.name(player)
    avg += this_player.passing_tds
    print year, this_player, this_player.passing_tds, (avg / 8)
Example #4
0
def getRushers(year=None):
	games = nflgame.games(int(year))
	players = nflgame.combine(games)
	myQuery = {}
	for p in players.rushing().sort("rushing_yds").limit(10):
		myQuery[str(p)] = p.rushing_yds
	return render_template('index.html', year=year, myQuery=myQuery, player="rushers")
Example #5
0
def print_top_receivers_by_ben(num_results=50):
    '''
    This will print players with highest targets and 
    show stats of completions and yardage gains.
    '''
    year, current_week = nflgame.live.current_year_and_week()
    weeks = [x for x in range(1, current_week + 1)]

    games = nflgame.games(year, weeks)
    players = nflgame.combine(games, plays=True)

    stars = [[None]]

    #print "\nStars:"
    for p in players.sort('receiving_tar').limit(num_results):
        #print p, p.receiving_tar, p.receiving_rec, p.receiving_yds
        player = p, p.team, p.receiving_tar, p.receiving_rec, p.receiving_yds
        stars.append(player)

    print "\n\nBest Receivers: "
    count = 1
    for p in stars:
        if p[0] != None:
            #print "%d. %s targets: %d times for a total of %d cmplts and %d yards." % (count, p[0], p[1], p[2], p[3])
            name = p[0]
            team = p[1]
            targets = p[2]
            cmplt = p[3]
            yards = p[4]
            completion_percent = int(100 * (float(cmplt) / targets))
            print "{0:<2} {1:<16} {2:<3}  T:{3:<4} R:{4:<4} Y:{5:<5} C:{6:<2}%".format(
                count, name, team, targets, cmplt, yards, completion_percent)
            count += 1
Example #6
0
def print_top_rushers_by_ben(num_results=50, year=None, weeks=None):
    '''
    This will print players with highest rushing yards and 
    show stats of attempts and yardage gains.
    '''
    if year is None:
        year, current_week = nflgame.live.current_year_and_week()
    if weeks is None:
        unused_var, current_week = nflgame.live.current_year_and_week()
        weeks = [x for x in range(1, current_week + 1)]

    games = nflgame.games(year, weeks)
    #print games
    players = nflgame.combine(games, plays=True)

    stars = [[None]]

    #print "\nStars:"
    for p in players.sort('rushing_yds').limit(num_results):
        #print p, p.team, p.rushing_att, p.rushing_yds
        player = p, p.team, p.rushing_att, p.rushing_yds
        stars.append(player)

    print "\n\nBest Rushers: "
    count = 1
    for p in stars:
        if p[0] != None:
            name = p[0]
            team = p[1]
            attempts = p[2]
            yards = p[3]
            avg_yds_carry = int((float(yards) / attempts))
            print "{0:<2} {1:<16} {2:<3}  A:{3:<4} Y:{4:<5} AVG:{5:<2}".format(
                count, name, team, attempts, yards, avg_yds_carry)
            count += 1
Example #7
0
def getPlayerStats(plyr,stat): 
	game = nflgame.games(2012,week=[2,3,4,6])
	players = nflgame.combine(game)
	player = players.name(plyr)
	playerStats = player.stats
	if stat in playerStats:
		print 'stat: ',stat,' value = ',playerStats[stat]
Example #8
0
def getPlayerStats(plyr, stat):
    game = nflgame.games(2012, week=[2, 3, 4, 6])
    players = nflgame.combine(game)
    player = players.name(plyr)
    playerStats = player.stats
    if stat in playerStats:
        print 'stat: ', stat, ' value = ', playerStats[stat]
Example #9
0
	def find(name, team=None):
		players=nflgame.combine()
		hits = []
		for player in players.itervalues():
			if player.name.lower() == name.lower():
				if team is None or team.lower() == player.team.lower():
					hits.append(player)
					return hits
Example #10
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)
Example #11
0
def getQBDataBySeason(year, player):
	season = nflgame.games(year)
	qbs = nflgame.combine(season)
	for p in qbs:
		if(p.name == player):
			return[p.passing_att, p.passing_yds, p.passing_tds, p.passing_ints, p.passing_twoptm,
				   p.rushing_att, p.rushing_yds, p.rushing_tds, p.rushing_twoptm,
				   p.receiving_yds, p.receiving_tds, p.receiving_rec, p.receiving_twoptm,
				   p.games, p.fumbles_tot]
Example #12
0
def top_receiving_targets_this_season():
    year, current_week = nflgame.live.current_year_and_week()
    weeks = [x for x in range(1, current_week + 1)]

    games = nflgame.games(year, weeks)
    players = nflgame.combine(games, plays=True)

    print "\n\Targets:"
    for p in players.sort('receiving_tar').limit(50):
        print p, p.receiving_tar
Example #13
0
def getAllPlayers(year):
    weeks = []
    for x in xrange(1, 18):
        weeks.append(x)
    game = nflgame.games(2009, week=weeks)
    players = nflgame.combine(game)

    playerDict = {}
    for p in players:
        playerDict[str(p.player.full_name)] = str(p.player.gsis_name)
    return playerDict
Example #14
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 generate_fleaflicker_scores(year=2017):
    print("Generating FleaFlicker year {}".format(year))
    f = FleaFlickerRuleset()
    score_df = pd.DataFrame()

    for i in range(1, 18, 1):
        print("Week {}".format(i))
        games = nfl.games(year, week=i)
        players = nfl.combine(games)
        player_scores = dict()
        for player in players:
            player_scores["{}".format(player.playerid,
                                      player.name)] = f.eval_player(player)
        score_df["WEEK_{}".format(i)] = pd.Series(player_scores)

    score_df.fillna(0, inplace=True)
    score_df.to_csv("FLEAFLICKER_YEAR_{}.csv".format(year),
                    index_label="playerid")
Example #16
0
    def eval_game(self, game):
        master_player_scores_dict = defaultdict(float)
        combined_games = nfl.combine([game])
        for drive in game.drives:
            for play in drive.plays:
                for player in play.players:
                    if player.player is not None:
                        scored = self.eval_player(player)
                        master_player_scores_dict["{}".format(
                            player.player.playerid,
                            player.player.name)] += scored

        for player_stats in combined_games:
            scored = self.eval_player(player_stats,
                                      alt_rule_list=self.non_play_rules)
            master_player_scores_dict["{}".format(
                player_stats.player.playerid,
                player_stats.player.name)] += scored
        return master_player_scores_dict
def get_player_stats(player):

    team = player.team
    weeks = range(1, week)

    stats = []
    stats.append(HEADERS[player.position])

    for w in weeks:
        try:
            game = nfl.games(year, w, home=team, away=team)
            players = nfl.combine(game)
            player_game_stats = players.name(player.gsis_name)
            if not player_game_stats:
                player_game_stats = "DNP"
        except:
            player_game_stats = "BYE"
        stats.append(STAT_FUNCTIONS[player.position](player_game_stats))
        stats[-1].append(score_player(player_game_stats, player.position))

    return stats
Example #18
0
def print_top_flex_by_ben(num_results=100):
    '''
    This will print players with highest combined rush/receiving attempts and 
    show stats attempts and yardage gains.
    '''
    year, current_week = nflgame.live.current_year_and_week()
    weeks = [x for x in range(1, current_week + 1)]

    games = nflgame.games(year, weeks)
    players = nflgame.combine(games, plays=True)

    stars = [[]]

    for p in players:
        combined_yards = p.receiving_yds + p.rushing_yds
        combined_attempts = p.receiving_tar + p.rushing_att
        a_player = combined_yards, combined_attempts, p
        stars.append(a_player)

    stars.sort(reverse=True)

    print "\n\nBest Flex: "
    count = 1
    for player in stars:
        if player != []:
            tot_yards = player[0]
            tot_attempts = player[1]
            name = player[2]
            team = player[2].team
            if tot_attempts != 0:
                avg_yds_each = int((float(tot_yards) / tot_attempts))
            else:
                avg_yds_each = 0
            print "{0:<3} {1:<16} {2:<3}  Y:{3:<5} A:{4:<4} AVG:{5:<2}".format(
                count, name, team, tot_yards, tot_attempts, avg_yds_each)
            count += 1
        if count > num_results: break
def fetch_qb_stats():
    # statistics is a dictionary of all player stats
    # the keys are player names, the values are lists
    # each list contains dictionaries that contain single game stats
    statistics = {}
    teams = map(lambda x: x[0], nflgame.teams)
    for year in range(2009, 2015):
        for week in range(1, 18):
            games = nflgame.games(year=year, week=week)
            for index, game in enumerate(games):
                players = nflgame.combine([games[index]])
                # every player with at least 5 passing attempts
                # less than five is not taken into account
                for player in filter(lambda player: player.passing_att >= 5, players.passing()):
                    # if player has not been saved before create entry
                    if not(player.playerid in statistics.keys()):
                        statistics[player.playerid] = create_empty_entry()
                        statistics[player.playerid].update(get_static_data(id = player.playerid))
                    # save data in dictionary
                    statistics[player.playerid][str(year)][str(week)]= {
                        'home': game.home,
                        'away': game.away,
                        'passing_attempts': player.passing_att,
                        'passing_yards': player.passing_yds,
                        'passing_touchdowns': player.passing_tds,
                        'passing_interceptions': player.passing_ints,
                        'passing_two_point_attempts': player.passing_twopta,
                        'passing_two_point_made': player.passing_twoptm,
                        'rushing_attempts': player.rushing_att,
                        'rushing_yards': player.rushing_yds,
                        'rushing_touchdowns': player.rushing_tds,
                        'rushing_two_point_attempts': player.rushing_twopta,
                        'rushing_two_point_made': player.rushing_twoptm,
                        'fumbles': player.fumbles_tot,
                        'played': True
                        }
    return statistics
Example #20
0
import nflgame

while True:
    year = raw_input("Enter year to pull nflgame data from:")
    fileName = "season" + str(year) + ".csv"
    try:
        nflgame.combine(nflgame.games(int(year))).csv(fileName)
        break
    except:
        print "Invalid year"
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 30 15:36:25 2017

@author: Tyler
"""

import nflgame
import csv


games = nflgame.games(2017, week=[1,2,3,4,5,6])
players = nflgame.combine(games)

#header = ['Name', 'Position', 'Team', 'Passing_Yards', 'Rushing_Yards', 'Receiving_Yards', 'Passing_TDs', 'Rushing_TDs',	
 #         'Receiving_TD','FG_Made','FG_Missed', 'Extra_Points_Made', 'Interceptions',	'Fumbles_Lost']

header = ['Name', 'Position', 'Team', 'Passing_Yards','Rushing_Yards','Receiving_Yards',	'Passing_TDs',	'Rushing_TDs',	
          'Receiving_TD',	'FG_Made', 'FG_Missed',	'Extra_Points_Made', 'Interceptions_Thrown', 'Fumbles_Lost', 'Interceptions',
          'Forced_Fumbles','Sacks','Blocked_Kicks','Blocked_Punts','Safeties','Kickoff_Return_TD','Punt_Return_TD','Defensive_TD', 'Punting_i20', 'Punting_Yards']

with open('nfl_stats_first3.csv', 'w') as fp:
    wr = csv.writer(fp, delimiter=',', lineterminator='\n')
    wr.writerow(header)
    for p in players:
        wr.writerow([p,p.guess_position, p.team,p.passing_yds,p.rushing_yds, p.receiving_yds, p.passing_tds,p.rushing_tds, 
                     p.receiving_tds, p.kicking_fgm, p.kicking_fga - p.kicking_fgm, p.kicking_xpmade, p.passing_int,  p.fumbles_lost,
                     p.defense_int, p.defense_ffum, p.defense_sk, p.defense_xpblk+p.defense_fgblk, p.defense_puntblk, p.defense_safe,
                     p.kickret_tds, p.puntret_tds, p.defense_tds, p.punting_i20, p.punting_yds])
"Import nfl game data into csv and then convert to pandas dataframe"

import nflgame

# For each season, save to a separate csv file
for i in range(2009, 2018):
    filename = "season" + str(i) + ".csv"
    nflgame.combine(nflgame.games(i)).csv(filename)
Example #23
0
import nflgame as nfl

games = nfl.games(2014)
players = nfl.combine(games)

write_file = open('qbs.csv', 'w')

PLAYER_FILTERS = [
    players.passing,
    players.rushing,
    players.receiving,
]

for player_filter in PLAYER_FILTERS:
    for player in player_filter():
        stats = [
            player.name,
            player.team,
            player.guess_position
        ]
        write_file.write(",".join(stats) + "\n")

write_file.close()
Example #24
0
import nflgame


print ('Rushing attempts, rushing yards, rushing touchdowns')
games = nflgame.games(2015, week=6)
players = nflgame.combine(games)
for p in players.rushing().sort("rushing_yds").limit(10):
	print p, p.rushing_att, p.rushing_yds, p.rushing_tds


plays = nflgame.combine_plays(games)
for p in plays.sort('passing_yds').limit(5):
    print p
import nflgame
import reverie as rev
import os
import pandas as pd
import tqdm

dir_path = os.path.dirname(os.path.realpath(__file__))
output_directory = os.path.abspath(
    os.path.join(dir_path, '..', 'data', 'game_data'))

os.makedirs(output_directory, exist_ok=True)
years = list(range(2009, 2020))
for year in tqdm.tqdm(years):
    csv_filename = os.path.join(output_directory, f'season{year}.csv')
    parquet_filename = os.path.join(output_directory, f'{year}.parquet')
    nflgame.combine(nflgame.games(year)).csv(csv_filename)

    df = pd.read_csv(csv_filename)
    df.to_parquet(parquet_filename)
    os.remove(csv_filename)
Example #26
0
import nflgame

nflgame.combine(nflgame.games(2009)).csv('season2009.csv')
nflgame.combine(nflgame.games(2010)).csv('season2010.csv')
nflgame.combine(nflgame.games(2011)).csv('season2011.csv')
nflgame.combine(nflgame.games(2012)).csv('season2012.csv')
nflgame.combine(nflgame.games(2013)).csv('season2013.csv')
nflgame.combine(nflgame.games(2014)).csv('season2014.csv')
nflgame.combine(nflgame.games(2015)).csv('season2015.csv')
import nflgame

allweeks  = nflgame.games(2012)
players = nflgame.combine(allweeks)

rushers = players.rushing()
top10 = rushers.sort("rushing_yds").limit(10)

top10.csv('top10rushers.csv')
Example #28
0
    output = {}
    for p in players:
        output[p.name] = [calculate_fantasy_points(p)]
    return output


def print_players(players):
    """
    :param players: Dictionary of players and their fantasy points.
    :return: None
    """
    for key, value in players.iteritems():
        if value != 0:
            if len(value) == 2:
                print key, value


# All the games week 1, of the 2013 season.
games = nflgame.games(2015)
players = nflgame.combine(games, plays=True)
out = create_dict_points(players.sort('receiving_tar').limit(50))
#print_players(out)

with open('salaries2016.csv', 'rU') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        if row[0] in out:
            out[row[0]].append(row[1])

print_players(out)
Example #29
0
import pandas as pd

data = pd.DataFrame(
    0,
    index=[1],
    columns=['year', 'name', 'thisAtt', 'thisYds', 'nextAtt', 'nextYds'])
garbage = []

yearno = 2009
while yearno < 2015:
    gamesthis = N.games(yearno, kind='REG')
    gamesnext = N.games(yearno + 1, kind='REG')
    playerstatsthis = N.combine_game_stats(gamesthis)
    #playerstatsnext = N.combine_game_stats(gamesnext)
    #playersthis = N.combine(gamesthis)
    playersnext = N.combine(gamesnext)

    for p in playerstatsthis.rushing():
        player = playersnext.name(str(p))
        try:
            if p.rushing_att > 25 and player.rushing_att > 25:
                data = data.append(dict(year=yearno,
                                        name=p,
                                        thisAtt=p.rushing_att,
                                        thisYds=p.rushing_yds,
                                        nextAtt=player.rushing_att,
                                        nextYds=player.rushing_yds),
                                   ignore_index=True)
                #print(str(p), p.rushing_att, p.rushing_yds, player.rushing_att, player.rushing_yds)
        except:
            garbage.append(str(p))
with open('Player_List.csv', 'wb') as csvwrite:
    gmewriter = csv.writer(csvwrite, delimiter=',')
    gmewriter.writerow([
        'Gamekey', 'Home_team', 'Away_Team', 'Player_Short_Name',
        'Player_Team', 'Home_Team'
    ])
    for key in schedule_games:
        game = schedule_games[key]
        if game['year'] > 2012 and game['season_type'] == 'REG':
            id1 = game['gamekey']
            game1 = game['year']
            week1 = game['week']
            home1 = game['home']
            away1 = game['away']
            games = nflgame.games(game1, week1, home1, away1)
            players = nflgame.combine(games)
            for p in players:
                gmewriter.writerow([id1, home1, away1, p.name, p.team, p.home])

#Next we are going to start with some specific stats - passing, rushing, defense, kicking, puntreturn, etc.
#Then the plan is to join this back to the roster files in order to get data

#Let's Start with Passing

with open('passing_data.csv', 'wb') as csvwriter:
    passwriter = csv.writer(csvwriter, delimiter=',')
    passwriter.writerow(['Gamekey', 'Home_team', 'Away_Team', 'Day_of_week', \
    'Month', 'Day', 'Year', 'Week', 'Player_Short_Name', 'Player_Team', \
    'Home_Team',  'passing_att', 'passing_incmp', 'passing_cmp', 'passing_tds',\
    'passing_int', 'passing_yds', 'passing_twoptm', 'passing_yds_FF_pts', \
    'passing_tds_FF_pts', 'passing_twopt_FF_pts', 'intercept_FF_pts', 'total_FF_pts'])
Example #31
0
#import json
#from bs4 import BeautifulSoup
#import pandas as pd
import nflgame

games_all = nflgame.games(range(2009, 2016))
games2 = nflgame.games(range(2009, 2016), kind='REG')
len(games_all)  #1553 when 2009-2015

players = nflgame.combine_game_stats(games_all)

for p in players.rushing().sort("rushing_yds").limit(10):
    print p, p.rushing_yds

# cd ~/Desktop/DAT8/project/qb_projections
nflgame.combine(games_all).csv('season2009_2015.csv')

test = games_all[1552]
test.players.filter(passing_yds=lambda x: x > 0)
test.players.filter(pos=lambda x: x == 'qb').csv('qb_test3.csv')
test.players.filter(passing_att=lambda x: x > 5).csv('qb_test3.csv')

import sys
sys.stdout()

import nfldb
db = nfldb.connect()
q = nfldb.Query(db)

q.game(season_year=2013, season_type='Regular', week=17, team='NE')
q.play_player(team='NE')
Example #32
0
#import json
#from bs4 import BeautifulSoup
#import pandas as pd
import nflgame

games_all = nflgame.games(range(2009, 2016))
games2 = nflgame.games(range(2009, 2016), kind='REG')
len(games_all) #1553 when 2009-2015

players = nflgame.combine_game_stats(games_all)

for p in players.rushing().sort("rushing_yds").limit(10):
    print p, p.rushing_yds

# cd ~/Desktop/DAT8/project/qb_projections
nflgame.combine(games_all).csv('season2009_2015.csv')

test = games_all[1552]
test.players.filter(passing_yds=lambda x:x>0)
test.players.filter(pos=lambda x:x=='qb').csv('qb_test3.csv')
test.players.filter(passing_att=lambda x:x>5).csv('qb_test3.csv')

import sys
sys.stdout()

import nfldb
db = nfldb.connect()
q = nfldb.Query(db)

q.game(season_year=2013, season_type='Regular', week=17, team='NE')
q.play_player(team='NE')
import nflgame
import csv
import itertools


print 'nflgame API loaded and updated'
week = raw_input('What week of the season, 1-17?: ')
filename = 'nfl_weeklystats_week' + str(week) + '.csv'
f = open(filename,'a')
numGames = raw_input('Enter the number of games to gather data for: ')
f.write(numGames + ',12\n')
for i in range(int(numGames)):
        awayTeam = raw_input('Enter the AWAY team: ').upper()
        homeTeam = raw_input('Enter the HOME team: ').upper()
        HT_AVG1 = nflgame.games_gen(2013, home=homeTeam, away=homeTeam, kind="REG")
        QBs = nflgame.combine(HT_AVG1)
        print 'Which HOME QB statistics to use?'
        for p in QBs.passing().sort("passing_att"):
                print p
        QBname = raw_input('Enter the quarterback name as it is written: ')        
        QB_AVG = nflgame.games_gen(2013, kind="REG")
        playerStats = nflgame.combine(QB_AVG)
        QBplayer = playerStats.name(QBname)
        AT_AVG1 = nflgame.games_gen(2013, home=awayTeam, away=awayTeam, kind="REG")
        aQBs = nflgame.combine(AT_AVG1)
        print 'Which AWAY QB statistics to use?'
        for p in aQBs.passing().sort("passing_att"):
                print p
        aQBname = raw_input('Enter the quarterback name as it is written: ')        
        aQB_AVG = nflgame.games_gen(2013, kind="REG")
        playerStats = nflgame.combine(aQB_AVG)
Example #34
0
import nflgame

players = nflgame.combine(nflgame.games(2012))

for p in players.rushing().sort("rushing_yds").limit(100):
    print p, p.rushing_att, p.rushing_yds, p.rushing_tds
Example #35
0
import nflgame

#games = nflgame.games(2013, week=1)
#games(year, week=None, home=None, away=, kind='REG')

i=1
k=1
while i < 18:
	try:
		nflgame.combine(nflgame.games(2012,i, away="SF", home="SF")).csv(str(k)+".csv")
		k=k+1
	except Exception:
    		pass
	print i
	i=i+1
Example #36
0
        schedulewriter.writerow(['week', 'home', 'away', 'year', 'weekday', 'month', 'day'])
        for item, info in schedule_games.iteritems():
            if info['year'] == year and info['season_type']=='REG':
                row = info['week'], info['home'], info['away'], info['year'], info['wday'], info['month'], info['day']
                schedulewriter.writerow(row)
#######################################################################################################################
"""
Listing top Receivers Targeted
"""
import nflgame

year, current_week = nflgame.live.current_year_and_week()
weeks = [x for x in range(1, current_week+1)]

games = nflgame.games(year, weeks)
players = nflgame.combine(games, plays=True)

for p in players.sort('receiving_tar').limit(50):
    print p, p.receiving_tar, p.team

#######################################################################################################################
"""
Exports all scores
"""
import nflgame
import csv

def writeScoresToCSV(year):
    games = nflgame.games_gen(year)
    with open('Scores_'+str(year)+'.csv', 'wb') as csvfile:
        scorewriter = csv.writer(csvfile, delimiter=',')
Example #37
0
import nflgame
from nflgame import game
import json
import csv
import requests
import time
from datetime import date

date = date.today()

'''

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Token token=ee1343e93b0153c0b6c84f891254b3dc',
    'Accept': 'application/vnd.stattleship.com; version=1',
}

data = requests.get('https://api.stattleship.com/football/nfl/team_season_stats', headers=headers)

print(data.json());

with open("nflteamdata{0}.json".format(date), 'w') as outfile:
	json.dump(data.json(), outfile, indent=4, sort_keys=True, separators=(',', ':'))

'''



nflgame.combine(nflgame.games(2016)).csv("nflplayerdata-{0}.csv".format(date))
Example #38
0
#!/usr/bin/python2.7

import nflgame 

nflgame.combine(nflgame.games(2014, 2)).csv("2014 week 2.csv")