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

Bug Fixes #111

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file.

## Unreleased

- N/A
- Fixed bug where Sleeper leagues without divisions would fail to load
- Fixed bug where Yahoo leagues could not load league IDs for previous years

## [2.5.3]

Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: deps
deps: deps
@python3 -m pip install -r requirements.dev.txt
@python3 -m pip install -r requirements.txt

.PHONY: fmt
fmt:
@black --config=pyproject.toml .
@autoflake --config=pyproject.toml .
@isort .

.PHONY: test
test:
@python3 -m pytest test/

.PHONY: up-reqs
up-reqs:
@pipreqs --force --mode compat
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,8 @@ Please make sure to update tests as appropriate.
## Development

_Run these commands from the root folder_
- Format Code: `./main fmt`
- Run Unit Tests: `./main test`
- Generate Coverage Report: `./main cov`

### Running Tests

Run the following command from the root folder:

```bash
pytest
```

- Format Code: `make fmt`
- Run Unit Tests: `make test`

## License

Expand Down
7 changes: 0 additions & 7 deletions batch/coverage.bat

This file was deleted.

4 changes: 0 additions & 4 deletions batch/format.bat

This file was deleted.

4 changes: 0 additions & 4 deletions batch/test.bat

This file was deleted.

28 changes: 17 additions & 11 deletions leeger/league_loader/SleeperLeagueLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,27 @@ def __buildLeague(self, sleeperLeagues: list[SleeperLeague]) -> League:
return League(name=self._getLeagueName(), owners=owners, years=self._getValidYears(years))

def __buildYear(self, sleeperLeague: SleeperLeague) -> Year:
# save division info
for divisionNumber in range(1, sleeperLeague.settings.divisions + 1):
self.__sleeperDivisionIdToDivisionMap[divisionNumber] = Division(
name=getattr(sleeperLeague.metadata, f"division_{divisionNumber}")
)
# save division info if applicable
if self.__yearHasDivisions(sleeperLeague):
for divisionNumber in range(1, sleeperLeague.settings.divisions + 1):
self.__sleeperDivisionIdToDivisionMap[divisionNumber] = Division(
name=getattr(sleeperLeague.metadata, f"division_{divisionNumber}")
)
teams = self.__buildTeams(sleeperLeague)
weeks = self.__buildWeeks(sleeperLeague)
# add YearSettings
yearSettings = YearSettings()
if sleeperLeague.settings.league_average_match == 1:
yearSettings.leagueMedianGames = True
# TODO: see if there are cases where Sleeper leagues do NOT have divisions

year = Year(
yearNumber=int(sleeperLeague.season),
teams=teams,
weeks=weeks,
yearSettings=yearSettings,
divisions=list(self.__sleeperDivisionIdToDivisionMap.values()),
divisions=None
if not self.__yearHasDivisions(sleeperLeague)
else list(self.__sleeperDivisionIdToDivisionMap.values()),
)
# clear division info
self.__sleeperDivisionIdToDivisionMap = dict()
Expand Down Expand Up @@ -315,6 +318,9 @@ def __buildWeeks(self, sleeperLeague: SleeperLeague) -> list[Week]:
weeks.append(Week(weekNumber=weekNumber, matchups=matchups))
return weeks

def __yearHasDivisions(self, sleeperLeague: SleeperLeague) -> bool:
return sleeperLeague.settings.divisions is not None

