Closed russellkt closed 1 month ago
If we assign this dictionary to a variable called data
, you'll see that there are two keys.
>>> data.keys()
[0, 1]
In data[1]
are all the week specific stats & projections for a player. For example, to get the projected point total for just the single week:
>>> data[1]['projected_points']
16.54
Thanks @DesiPilla . I am pulling the data[2]['projected_points'] but the value is 266.48 for Garrett Wilson with similar values for all of the players both on roster and free agents. The code worked fine all last season and also appears reasonable for Week 1 or data[1].
2: {'projected_points': 266.48,
First Five Free Agents:
[Player(Ka'imi Fairbairn, points:0, projected:131.89), Player(Devin Singletary, points:0, projected:193.02), Player(Cameron Dicker, points:0, projected:129.94), Player(Chiefs D/ST, points:0, projected:96.36), Player(Zach Charbonnet, points:0, projected:121.6)]
Can you share the code you used to pull the data?
Sure, I have this in a jupyter notebook so here is the relevant code:
wk=2
fhope = League(league_id=***, year=2024, swid='{***}', espn_s2=espn_auth)
free_agents = fhope.free_agents(size=250)
fas_df = pd.DataFrame([o.__dict__ for o in free_agents])
rustlers = fhope.teams[8]
roster = rustlers.roster
rustlers_df = pd.DataFrame([o.__dict__ for o in rustlers.roster])
rustlers_df["projected_points"] = rustlers_df.apply(
lambda row: row["stats"][wk]["projected_points"],
axis=1)
rustlers_fa = pd.concat([fas_df, rustlers_df], ignore_index=True)
rustlers_fa[['name','projected_points']]
Output:
Interesting. After looking into it, I think it might be a glitch on ESPN's part. The projected_avg_points
for Bijan is 19.7 pts
, which is what the ESPN website/app says is his Week 2 projection. I think their API is probably glitching out and will hopefully get fixed soon.
>>> player["stats"][2]["projected_points"]
313.3
>>> player["stats"][2]["projected_avg_points"]
19.7
Thank you, the projected_avg_points does not match up exactly with the projected points I am seeing on the website but will continue to monitor and report back.
@DesiPilla Thanks for digging this out! Was exactly the fix I was looking for, hadn't noticed the avg field seemed correct.
Also experiencing this issue!
I realized later it isn’t always right - Josh Jacob’s projected avg doesn’t match the roster on the site. Haven’t gotten to debug it to trace further tho..
Thanks, -Bill
From: Josh Spratt @.> Sent: Wednesday, September 11, 2024 5:56:54 PM To: cwendt94/espn-api @.> Cc: Comment @.***> Subject: Re: [cwendt94/espn-api] Week 2 Projected Points Appear to be a Total (Issue #571)
Also experiencing this issue!
— Reply to this email directly, view it on GitHubhttps://github.com/cwendt94/espn-api/issues/571#issuecomment-2345046830 or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABCQI4BVUMZBKLJPO3PVPETZWDRFNBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVEYTSOBWGY4TIOBVQKSHI6LQMWSWS43TOVS2K5TBNR2WLKRSGUYTOMJUHE2DGMFHORZGSZ3HMVZKMY3SMVQXIZI. You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I am seeing the same issue.
Taking a quick look on the website it appears the correct value is stats[{"appliedTotal":xxx, ..."scoringPeriodId":2}] I'm not as optimistic that espn will be fixing as their site appears to be working fine. Hopefully I'll have more time to dive in and debug soon.
Right, what I ended up doing to cover for this in the meantime is to parse the response of:
https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2024/segments/0/leagues/{league_id}?rosterForTeamId=1&view=mDraftDetail&view=mLiveScoring&view=mMatchupScore&view=mPendingTransactions&view=mPositionalRatings&view=mRoster&view=mSettings&view=mTeam&view=modular&view=mNav
which is the API called on the ESPN matchup page. That "appliedTotal" field you mentioned has the projected points for the week. Thanks for taking a look.
It appears there are actually two values in the json for scoringPeriodId: 2, one appliedTotal appears to be ROS, and one for the week. Looking closer it looks like the correct one for the week is delineated by "statSplitTypeId": 1 and the ROS by "statSplitTypeId": 2
I wish my python skills were better but I did fork the code and it appears there is no delineation for statSplitTypeId in the Player class when parsing the stats. My thinking is espn changed the api to be able to track the rest of the season stats from original as the season progresses. In line 42 it does delineate between stat source which I believe is the delineation between actual and projected.
Was able to fork and get a codespace up and running. When debugging, it appears the stats for scoring period 2 are getting set correctly but then overriden by the second stats for scoring period 2 of statSplitTypeId: 2 which appears to have the rest of the season projections.
I was able to correct the behavior by changing line 34 of the Player class file from
if stats.get('seasonId') != year:
to
if stats.get('seasonId') != year or stats.get('statSplitTypeId') == 2:
However, I have not issued a pull request since my skills are weak and there might be a better way to accomplish.
Thanks for this update and investigation! I believe I saw something similar in baseball and had to do the same https://github.com/cwendt94/espn-api/commit/80bcefc2bd96178b93d6503ecf2223b863d93d57.
I will create a fix!
should be fixed in v0.38.1
Running through my notebooks for the waiver wire I am getting what appears to be Total Projected Points rather than Week 2 Projections. It is occurring for both Free Agents Projected points and for the Stats of a Rostered Player. Example for Garrett Wilson(on Roster) showing Week 2 Projections of 266.48: