Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get roster of previous week? #35

Closed
DesiPilla opened this issue Sep 10, 2019 · 13 comments
Closed

Get roster of previous week? #35

DesiPilla opened this issue Sep 10, 2019 · 13 comments

Comments

@DesiPilla
Copy link
Contributor

A team's roster is listed under ['rosterForMatchupPeriod']['entries'] or ['rosterForCurrentScoringPeriod']['entries'], but after a week has concluded, neither ['rosterForMatchupPeriod'] or ['rosterForCurrentScoringPeriod'] exist anymore, only ['pointsByScoringPeriod']. Where can I find the roster for a previous week?

@cwendt94
Copy link
Owner

Check out the league function load_roster_week(week=1). That should set the Teams roster to that week. I haven’t tried it for this season yet because week 1 just ended but I believe that is what you are looking for.

@joshbis
Copy link

joshbis commented Sep 12, 2019

Is there a way to tell which players were Bench vs. Rostered in this function?

@DesiPilla
Copy link
Contributor Author

DesiPilla commented Sep 12, 2019

In the load_roster_week function, line 214 pulls the data. If you go to
data['teams'][teamIndex]['roster']['entries'][playerIndex]['lineupSlotId'] it will return the slotId of the player for the given week. The map of slotIds are
{'QB': 0,'TQB': 1,'RB': 2,'RB/WR': 3,'WR': 4,
'WR/TE': 5,'TE': 6,'OP': 7,'DT': 8,'DE': 9,
'LB': 10,'DL': 11,'CB': 12,'S': 13,'DB': 14,
'DP': 15,'D/ST': 16,'K': 17,'P': 18,'HC': 19,
'BE': 20,'IR': 21,'': 22,'RB/WR/TE': 23, ' ': 24
}
A slotId of 20 is a bench player. Note that not every league uses every slotId, but this is the full map of possible Ids.

@cwendt94
Copy link
Owner

@joshbis at the moment no. Honestly I should probably put slot_position in the Player class. However, right now you can use box_scores(week=1) to get week 1 roster benched and rostered players for a team.

@joshbis
Copy link

joshbis commented Sep 12, 2019

Sorry, I'm dumb and maybe this isn't the place to ask, but is this an attribute of the player? I think I was hoping it would be pullable via the weekly box scores since that already has the points.

i.e., league.teams[0].roster[0] gets me to the first player on the first team's roster.

(beyond the scope of this is that the functions are great and I'd love more syntax examples for idiots)

@cwendt94
Copy link
Owner

No worries. Yeah you can get this information from the box scores function.

Here is a quick example below:

>>> box_scores = league.box_scores(week=1)
>>> box_scores[0].home_team
Team(Team 1)
>>> box_scores[0].away_team
Team(Team Viking Queen)
>>> box_scores[0].home_score
69.24
>>> box_scores[0].away_score
87.62
>>> box_scores[0].home_lineup
[Player(Kareem Hunt, points:0, projected:0), Player(Travis Kelce, points:0, projected:0), Player(Zach Ertz, points:15, projected:9), Player(Josh Gordon, points:7, projected:8), Player(Kenyan Drake, points:21, projected:8), Player(Devin Funchess, points:0, projected:0), Player(Tarik Cohen, points:11, projected:8), Player(Wil Lutz, points:10, projected:7), Player(Dion Lewis, points:4, projected:9), Player(Matthew Stafford, points:5, projected:15), Player(Ezekiel Elliott, points:20, projected:17), Player(Brandin Cooks, points:0, projected:0), Player(Kerryon Johnson, points:0, projected:0), Player(Mitchell Trubisky, points:0, projected:0), Player(Bengals D/ST, points:6, projected:-3), Player(Courtland Sutton, points:7, projected:1)]
>>> box_scores[0].home_lineup[2].points
15.1
>>> box_scores[0].home_lineup[2].projected_points
9.97
>>> box_scores[0].home_lineup[2].slot_position
'TE'
>>> box_scores[0].home_lineup[2].position
'TE'
>>> box_scores[0].home_lineup[2].name
'Zach Ertz'

I definitely need to update my documentation and add all of the fields and functions of the API to make it easier to use!

Does this answer your question?

@joshbis
Copy link

joshbis commented Sep 12, 2019

Nice! That's super helpful. So that -- and other individual attributes -- is pulled player by player within the week's box score? I had started playing around with this to get the full week's lineup by iterating over the home and away teams:

home = pd.concat([pd.DataFrame({ 'player_info' : box_scores[i].home_lineup, 'team' : box_scores[i].home_team}) for i in range(0,6)], ignore_index=True)

With a little tinkering I could do the same with those slot positions.

@cwendt94
Copy link
Owner

Exactly, so in each box_score object has each home and away team lineup which is a list of box_player objects that have that information. Does this help with your question on #38? For that question this would be the best option at the moment.

@joshbis
Copy link

joshbis commented Sep 12, 2019

yes -- I can delete #38 -- it helps to understand the tool as pulling information players within rosters within leagues and not the universe of all players at ESPN.

I.e., you can find free agents but not their scores for a given week if they weren't on a roster?

@cwendt94
Copy link
Owner

Correct right now you cannot. However, I am looking at the free agents endpoint and I believe I should be able to get projected and actual points of free agents. Would that be helpful field to have for free agents?

@joshbis
Copy link

joshbis commented Sep 12, 2019

I guess in the abstract I could imagine how it would be useful to someone using the API to analyze trades or scour the wires.

In writing this out, though, it's beyond what I was doing -- pulling actual scores and graphing how they corresponded to auction values (I already have them, but it raises a question of whether these are stored anywhere).

@cwendt94
Copy link
Owner

Yeah definitely and a lot of added features and data were ideas from other people that I didn't even think of. You can do a lot of cool stuff with the data!

@joshbis
Copy link

joshbis commented Sep 12, 2019

thanks -- here's my week one masterpiece. looking forward to playing around with it more over the course of the season.

https://www.dropbox.com/s/u0zg32qze4zue1c/w1_payoffs.png?dl=0

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

No branches or pull requests

3 participants