uberfastman / fantasy-football-metrics-weekly-report

Command line application to create weekly reports (containing stats, metrics, and rankings) for Fantasy Football leagues on the following platforms: Yahoo, ESPN, CBS, Sleeper, Fleaflicker
GNU General Public License v3.0
199 stars 49 forks source link

<KeyError: '1'> occurs when generating a Sleeper report #116

Closed michaelrdixey closed 4 years ago

michaelrdixey commented 4 years ago

I am running into an error when trying to generate a Sleeper report. This same error occurs on both the Docker image and my python virtualenv: -appears to be related to an index problem on line 203 in sleeper.py

on Oct 02, 2020... 2020-10-02 21:59:07,885 - report.builder - INFO - Retrieving fantasy football data from Sleeper API... Sleeper does not provide the current NFL week in the API. Are you trying to generate a report for week 3 (current NFL week 4)? (y/n) -> y [2020-10-02 21:59:44,690 INFO] [dao.sleeper.sleeper.query] File 519625693429035008-player_data.json does not exist... attempting data retrieval. 2020-10-02 21:59:44,690 - dao.sleeper - INFO - File 519625693429035008-player_data.json does not exist... attempting data retrieval. [2020-10-02 21:59:46,418 INFO] [dao.sleeper.sleeper.query] File 519625693429035008-player_season_stats.json does not exist... attempting data retrieval. 2020-10-02 21:59:46,418 - dao.sleeper - INFO - File 519625693429035008-player_season_stats.json does not exist... attempting data retrieval. [2020-10-02 21:59:47,477 INFO] [dao.sleeper.sleeper.query] File 519625693429035008-player_season_projected_stats.json does not exist... attempting data retrieval. 2020-10-02 21:59:47,477 - dao.sleeper - INFO - File 519625693429035008-player_season_projected_stats.json does not exist... attempting data retrieval. Traceback (most recent call last): File "main.py", line 241, in report = select_league( File "main.py", line 155, in select_league return FantasyFootballReport(week_for_report=week_for_report, File "/app/report/builder.py", line 106, in init self.league = league_data_factory( File "/app/utils/report_tools.py", line 132, in league_data_factory sleeper_league = SleeperLeagueData( File "/app/dao/sleeper.py", line 203, in init for matchup in self.matchups_by_week[str(week_for_rosters)]: KeyError: '1'

C:\Users\Thor\PycharmProjects\fantasy-football-metrics-weekly-report>

uberfastman commented 4 years ago

@michaelrdixey I've pushed a fix to the issue.

Just to make sure my suspicions are correct... does your Sleeper league have custom playoffs? For some reason the API was returning that your playoff start week was week 0, even though it also said your league has 6 playoff spots, which to me implied that you must be doing some sort of manual playoff seeding or something...?

Anyway, regardless, if you pull the latest from develop it should work for your league now, I was able to generate a week 3 report for your league without issue!

michaelrdixey commented 4 years ago

@uberfastman Thanks for pushing the fix, report is generating properly now. You are correct in that our league does do a manual playoff seeding.

uberfastman commented 4 years ago

@michaelrdixey awesome, glad it's working properly now! For future reference now that I've fixed this, just make sure that for any leagues you have with manual playoffs, you set have the num_regular_season_weeks value set to whichever week is your last week of the regular season in your config.ini.