Closed Sharwin24 closed 1 year ago
The player.slot_position
s are stored with the box_score of that week, not just current lineup. You can get the different box scores by providing the week in the parameters. As an example league.box_scores(week=12)
I validated this for football at least.
Ah ok that makes sense and I was able to implement what I wanted:
# Given a team and a week, collect the starters and the bench players for each team
def getStartersAndBench(team_owner: str, week: int) -> (list, list):
starters = []
bench = []
# Select the roster depending on the week
myLeague.load_roster_week(week)
boxScores = myLeague.box_scores(week)
for boxScore in boxScores:
if boxScore.home_team.owner == team_owner:
lineup = boxScore.home_lineup
break
elif boxScore.away_team.owner == team_owner:
lineup = boxScore.away_lineup
break
# Get the starters and bench
for player in lineup:
if player.slot_position == 'BE' or player.slot_position == 'IR':
bench.append(player)
else:
starters.append(player)
return (starters, bench)
Wondering if you have any feedback for this method to make it cleaner or more efficient
Sport
Football
Summary
Currently, it seems like the only way to view a player's position is through the
BoxPlayer
class which contains aslotPosition
field which I think is updated live as the player's position changes throughout the game. I'm not sure how to obtain aBoxPlayer
object for a given league, a given week, and a given team (byteam_id
).My intention is to generate the list of starters and bench players for each week for each team.