Skip to content

Added the other types methods to get player stats. Added an annual st…#4

Open
matthewstirling wants to merge 5 commits intomdgoldberg:masterfrom
matthewstirling:nfl_player_stats
Open

Added the other types methods to get player stats. Added an annual st…#4
matthewstirling wants to merge 5 commits intomdgoldberg:masterfrom
matthewstirling:nfl_player_stats

Conversation

@matthewstirling
Copy link
Copy Markdown

…ats merge method.

I added methods to get defensive, return stats, kicking stats, and other types of statistic tables found on pfr pages. I also created a all_annual_stats method in player to combine all the different types of locations for annual player stats into one method call with a df return.

@matthewstirling
Copy link
Copy Markdown
Author

I added the collegeid method from the other branch. I'll close that pull request.

Copy link
Copy Markdown
Owner

@mdgoldberg mdgoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments. Thanks again for contributing!! Love reading your PRs. Great to look over the nfl code, which I haven't touched for a while, and to see it being expanded.

Comment thread sportsref/nfl/players.py Outdated
return college

@sportsref.decorators.memoize
def collegeid(self):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there already a "college" function right above this one?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other college function returns the college. this returns the player's college id so you could cross-reference their college page.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess maybe the name isn't clear, but the other function returns the college ID too, I'm pretty sure

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I've been clear. For Brady:
p.college() yields u'michigan'
p.collegeid() yields u'tom-brady-1'
The first one is Tom Brady's college's ID for the cfb website. The one I added yields Tom Brady's ID for the cfb website. My method is useful for looking up college info for an existing NFL player.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I see. I'm sorry I should have figured that out, I didn't look closely enough. Sounds good, want to change it to college_player_id() just to be super clear? Usually in comments and stuff when I say "{X} ID" I mean an ID of an X, where X is "boxscore", "player", etc. so I think just to be clear it should be college_player_id() or ncaaf_player_id() maybe?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to ncaaf_player_id()

Comment thread sportsref/nfl/players.py Outdated
:returns: Pandas DataFrame with defense/fumble stats.
"""
doc = self.get_doc()
table = (doc('#all_defense') if kind == 'R'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bit cleaner (and I just made this change myself to the pre-existing functions, will be included in the next release) to change these table assignments to doc('table#defense') for example, instead of doc('#all_defense'). That's more explicit, and the new utils.get_html should allow you to access table#defense. I realize utils.parse_table works on the div#all_defense div as well, but since this could change, I think it makes the most sense to use table#defense. It'd be great if you could make this change here and on the other functions you added (basically just adding table before the # and getting rid of all_).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I changed all of the methods I wrote to incorporate this approach.

Comment thread sportsref/nfl/players.py

@sportsref.decorators.memoize
@sportsref.decorators.kind_rpb(include_type=True)
def all_annual_stats(self, kind='R'):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't actually tested this function, but it looks good to me.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use this function a lot, so I'll thoroughly test it on pretty much every possible player once I get rolling.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. On my todo list for the overall project is to write an actual test suite but I probably won't until I finish my thesis. But until then I'm fine with you just opening new pull requests or whatever if there are bugs after it's merged in.

Comment thread sportsref/nfl/teams.py Outdated
"""
# set link and table_name and then get the pyquery table
link = sportsref.nfl.BASE_URL + \
'/teams/{}/{}_injuries.htm'.format(self.teamID, str(year))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done using self.get_year_doc. See the roster function for reference.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_year_doc returns the html in pyquery form for the team and year combo. For example the link:
"http://www.pro-football-reference.com/teams/rav/2012.htm"
The injury and snap count info are not on that page as far as I can tell. They are on related, but different links:
"http://www.pro-football-reference.com/teams/rav/2012_injuries.htm"
and
"http://www.pro-football-reference.com/teams/rav/2012-snap-counts.htm"
These are entirely different html pages and content on those pages. Am I missing something? Is the data on the base page but hidden and still parsable?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd get those as self.get_year_doc('2012_injuries') and self.get_year_doc('2012-snap-counts'). See the way they're used in the roster function. It just wraps those first two lines in a function, but those functions become tedious when they all do the same thing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't see that. Very nice stuff there. Made the changes.

Comment thread sportsref/nfl/teams.py Outdated
"""
# set link and table_name and then get the pyquery table
link = sportsref.nfl.BASE_URL + \
'/teams/{}/{}-snap-counts.htm'.format(self.teamID, str(year))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self.get_year_doc here too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see comment above.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above. also in the line below this change '#all_snap_counts' to 'table#snap_counts' once you merge in the new master branch

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this.

@matthewstirling
Copy link
Copy Markdown
Author

I made all the table method changes. Please see the comments for the other three items.

@matthewstirling
Copy link
Copy Markdown
Author

I think I've caught up with all your requested changes on this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants