Open Coop197823 opened 7 years ago
What is the definition of a "deep" pass vs. a "short" pass?
passing_cmp_air_yds
(the number of yards a ball traveled in the air) is recorded for quarterbacks and receiving_yds
and receiving_yac_yds
are included for receivers so finding how many yards the ball traveled in the air is trivial.
import nflgame
games = nflgame.games(2016, 17, 'MIN', 'MIN', 'REG')
plays = nflgame.combine_plays(games)
for play in plays.filter(receiving_rec__gt=0):
for player in play.players:
if player.player.position in ['WR', 'TE', 'RB']:
print play
print '\t', player, player.player.position
print '\t', player.formatted_stats()
print '\tpass_depth:', player.receiving_yds-player.receiving_yac_yds
(CHI, CHI 30, Q4, 1 and 10) (11:21) (Shotgun) M.Barkley pass short right to D.Brown to CHI 36 for 6 yards (C.Munnerlyn).
D.Brown TE
receiving_yds: 6, receiving_rec: 1, receiving_tar: 1, receiving_yac_yds: 2
pass_depth: 4
(CHI, CHI 22, Q4, 2 and 7) (9:13) (Shotgun) D.Fales pass short right to C.Meredith to CHI 34 for 12 yards (H.Smith).
C.Meredith WR
receiving_yds: 12, receiving_rec: 1, receiving_tar: 1, receiving_yac_yds: 2
pass_depth: 10
(CHI, CHI 34, Q4, 1 and 10) (3:26) (Shotgun) D.Fales pass short left to J.Langford to CHI 44 for 10 yards (E.Lamur).
J.Langford RB
receiving_yds: 10, receiving_rec: 1, receiving_tar: 1, receiving_yac_yds: 13
pass_depth: -3
Wow, great. Yes you are right it is trivial! Thank you so much for the insights! Would the left, middle, or right designation be available?
You do have to do a little more gymnastics to identify how long the passes are for incomplete passes. passing_incmp_air_yds
is a stat for quarterbacks, but no corresponding value is assigned to receivers, they'll only get a receiving_tar
on the play.
As for your second question, there aren't any stats that correspond to the direction of the play. I think you'd have to parse the play description to obtain those.
I think completed passes would be adequate. I can calculate average depth of reception as well as the percent receptions are at a certain distance to create something to determine what type the receiver is. I thought I was going to have to pay $300 a month at pro-football focus for this data, so this is awesome! The left or right stuff is just an ask, but I do not think crucial to my models, so I really appreciate this project!!
one more quick follow up. I have modified the code a bit to pull the player plus the position regarless of TE, WR, or RB, and when I run the code I get the error:
AttributeError: 'NoneType' object has no attribute 'position'
What is the best work around for this type of error when there is no team or position for that player and play?
Here is my updated code:
import nflgame
games = nflgame.games(2016, 17, 'MIN', 'MIN', 'REG')
plays = nflgame.combine_plays(games)
for play in plays.filter(receiving_rec__gt=0):
for player in play.players:
print '\t', player, player.player.position, '\tpass_depth:', player.receiving_yds-player.receiving_yac_yds
Even when I do filter for TE, WR and RB, I still get the error.
You might be hitting a player that is no longer on an active roster and therefore has no metadata present in nflgame
.
I think you can try player.guess_position
, though I'm not positive that won't still result in a NoneType
object for that player (your code sample does not cause any AttributeErrors
for me).
Can I ask what version of nflgame and python you are using? I am on python 2.7.8 with nflgame 1.2.20 running on windows 7. Would my version of python cause problems? I tried using player.guess_position, and it still gets that error. Maybe I should try to update the layer database. How do I update the player database for when I run nflgame-update-players in my python gui, I get the error:
NameError: name 'update' is not defined
Looks like same.
But I think it's entirely possible that each library's players.json
file ends up being different as nflgame-update-players
gets run over the course of a season. (a json file that gets updated weekly would capture all of the player additions throughout the course of the season, whereas a file that gets updated at only the beginning and end of the season would miss out on players that appeared temporarily on an active roster but dropped off before the conclusion of the season).
If your sample code were a bit more verbose we might be able to pinpoint exactly what the problem is and try to work around it. Try adding a line before the offending line that might help us identify where the problem lies.
for player in play.players:
print player, dir(player)
print '\t', player, player.player.position, '\tpass_depth:', player.receiving_yds-player.receiving_yac_yds
Thanks for your patience. I had installed nflgame last year and just got back to it a few days ago. It seems all I needed to do was to update the database using the code:
import nflgame.update_players
nflgame.update_players.run()
It now goes through and adds all the player data as appropriate. Again, thank you for your help and patience!!
No problem, am happy to help.
As an alternative to updating that way, @BurntSushi has added a convenience script to your /Python/Scripts directory. Can just run the file nflgame-update-players
from that location.
I have noticed within the play by play game texts for passes, it includes data on Depth of Pass (where the receiver catches the ball) either "Deep" or "Short". Is it possible to add a new category that includes the total number of passes that were caught deep or short (and for that matter left or right, as well as rush left, middle, or right) for each player? I have been playing around with this in excel as it seems to be a good statistic in looking at receivers and determining what type of receiver they are (deep threat or possession). Thanks for entertaining my request!