Skip to content

Commit

Permalink
Devex Improvements (#120)
Browse files Browse the repository at this point in the history
- Use Ruff as a formatter
- General Makefile improvements
  • Loading branch information
joeyagreco authored Aug 12, 2024
1 parent cb544a7 commit 6a7c7ae
Show file tree
Hide file tree
Showing 119 changed files with 11,710 additions and 3,823 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
12 changes: 5 additions & 7 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ jobs:
build:
name: unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3

- name: Get current required Python version
id: get-python-versions
run: |
MINIMUM_VERSION=$(grep -oP '__version_minimum_python__ = "\K.*(?=")' leeger/_version.py)
echo "CURRENT_VERSION=$MINIMUM_VERSION" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ env.CURRENT_VERSION }}
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
Expand Down
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
Loading

0 comments on commit 6a7c7ae

Please sign in to comment.