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

Sleeper League Loader (Key Error) #116

Open
gwamstutz64 opened this issue Jan 4, 2024 · 2 comments
Open

Sleeper League Loader (Key Error) #116

gwamstutz64 opened this issue Jan 4, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@gwamstutz64
Copy link

League Loader

Sleeper

Summary

When I try the basic "quick start" for loading in a sleeper league, I get a KeyError: 7. Will post the full log below. Wondering if it has to do with a team that the owner was removed and is now just an NPC team. Also, sorry if this is mentioned somewhere in the README or anything, I wasn't able to find it.

League Info

League ID: 1000931507806011392
Season: 2023

Error Logs

KeyError Traceback (most recent call last)
Cell In[8], line 2
1 sleeperLeagueLoader = SleeperLeagueLoader("1000931507806011392", [2023])
----> 2 League = sleeperLeagueLoader.loadLeague()

File ~\anaconda3\envs\py36\Lib\site-packages\leeger\league_loader\SleeperLeagueLoader.py:121, in SleeperLeagueLoader.loadLeague(self, validate)
119 def loadLeague(self, validate: bool = True) -> League:
120 sleeperLeagues = self.__getAllLeagues()
--> 121 league = self.__buildLeague(sleeperLeagues)
122 if validate:
123 # validate new league
124 leagueValidation.runAllChecks(league)

File ~\anaconda3\envs\py36\Lib\site-packages\leeger\league_loader\SleeperLeagueLoader.py:136, in SleeperLeagueLoader.__buildLeague(self, sleeperLeagues)
133 for sleeperLeague in sleeperLeagues:
134 # save league name for each year
135 self._leagueNameByYear[int(sleeperLeague.season)] = sleeperLeague.name
--> 136 years.append(self.__buildYear(sleeperLeague))
137 return League(name=self._getLeagueName(), owners=owners, years=self._getValidYears(years))

File ~\anaconda3\envs\py36\Lib\site-packages\leeger\league_loader\SleeperLeagueLoader.py:147, in SleeperLeagueLoader.__buildYear(self, sleeperLeague)
143 self._sleeperDivisionIdToDivisionMap[divisionNumber] = Division(
144 name=getattr(sleeperLeague.metadata, f"division
{divisionNumber}")
145 )
146 teams = self.__buildTeams(sleeperLeague)
--> 147 weeks = self.__buildWeeks(sleeperLeague)
148 # add YearSettings
149 yearSettings = YearSettings()

File ~\anaconda3\envs\py36\Lib\site-packages\leeger\league_loader\SleeperLeagueLoader.py:192, in SleeperLeagueLoader.__buildWeeks(self, sleeperLeague)
189 for sleeperMatchupPair in sleeperMatchupIdToSleeperMatchupMap.values():
190 # team A
191 teamASleeperMatchup = sleeperMatchupPair[0]
--> 192 teamA = self.__sleeperRosterIdToTeamMap[teamASleeperMatchup.roster_id]
194 # team B
195 teamBSleeperMatchup = sleeperMatchupPair[1]

KeyError: 7

@gwamstutz64 gwamstutz64 added the bug Something isn't working label Jan 4, 2024
@joeyagreco
Copy link
Owner

@ryan-gillies
Copy link

ryan-gillies commented Apr 26, 2024

I'm also getting a key error when trying to compile an all-time statsheet from Sleeper. I don't have any users that changed usernames, but do have several owners leaving and new owners from one year to the next.

Error Logs

Traceback (most recent call last):
File "/Users/ryan.gillies/Documents/side_judge/backend/models/league.py", line 91, in _load_leeger
leagueStats: AllTimeStatSheet = leagueStatSheet(leeger, validate = True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ryan.gillies/Documents/side_judge/.venv/lib/python3.11/site-packages/leeger/util/stat_sheet.py", line 81, in leagueStatSheet
maxScoringShare = ScoringShareAllTimeCalculator.getMaxScoringShare(league, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ryan.gillies/Documents/side_judge/.venv/lib/python3.11/site-packages/leeger/decorator/validators.py", line 38, in wrapFunction
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ryan.gillies/Documents/side_judge/.venv/lib/python3.11/site-packages/leeger/calculator/all_time_calculator/ScoringShareAllTimeCalculator.py", line 143, in getMaxScoringShare
maxScoringSharesByYear[yearNumber][ownerId]
KeyError: '506256e003f911efba5b5af986bf8fed'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^

Code

def _load_leeger(self):
        from leeger.league_loader import SleeperLeagueLoader
        from leeger.model.league import League, Year
        from leeger.model.stat.YearStatSheet import YearStatSheet
        from leeger.util.stat_sheet import yearStatSheet, leagueStatSheet
        from leeger.model.stat.AllTimeStatSheet import AllTimeStatSheet
        league_loader = SleeperLeagueLoader(self.league_id, self.years)
        leeger: League = league_loader.loadLeague()
        from leeger.model.stat.AllTimeStatSheet import AllTimeStatSheet
        from leeger.util.stat_sheet import leagueStatSheet
        try:
            leagueStats: AllTimeStatSheet = leagueStatSheet(leeger, validate = True)
        except KeyError:
            import traceback
            traceback.print_exc()
        return leeger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants