BurntSushi / nflgame

An API to retrieve and read NFL Game Center JSON data. It can work with real-time data, which can be used for fantasy football.
http://pdoc.burntsushi.net/nflgame
The Unlicense
1.27k stars 414 forks source link

Complete List of Active Players #33

Closed cminton closed 11 years ago

cminton commented 11 years ago

I would like to dump out a complete list of active players. I'm starting to look at statistics for players and thinking about the players with similar gsis_names. For example, Calvin and Chris Johnson. Is Calvin 'Ca' or is Chris 'Ch'? I want this because I'm going to enter the players on teams in my league and look at their stats and the stats. I figured I would dump out the players with:

All players

players=nflgame.player._create_players()

Active players

act=[k for k in players.keys() if players[k].status=='ACT']

Active offense players

pos=['QB','RB','WR','TE','K'] offense=[k for k in act if players[k].position in pos]

Not all these players have the attribute 'gsis_id' but, I can use the key for them. However, not all of them have a gsis_name. Why is that?

Is there an easy way to get a list of player names, teams, gsis_names and gsis_ids?

BurntSushi commented 11 years ago

Most of the problems you're seeing are due to bugs you've just helped me flush out and fix. I've pushed a new release 1.1.15 with updates to the player database and the update script. You should update to get the fixes. Basically, the problem was that the values in status were stale. If a player was once active but was dropped from a team, their status in the database remained active. That should no longer be true.

Now, to answer your questions.

I would like to dump out a complete list of active players.

I believe your general approach should now be correct. Filtering by the status ACT should provide the correct results. You should also be able to filter by team to give you rostered players, but that can include injured players or players inactive for other reasons.

For example, Calvin and Chris Johnson. Is Calvin 'Ca' or is Chris 'Ch'?

Unfortunately, neither. They are both C.Johnson. If you want to find specific players, I suggest you use nflgame.find to look up a player by their full name.

Note that not every active player will have gsis_name set to a valid value! This is because not every active player has recorded a statistic, and therefore, nflgame cannot know his gsis_name.

This code now executes successfully. Note that I'm using full_name instead of gsis_name:

import nflgame

opos = ['QB', 'RB', 'WR', 'TE', 'K']
act = [k for k in nflgame.players.keys() if nflgame.players[k].status == 'ACT']
offense = [k for k in act if nflgame.players[k].position in opos]

for gsis_id in offense:
    p = nflgame.players[gsis_id]
    assert len(p.full_name) > 0 and len(p.player_id) > 0, str(p)

Also note that I'm not calling _create_players. The nflgame.players variable is automatically populated for you. No need to repeat the work!

Finally, each player object has some methods that you might find useful. Although, they can be slow so I don't recommend using them in a loop with a lot of iterations.

cminton commented 11 years ago

Thanks Andrew. I've updated and copied to my phone. I'm making changes to my scripts to use the gsis_id instead of the name. I would like to write a wiki to explain the steps to running on an Android device, but I've never done that. Are you suggesting one on github? Is there an easy doc to explain how to set it up? As I mentioned, my background is Comp Sci, but that's from 30 years ago, so while I can code very well, I'm not familiar with setting up wikis. (I switched from tech to finance 20 years ago.)

regards, Charlie

On Sep 2, 2013, at 1:51 PM, Andrew Gallant wrote:

Most of the problems you're seeing are due to bugs you've just helped me flush out and fix. I've pushed a new release 1.1.15 with updates to the player database and the update script. You should update to get the fixes. Basically, the problem was that the values in status were stale. If a player was once active but was dropped from a team, their status in the database remained active. That should no longer be true.

Now, to answer your questions.

I would like to dump out a complete list of active players.

I believe your general approach should now be correct. Filtering by the status ACT should provide the correct results. You should also be able to filter by team to give you rostered players, but that can include injured players or players inactive for other reasons.

For example, Calvin and Chris Johnson. Is Calvin 'Ca' or is Chris 'Ch'?

Unfortunately, neither. They are both C.Johnson. If you want to find specific players, I suggest you use nflgame.find to look up a player by their full name.

Note that not every active player will have gsis_name set to a valid value! This is because not every active player has recorded a statistic, and therefore, nflgame cannot know his gsis_name.

This code now executes successfully. Note that I'm using full_name instead of gsis_name:

import nflgame

opos = ['QB', 'RB', 'WR', 'TE', 'K'] act = [k for k in nflgame.players.keys() if nflgame.players[k].status == 'ACT'] offense = [k for k in act if nflgame.players[k].position in opos]

for gsis_id in offense: p = nflgame.players[gsis_id] assert len(p.full_name) > 0 and len(p.player_id) > 0, str(p) Also note that I'm not calling _create_players. The nflgame.players variable is automatically populated for you. No need to repeat the work!

Finally, each player object has some methods that you might find useful. Although, they can be slow so I don't recommend using them in a loop with a lot of iterations.

— Reply to this email directly or view it on GitHub.

BurntSushi commented 11 years ago

@cminton You can just click the New Page button on nflgame's wiki. Type in whatever name you want, and it should bring you to an edit box where you can type away. I think there are formatting buttons, so you won't need to know Markdown.

Thanks!

teamfball commented 11 years ago

Wow, a lot has happened over the holiday, thanks to cminton and BurntSushi My roster list looks very nice but does anyone else notice the number of duplicate names, seams like more than ever. These are just the ones on my existing injury list.

Jonathan Stewart
Brandon Marshall
Andre Smith
Chris Givens
A.J. Davis
Brandon Williams
Steve Williams
Chris Clemons
Zach Miller
Michael Smith

Currently I’m getting the injuries here , http://www.pro-football-reference.com/years/2013/injuries.htm . The name formats are a very good match. But because of the lack of a gsisid simple name matching will be troublesome again this year. Ultimately, I believe my answer is here; http://www.nfl.com/injuries?week=1 which just became active this morning but has yet to be populated. I’m confident in being able to scrape this page with excel. However, if the gsisid is present it certainly won’t be listed in the table format, but rather obscured in the source code. Does anyone know how to scrape that type of page of all its contents?

BurntSushi commented 11 years ago

@teamfball Could you please show the code you used to generate that list of duplicates? I do in fact see, for example, two players named Jonathan Stewart, but they are two different players. One is an RB and the other is an inside LB.

So when you print a list of names, you should also print their team and position.

Finally, please open a new issue about the injury stuff. Keep my issue tracker clean, dammit!