Closed DesiPilla closed 1 year ago
Wow thanks for doing all of this research and finding a way to figure out if the player played the game or not! I will look into this and try to add this logic for "injury" and active field for the box_player class!
Sport
Football
Summary
Okay so for a while now, an issue we've had is that ESPN only return's a player's current health status, even when querying a previous week or year. I think I have a way to get around this and assume a player's health status from previous weeks.
Example REST call: https://fantasy.espn.com/apis/v3/games/ffl/seasons/2022/segments/0/leagues/1086064?view=mMatchupScore&view=mScoreboard&scoringPeriodId=6 (I know this isn't that far back, but it still works).
LAC WR Keenan Allen was OUT due to injury. His player json looks like:
As we see,
"injured": false
and"injuryStatus": "QUESTIONABLE"
are not reflective of his actualout
status in Week 6. However,resp["player"]["stats"][1]["stats"] = {}
is an empty dictionary. I believe that this indicates that the player wasOUT
that week. Note: We must look at thestat
dictionary with"statSourceId": 1
. I think this refers to single-season stats, vs season-long stats.For example, here's the json for NYJ WR Elijah Moore from that week.
Moore played, but did not record a single stat. Yet, despite not registering any stats, his json shows
resp["player"]["stats"][0]["stats"] = "stats": { "155": 1.0, "210": 1.0 }
. For reference,statId
155 refers to "Team win" and 210 refers to "Games played". Because Moore was active for the game, these two stats appear in his json.So, this would indicate that if a player's
resp["player"]["stats"][0]["stats"]
is an empty dictionary, then we can safely assume that the player wasOUT
that week. However, there are two other things to consider:Here's the json for TEN RB Derrick Henry
The Titans were on a bye during Week 6, so Henry did not play. His json also has
"injuryStatus": "ACTIVE"
. However, recall thatresp["player"]["stats"]
is a list with 2 elements in it:"statSourceId": 0
is astats
dictionary containing single-week stats for the current week, and"statSourceId": 1
is astats
dictionary containing season-long stats. In Henry's json,len(resp["player"]["stats"]) = 1
. He only has onestats
dictionary, the one with"statSourceId": 1
. This is because he did not play this week, and was not supposed to play. This is also the case for other players on bye, which to me makes it a reliable indicator that the player was on a bye and not injured.Here's the json for ARI WR DeAndre Hopkins from Week 6
First, let's note that Hopkins' json shows
"injured": false
and"injuryStatus": "ACTIVE"
when it should show"injured":false
and"injuryStatus":"SUSPENSION"
. This is because, today in Week 10, he is no longer suspended. In Week 6, though, Hopkins was still serving his 6-game suspension. BUT, we can see thatresp["player"]["stats"][0]["stats"] = {}
, which we previously decided safely meant that a player wasOUT
. This is the edge case. If the player is still suspended today, it becomes an easy fix (just check for"injuryStatus":"SUSPENSION"
). But in a case like this, I don't know how to pull this data simply from the API.Perhaps, a player being suspended is comparable to being
OUT
. It's not due to injury, but it's distinct from a bye. Players on suspension function more like those that are injured, since teams will stash them waiting until they come back from suspension. And when they do, you don't know how long it will take before they make meaningful contributions to the team (like injured players). Players returning from a bye don't really exhibit this behavior.In conclusion
When looking at a player's json, if
resp["player"]["stats"][0]["stats"] = {}
(make sure it's the one with"statSourceId": 1
, ANDlen(resp["player"]["stats"]) == 2
, the player WASOUT
(or suspended).Does this sound right?