Skip to content

Commit

Permalink
formatting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Aug 12, 2024
1 parent cb544a7 commit e731197
Show file tree
Hide file tree
Showing 116 changed files with 11,701 additions and 3,809 deletions.
27 changes: 10 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
.PHONY: deps
deps:
@python3.10 -m pip install -r requirements.dev.txt
@python3.10 -m pip install -r requirements.txt
@python -m pip install -r requirements.dev.txt
@python -m pip install -r requirements.txt

.PHONY: fmt
fmt:
@black --config=pyproject.toml .
@autoflake --config=pyproject.toml .
@isort .
@ruff check --fix
@ruff format

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

@ruff check
@ruff format --check

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

.PHONY: reqs
reqs:
@pipreqs --force --mode compat
@python -m pytest test/

.PHONY: pkg-build
pkg-build:
@rm -rf build
@rm -rf dist
@python3.10 setup.py sdist bdist_wheel
@python setup.py sdist bdist_wheel

.PHONY: pkg-test
pkg-test:
@python3.10 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
@python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

.PHONY: pkg-prod
pkg-prod:
@python3.10 -m twine upload dist/*
@python -m twine upload dist/*
24 changes: 20 additions & 4 deletions e2e/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@
teamDominic2019 = Team(ownerId=ownerDominic.id, name="Bike Ridas")

matchup1 = Matchup(
teamAId=teamFrankie2019.id, teamBId=teamDominic2019.id, teamAScore=101.2, teamBScore=122
teamAId=teamFrankie2019.id,
teamBId=teamDominic2019.id,
teamAScore=101.2,
teamBScore=122,
)
matchup2 = Matchup(
teamAId=teamMonika2019.id, teamBId=teamGiovanna2019.id, teamAScore=78.4, teamBScore=114.3
teamAId=teamMonika2019.id,
teamBId=teamGiovanna2019.id,
teamAScore=78.4,
teamBScore=114.3,
)
matchup3 = Matchup(
teamAId=teamJoseph2019.id, teamBId=teamVincent2019.id, teamAScore=112, teamBScore=145.3
teamAId=teamJoseph2019.id,
teamBId=teamVincent2019.id,
teamAScore=112,
teamBScore=145.3,
)

matchup4 = Matchup(
Expand Down Expand Up @@ -107,6 +116,13 @@

LEAGUE = League(
name="G League",
owners=[ownerFrankie, ownerMonika, ownerJoseph, ownerVincent, ownerGiovanna, ownerDominic],
owners=[
ownerFrankie,
ownerMonika,
ownerJoseph,
ownerVincent,
ownerGiovanna,
ownerDominic,
],
years=[year2019],
)
4 changes: 3 additions & 1 deletion example/league/comparingLeagueObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

# 2. lets compare it
league.equals(league) # compares models with all fields
league.equals(league, ignoreBaseIds=True) # ignores the base "id" field in each object
league.equals(
league, ignoreBaseIds=True
) # ignores the base "id" field in each object
league.equals(
league, ignoreIds=True
) # ignores fields that hold an id but not the base "id" fields
Expand Down
24 changes: 20 additions & 4 deletions example/league/manualLeagueBuildingExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@
# Create matchups for week 1.
# Use the team IDs when creating a matchup.
matchup1 = Matchup(
teamAId=teamFrankie2019.id, teamBId=teamDominic2019.id, teamAScore=101.2, teamBScore=122
teamAId=teamFrankie2019.id,
teamBId=teamDominic2019.id,
teamAScore=101.2,
teamBScore=122,
)
matchup2 = Matchup(
teamAId=teamMonika2019.id, teamBId=teamGiovanna2019.id, teamAScore=78.4, teamBScore=114.3
teamAId=teamMonika2019.id,
teamBId=teamGiovanna2019.id,
teamAScore=78.4,
teamBScore=114.3,
)
matchup3 = Matchup(
teamAId=teamJoseph2019.id, teamBId=teamVincent2019.id, teamAScore=112, teamBScore=145.3
teamAId=teamJoseph2019.id,
teamBId=teamVincent2019.id,
teamAScore=112,
teamBScore=145.3,
)

# Create matchups for week 2.
Expand Down Expand Up @@ -126,6 +135,13 @@
# Create the league.
league = League(
name="G League",
owners=[ownerFrankie, ownerMonika, ownerJoseph, ownerVincent, ownerGiovanna, ownerDominic],
owners=[
ownerFrankie,
ownerMonika,
ownerJoseph,
ownerVincent,
ownerGiovanna,
ownerDominic,
],
years=[year2019],
)
4 changes: 3 additions & 1 deletion example/league/yearSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
year = Year(yearNumber=2020, teams=list(), weeks=list(), yearSettings=yearSettings)

# The YearSettings object can be used for multiple years if desired
anotherYear = Year(yearNumber=2021, teams=list(), weeks=list(), yearSettings=yearSettings)
anotherYear = Year(
yearNumber=2021, teams=list(), weeks=list(), yearSettings=yearSettings
)
4 changes: 3 additions & 1 deletion example/league_loader/espnLeagueLoaderExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
# Get a League object with years 2019 and 2020 for ESPN league with ID: "12345678".
espnS2 = "ABCDEFG1234567"
swid = "{ABC-DEF-GHI-JKL-MNOP}"
espnLeagueLoader = ESPNLeagueLoader("12345678", [2019, 2020], espnS2=espnS2, swid=swid)
espnLeagueLoader = ESPNLeagueLoader(
"12345678", [2019, 2020], espnS2=espnS2, swid=swid
)
league: League = espnLeagueLoader.loadLeague()
4 changes: 3 additions & 1 deletion example/league_loader/myFantasyLeagueLeagueLoaderExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

MFL_USERNAME = "myUsername" # The username for your MFL account.
MFL_PASSWORD = "myPassword" # The password for your MFL account.
MFL_USER_AGENT_NAME = "myUserAgentName" # The Client User Agent you set for your API Client.
MFL_USER_AGENT_NAME = (
"myUserAgentName" # The Client User Agent you set for your API Client.
)
LEAGUE_ID = "123456"

myFantasyLeagueLoader = MyFantasyLeagueLeagueLoader(
Expand Down
6 changes: 5 additions & 1 deletion example/league_loader/yahooLeagueLoaderExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
clientId = "myClientId"
clientSecret = "myClientSecret"
yahooLeagueLoader = YahooLeagueLoader(
"123456", [2019, 2020], clientId=clientId, clientSecret=clientSecret, loginTimeoutSeconds=4
"123456",
[2019, 2020],
clientId=clientId,
clientSecret=clientSecret,
loginTimeoutSeconds=4,
)
league: League = yahooLeagueLoader.loadLeague()
18 changes: 13 additions & 5 deletions example/stat/gettingStatsAllTimeExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@
wins = GameOutcomeAllTimeCalculator.getWins(league)

# Get opponent points scored per game.
opponentPointsScoredPerGame = PointsScoredAllTimeCalculator.getOpponentPointsScoredPerGame(
league
opponentPointsScoredPerGame = (
PointsScoredAllTimeCalculator.getOpponentPointsScoredPerGame(league)
)

# To limit results to only regular season, specify that as a keyword argument.
maxScore = SingleScoreAllTimeCalculator.getMaxScore(league, onlyRegularSeason=True)

# To limit results to only post-season (playoffs), specify that as a keyword argument.
scoringShare = ScoringShareAllTimeCalculator.getScoringShare(league, onlyPostSeason=True)
scoringShare = ScoringShareAllTimeCalculator.getScoringShare(
league, onlyPostSeason=True
)

# To limit results to only championship games, specify that as a keyword argument.
winPercentage = GameOutcomeAllTimeCalculator.getWinPercentage(league, onlyChampionship=True)
winPercentage = GameOutcomeAllTimeCalculator.getWinPercentage(
league, onlyChampionship=True
)

# To limit results to only certain years, specify that as a keyword argument.
# This league has years 2019, 2020, 2021, 2022.
Expand Down Expand Up @@ -89,5 +93,9 @@
)
# Will get week 5, 2020 - week 10, 2021.
smartWins = SmartWinsAllTimeCalculator.getSmartWins(
league, weekNumberStart=5, yearNumberStart=2020, weekNumberEnd=10, yearNumberEnd=2021
league,
weekNumberStart=5,
yearNumberStart=2020,
weekNumberEnd=10,
yearNumberEnd=2021,
)
30 changes: 20 additions & 10 deletions example/stat/gettingStatsForYearExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,41 @@
wins = GameOutcomeYearCalculator.getWins(year2019)

# Get opponent points scored per game.
opponentPointsScoredPerGame = PointsScoredYearCalculator.getOpponentPointsScoredPerGame(
year2019
opponentPointsScoredPerGame = (
PointsScoredYearCalculator.getOpponentPointsScoredPerGame(year2019)
)

# To limit results to only regular season, specify that as a keyword argument.
maxScore = SingleScoreYearCalculator.getMaxScore(year2019, onlyRegularSeason=True)

# To limit results to only post-season (playoffs), specify that as a keyword argument.
scoringShare = ScoringShareYearCalculator.getScoringShare(year2019, onlyPostSeason=True)
scoringShare = ScoringShareYearCalculator.getScoringShare(
year2019, onlyPostSeason=True
)

# To limit results to only championship games, specify that as a keyword argument.
winPercentage = GameOutcomeYearCalculator.getWinPercentage(year2019, onlyChampionship=True)
winPercentage = GameOutcomeYearCalculator.getWinPercentage(
year2019, onlyChampionship=True
)

# To limit results to only certain weeks, specify that as a keyword argument.
# Let's assume this year has weeks 1-15.

# Will get weeks 5-15.
scoringStandardDeviation = ScoringStandardDeviationYearCalculator.getScoringStandardDeviation(
year2019, weekNumberStart=5
scoringStandardDeviation = (
ScoringStandardDeviationYearCalculator.getScoringStandardDeviation(
year2019, weekNumberStart=5
)
)
# Will get weeks 1-10.
scoringStandardDeviation = ScoringStandardDeviationYearCalculator.getScoringStandardDeviation(
year2019, weekNumberEnd=10
scoringStandardDeviation = (
ScoringStandardDeviationYearCalculator.getScoringStandardDeviation(
year2019, weekNumberEnd=10
)
)
# Will get weeks 5-10.
scoringStandardDeviation = ScoringStandardDeviationYearCalculator.getScoringStandardDeviation(
year2019, weekNumberStart=5, weekNumberEnd=10
scoringStandardDeviation = (
ScoringStandardDeviationYearCalculator.getScoringStandardDeviation(
year2019, weekNumberStart=5, weekNumberEnd=10
)
)
11 changes: 8 additions & 3 deletions leeger/calculator/all_time_calculator/AWALAllTimeCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ def getOpponentAWAL(cls, league: League, **kwargs) -> dict[str, Optional[Deci]]:
...
}
"""
return cls._addAndCombineResults(league, AWALYearCalculator.getOpponentAWAL, **kwargs)
return cls._addAndCombineResults(
league, AWALYearCalculator.getOpponentAWAL, **kwargs
)

@classmethod
@validateLeague
def getOpponentAWALPerGame(cls, league: League, **kwargs) -> dict[str, Optional[Deci]]:
def getOpponentAWALPerGame(
cls, league: League, **kwargs
) -> dict[str, Optional[Deci]]:
"""
Returns the number of Adjusted Wins Against the League per game for each Owner's opponent in the given League.
Returns None for an Owner if they have no games played in the range.
Expand Down Expand Up @@ -124,7 +128,8 @@ def getOpponentAWALPerGame(cls, league: League, **kwargs) -> dict[str, Optional[
ownerIdAndOpponentAWALPerGame[ownerId] = None
else:
ownerIdAndOpponentAWALPerGame[ownerId] = (
ownerIdAndOpponentAWAL[ownerId] / ownerIdAndNumberOfGamesPlayed[ownerId]
ownerIdAndOpponentAWAL[ownerId]
/ ownerIdAndNumberOfGamesPlayed[ownerId]
)

return ownerIdAndOpponentAWALPerGame
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from leeger.calculator.parent.AllTimeCalculator import AllTimeCalculator
from leeger.calculator.year_calculator.GameOutcomeYearCalculator import GameOutcomeYearCalculator
from leeger.calculator.year_calculator.GameOutcomeYearCalculator import (
GameOutcomeYearCalculator,
)
from leeger.decorator.validators import validateLeague
from leeger.model.filter import AllTimeFilters
from leeger.model.league.League import League
Expand All @@ -25,7 +27,9 @@ def getWins(cls, league: League, **kwargs) -> dict[str, Optional[int]]:
...
}
"""
return cls._addAndCombineResults(league, GameOutcomeYearCalculator.getWins, **kwargs)
return cls._addAndCombineResults(
league, GameOutcomeYearCalculator.getWins, **kwargs
)

@classmethod
@validateLeague
Expand All @@ -42,7 +46,9 @@ def getLosses(cls, league: League, **kwargs) -> dict[str, Optional[int]]:
...
}
"""
return cls._addAndCombineResults(league, GameOutcomeYearCalculator.getLosses, **kwargs)
return cls._addAndCombineResults(
league, GameOutcomeYearCalculator.getLosses, **kwargs
)

@classmethod
@validateLeague
Expand All @@ -59,7 +65,9 @@ def getTies(cls, league: League, **kwargs) -> dict[str, Optional[int]]:
...
}
"""
return cls._addAndCombineResults(league, GameOutcomeYearCalculator.getTies, **kwargs)
return cls._addAndCombineResults(
league, GameOutcomeYearCalculator.getTies, **kwargs
)

@classmethod
@validateLeague
Expand Down Expand Up @@ -95,7 +103,12 @@ def getWinPercentage(cls, league: League, **kwargs) -> dict[str, Optional[Deci]]
numberOfTies = ownerIdAndTies[ownerId]
numberOfLeagueMedianWins = ownerIdAndLeagueMedianWins[ownerId]

if None in (numberOfWins, numberOfLosses, numberOfTies, numberOfLeagueMedianWins):
if None in (
numberOfWins,
numberOfLosses,
numberOfTies,
numberOfLeagueMedianWins,
):
ownerIdAndWinPercentage[ownerId] = None
else:
filters = AllTimeFilters.getForLeague(league, **kwargs)
Expand Down Expand Up @@ -210,7 +223,9 @@ def getLeagueMedianWins(cls, league: League, **kwargs) -> dict[str, Optional[Dec

@classmethod
@validateLeague
def getOpponentLeagueMedianWins(cls, league: League, **kwargs) -> dict[str, Optional[Deci]]:
def getOpponentLeagueMedianWins(
cls, league: League, **kwargs
) -> dict[str, Optional[Deci]]:
"""
Returns the number of league median wins for each Owner's opponents in the given League.
Returns None for an Owner if they have no games played in the range.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from leeger.calculator.parent.AllTimeCalculator import AllTimeCalculator
from leeger.calculator.year_calculator.PlusMinusYearCalculator import PlusMinusYearCalculator
from leeger.calculator.year_calculator.PlusMinusYearCalculator import (
PlusMinusYearCalculator,
)
from leeger.decorator.validators import validateLeague
from leeger.model.league.League import League
from leeger.util.Deci import Deci
Expand Down Expand Up @@ -35,4 +37,6 @@ def getPlusMinus(cls, league: League, **kwargs) -> dict[str, Optional[Deci]]:
}
"""

return cls._addAndCombineResults(league, PlusMinusYearCalculator.getPlusMinus, **kwargs)
return cls._addAndCombineResults(
league, PlusMinusYearCalculator.getPlusMinus, **kwargs
)
Loading

0 comments on commit e731197

Please sign in to comment.