本文整理汇总了Python中nfldb.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: week_choices
def week_choices(request):
response_data = week_choices_dict()
db = nfldb.connect()
current_week = nfldb.current(db)
response_data['current_year'] = current_week[1]
response_data['current_week'] = current_week[2]
return HttpResponse(json.dumps(response_data), content_type="application/json")
示例2: showStatDefense
def showStatDefense(team_input, week_input):
statJSON = {}
#STAT_STRING_LIST_DEFENSE=['defense_sk', 'defense_int', 'defense_frec', 'defense_safe', 'defense_frec_tds', 'defense_int_tds', 'defense_misc_tds', 'kickret_tds']
stat_string_list = STAT_STRING_LIST_DEFENSE
stat_season_totals = [0 for x in range(len(stat_string_list))]
#stat_string_list = ['puntret_tds']
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2012, season_type='Regular', week=week_input, team=team_input)
for p in q.as_games():
if p.away_team == team_input:
statJSON['points_allowed']= p.home_score
else:
statJSON['points_allowed']= p.away_score
#check for bye week all stats = 0
if len(q.as_games())==0:
team_home_away = 'bye'
for index in xrange(len(stat_string_list)):
statJSON[stat_string_list[index]] = 0
return statJSON
for index in xrange(len(stat_string_list)):
stat = showStat(stat_string_list[index], team_input, week_input)
statJSON[stat_string_list[index]] = stat
#stat_season_totals[index] +=stat
statJSON['defense_touchdowns'] = statJSON['defense_int_tds'] + statJSON['defense_frec_tds'] + statJSON['defense_misc_tds']
# for key, index in statJSON.items():
#print ("Totals Week: " +str(week_input) + " " + team_input + " " + key+ " "+ str(index) + '\n')
return statJSON
示例3: playerstats
def playerstats(self, **kwargs):
player = kwargs['player']
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=kwargs['season'], season_type='Regular')
if kwargs['targtype'] == "non-redzone":
pos1 = nfldb.FieldPosition.from_str('OWN 1')
pos2 = nfldb.FieldPosition.from_str('OPP 21')
#OPP 20 to OPP 10 yardline
elif kwargs['targtype'] == 'redzone':
pos1 = nfldb.FieldPosition.from_str('OPP 20')
pos2 = nfldb.FieldPosition.from_str('OPP 11')
#OPP 10 to OPP 6
elif kwargs['targtype'] == 'goaline1':
pos1 = nfldb.FieldPosition.from_str('OPP 10')
pos2 = nfldb.FieldPosition.from_str('OPP 6')
# OPP 5 to OPP 3
elif kwargs['targtype'] == 'goaline2':
pos1 = nfldb.FieldPosition.from_str('OPP 5')
pos2 = nfldb.FieldPosition.from_str('OPP 3')
#OPP 2 or OPP 1
elif kwargs['targtype'] == 'goaline3':
pos1 = nfldb.FieldPosition.from_str('OPP 2')
pos2 = nfldb.FieldPosition.from_str('OPP 1')
q.play(yardline__ge=pos1)
q.play(yardline__le=pos2)
q.player(full_name= player)
for pp in q.as_aggregate():
return pp
示例4: showPlayerStat
def showPlayerStat(player_ID, week_input):
statJSON={}
stat_string_list = STAT_STRING_LIST
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2012, season_type='Regular', week=week_input)
q.player(player_id=player_ID)
# for p in q.sort([('gsis_id', 'asc'), ('time', 'asc')]).as_plays():
# print p
for p in q.as_aggregate():
for index in xrange(len(stat_string_list)):
key = stat_string_list[index]
value = eval('p.'+stat_string_list[index])
statJSON[key]=value
#print key, value
#Check for empty week stat due to BYE week
if len(q.as_aggregate() )==0:
for index in xrange(len(stat_string_list)):
key = stat_string_list[index]
statJSON[key]=0
return statJSON
示例5: getOpponent
def getOpponent(team_input, week_input):
statJSON = {}
STAT_STRING_OPPONENT = ['passing_yds', 'passing_tds', 'rushing_yds','receiving_yds', 'receiving_tds' ,'kickret_tds', 'fumbles_rec_tds','rushing_tds']
stat_string_list = STAT_STRING_OPPONENT
stat_season_totals = [0 for x in range(len(stat_string_list))]
#stat_string_list = ['puntret_tds']
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2012, season_type='Regular', week=week_input, team=team_input)
#check for bye week all stats = 0
if len(q.as_games())==0:
team_home_away = 'bye'
statJSON['opponent']= 'bye'
for index in xrange(len(stat_string_list)):
statJSON[stat_string_list[index]+'_allowed'] = 0
return statJSON
for p in q.as_games():
if p.away_team == team_input:
opponent = p.home_team
else:
opponent = p.away_team
statJSON['opponent'] = opponent
#print "Team: ", team_input, " has Opponent: ", opponent
q.game(season_year=2012, season_type='Regular', week=week_input, team=opponent)
for p in q.as_games():
for index in xrange(len(stat_string_list)):
stat = showStat(stat_string_list[index], opponent, week_input)
statJSON[stat_string_list[index]+'_allowed'] = stat
stat_season_totals[index] +=stat
#print statJSON
return statJSON
示例6: makeWinMatrix
def makeWinMatrix(players):
db = nfldb.connect()
# Get number of players in list
size = len(players)
playerInd = {}
ind = 0
print '\n index\tname'
for x in players:
x = x.split(' (')
print str(ind) + '\t' + x[0]
qd = nfldb.Query(db)
qd.game(season_year=2015, season_type='Regular')
pp = qd.player(full_name=x[0]).as_aggregate()
for x in pp:
playerInd[ind] = x
ind += 1
xcord = 0
allWins = []
allLoses = []
while xcord < size - 1:
winsList = []
losesList = []
check = playerInd[xcord]
loses = 0
ycord = 0
while ycord < size - 1:
losesList.append(0)
if ycord != xcord:
against = playerInd[ycord]
wins, loses = calcWins(check, against, loses)
winsList.append(wins)
else:
winsList.append(0)
ycord += 1
losesList[xcord] = loses
rowWins = numpy.array([winsList])
rowLoses = numpy.array([losesList])
allWins.append(rowWins)
allLoses.append(rowLoses)
xcord += 1
matrixWins = numpy.vstack(allWins)
matrixLoses = numpy.vstack(allLoses)
print '---------- Wins ----------'
print(matrixWins)
print '---------- Loses ----------'
print(matrixLoses)
return matrixWins, matrixLoses
示例7: games_played
def games_played(self,player,year):
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=year, season_type='Regular',)
q.player(full_name=player)
if q.as_games() != None:
return len(q.as_games())
else:
return 0
示例8: __init__
def __init__(self, name, seasonyear):
self.__name = name
self.__seasonYear = seasonyear
__nfldbConnect = nfldb.connect()
q = nfldb.Query(__nfldbConnect).game(season_year=self.__seasonYear, season_type='Regular')
for pp in q.as_aggregate():
print pp.player
return
示例9: __init__
def __init__(self, name = "Team", short_name = "UNK", year = 2009):
self.name = name
self.short_name = short_name
self.possession = False
self.year = year
self.db = nfl.connect()
self.q = nfl.Query(self.db)
self.q.player(team=short_name)
self.roster = self.q.as_aggregate()
print self.name
示例10: testCheck
def testCheck(self):
return
db = nfldb.connect()
calc = Trade.Calculator(PURE)
q = nfldb.Query(db)
q.game(season_year=2009, season_type='Regular')
rushers = q.sort('rushing_yds').limit(100).as_aggregate()
receivers = q.sort('receiving_yds').limit(100).as_aggregate()
passers = q.sort('passing_yds').limit(35).as_aggregate()
players = Trade.aggpps_to_players(rushers + receivers + passers)
for rec,yds in calc.sort_position_more(players, 'TE'):
print "{} {}".format(rec,yds)
示例11: query_players_by_year
def query_players_by_year(self, year):
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=year, season_type='Regular')
# Only retrieving a limited amount to avoid more manual position tagging
rushers = q.sort('rushing_yds').limit(100).as_aggregate()
receivers = q.sort('receiving_yds').limit(100).as_aggregate()
passers = q.sort('passing_yds').limit(35).as_aggregate()
players = self.aggpps_to_players(rushers + receivers + passers)
return players
示例12: get_weeklypts
def get_weeklypts(team, week, year):
players = []
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=year, season_type='Regular', team=team, week=week )
for p in q.as_players():
if p.team == team and p.team != "UNK":
pts = get_weeklypoints(year,p.full_name, week)
if pts != 0:
players.append((p.full_name,str(p.position),str(p.team), week, pts))
return players
示例13: module1
def module1():
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2013, season_type='Regular')
for pp in q.sort('passing_yds').limit(10).as_aggregate():
print pp.player, pp.passing_yds
q.player(full_name="Tom Brady").play(passing_tds=1)
for play in q.as_plays():
print play
示例14: nfldb
def nfldb(year = 2013):
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=year, season_type='Regular')
for pp in q.sort('passing_yds').limit(15).as_aggregate():
print pp.player, pp.passing_yds, pp.rushing_tds
print "\n"
for pp in q.sort('rushing_yds').limit(15).as_aggregate():
print pp.player, pp.rushing_yds, pp.rushing_tds
示例15: index
def index(request, year=0, week=0, season_type='Regular'):
db = nfldb.connect()
current = nfldb.current(db)
if year == 0:
season_type, year, week = nfldb.current(db)
return redirect('index', year, season_type.name, week)
q = nfldb.Query(db).game(
season_year=year,
season_type=season_type,
week=week).sort('start_time')
games = q.as_games()
return render(request, 'games/index.html',
{'games_list': games, 'current': current, 'year': year})