def __isCompletedWeek(self, weekNumber: int, sleeperLeague: SleeperLeague) -> bool:
# see if this is the current year/week of the NFL
sportState = self.__getSleeperSportState()
Expand All @@ -335,10 +341,10 @@ def __buildTeams(self, sleeperLeague: SleeperLeague) -> list[Team]:
for sleeperRoster in sleeperRosters:
if sleeperRoster.owner_id == sleeperUser.user_id:
rosterId = sleeperRoster.roster_id
# TODO: see if there are cases where ESPN leagues do NOT have divisions
divisionId = self.__sleeperDivisionIdToDivisionMap[
sleeperRoster.settings.division
].id
if self.__yearHasDivisions(sleeperLeague):
divisionId = self.__sleeperDivisionIdToDivisionMap[
sleeperRoster.settings.division
].id
if rosterId is None:
raise DoesNotExistException(
f"No Roster ID match found for Sleeper User with ID: '{sleeperUser.user_id}'."
Expand Down
9 changes: 8 additions & 1 deletion leeger/league_loader/YahooLeagueLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __getAllLeagues(self) -> list[YahooLeague]:
# years from most -> least recent
remainingYears = sorted(self._years, reverse=True)
currentLeagueId = self._leagueId
print('jg clid', currentLeagueId)
previousLeagueId = None
for year in remainingYears:
foundLeagueForYear = False
Expand All @@ -100,12 +101,18 @@ def __getAllLeagues(self) -> list[YahooLeague]:
if str(league.league_id) == currentLeagueId:
yahooLeagues.append(league)
foundLeagueForYear = True
previousLeagueId = league.past_league_id
try:
# NOTE: this is weird. apparently the league ID here is returned like this: (414, 957486)
# NOTE: and the league id is always at index 1
previousLeagueId = str(league.past_league_id[1])
except Exception as e:
self._LOGGER.warning(f"could not get previous league id: {e}")
if not foundLeagueForYear:
raise LeagueLoaderException(
f"Could not find league for year {year} with ID {currentLeagueId}."
)
currentLeagueId = previousLeagueId
print('jg clid', currentLeagueId)

self._validateRetrievedLeagues(yahooLeagues)
return yahooLeagues
Expand Down
11 changes: 0 additions & 11 deletions main.bat

This file was deleted.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ skip-magic-trailing-comma = true
include = '\.py$'
quiet = true

[tool.isort]
profile = "black"
line_length = 100

[autoflake]
ignore_init_module_imports = true
in_place = true
Expand Down
5 changes: 5 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black==23.3.0
autoflake==2.1.1
isort==5.12.0
pipreqs==0.4.13
pytest~=7.4.3
15 changes: 7 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
numpy~=1.24.1
openpyxl~=3.1.1
espn-api~=0.30.0
yahoofantasy~=1.4.0
sleeper~=1.6.0
pymfl~=1.0.2
espn_api~=0.33.0
fleaflicker~=1.0.0
typing-extensions~=4.5.0
configparser~=5.3.0
numpy~=1.26.2
openpyxl~=3.1.2
pymfl~=1.0.2
setuptools~=69.0.2
sleeper~=1.7.3
yahoofantasy~=1.4.2
13 changes: 10 additions & 3 deletions test/test_league_loader/test_YahooLeagueLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@

class TestYahooLeagueLoader(unittest.TestCase):
# helper methods

def __foo(self) -> callable:
def mockTeamsMethod():
return ["", "123"]

return mockTeamsMethod

def __getMockTeamsMethod(self, teams: list) -> callable:
def mockTeamsMethod():
return teams
Expand Down Expand Up @@ -117,7 +124,7 @@ def test_loadLeague_happyPath(
mockLeague2023.season = 2023
mockLeague2023.current_week = 3
mockLeague2023.end_week = 3
mockLeague2023.past_league_id = "123"
mockLeague2023.past_league_id = ["", "123"]

# mock fake leagues 2023
mockLeague2023_fake1 = Mock()
Expand Down Expand Up @@ -665,7 +672,7 @@ def test_loadLeague_withOwnerNamesAndAliases(
mockLeague2023.season = 2023
mockLeague2023.current_week = 3
mockLeague2023.end_week = 3
mockLeague2023.past_league_id = "123"
mockLeague2023.past_league_id = ["", "123"]

# mock fake leagues 2023
mockLeague2023_fake1 = Mock()
Expand Down Expand Up @@ -1226,7 +1233,7 @@ def test_loadLeague_happyPath(
mockLeague2023.season = 2023
mockLeague2023.current_week = 3
mockLeague2023.end_week = 3
mockLeague2023.past_league_id = "123"
mockLeague2023.past_league_id = ["", "123"]

# mock fake leagues 2023
mockLeague2023_fake1 = Mock()
Expand Down