From 7c21ebc3a3a517b20f5faa0be84a75c4c4d6c7e1 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 13:21:43 -0600 Subject: [PATCH 1/8] add tests --- .github/workflows/pytest.yml | 24 ++++++++ main.py | 14 +++-- requirements.txt | 1 + tests/draftkings.csv | 75 ++++++++++++++++++++++++ tests/test.py | 109 +++++++++++++++++++++++++++++++++++ 5 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pytest.yml create mode 100644 tests/draftkings.csv create mode 100644 tests/test.py diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..a41cea2 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,24 @@ +name: Run Pytest + +on: + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run pytest + run: pytest diff --git a/main.py b/main.py index d72e0d5..fde6330 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,6 @@ # trim whitespace from columns players = players.apply(lambda x: x.str.strip() if x.dtype == "object" else x) - # Group players by position available_players = players.groupby([POSITION, PLAYER, PROJECTION, SALARY]).size().reset_index() @@ -34,6 +33,7 @@ for pos in available_players[POSITION].unique() } + def calculate_lineups(lineup_type, output_file): lineup_results = [] previous_lineups = [] @@ -86,7 +86,13 @@ def calculate_lineups(lineup_type, output_file): pd.DataFrame(lineup_results).to_csv(output_file + ".csv", index=False, header=False) -for name, config in lineup_configs.items(): - calculate_lineups(config, name) -print("Lineup files created") +def generate_lineup_files(): + for name, config in lineup_configs.items(): + calculate_lineups(config, name) + + print("Lineup files created") + + +if __name__ == "__main__": + generate_lineup_files() diff --git a/requirements.txt b/requirements.txt index 8845169..456354e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pandas==2.2.3 pulp==2.9.0 +pytest==8.3.3 diff --git a/tests/draftkings.csv b/tests/draftkings.csv new file mode 100644 index 0000000..45b6dde --- /dev/null +++ b/tests/draftkings.csv @@ -0,0 +1,75 @@ +Player,DK Position,DK Salary,DK Projection +"Alvin and the Chipmunks","RB","7800","22.9" +"Matt Busche","RB","7800","22.9" +"Chase from Paw Patrol","RB","5900","17.9" +"Austin Powers","RB","5300","16.2" +"Kyren Williams","RB","7000","21.1" +"CeeDee Lamb","WR","8800","22.6" +"Chris Olave","WR","6100","17" +"Drake London","WR","6700","20" +"James Conner","RB","7600","17.5" +"Mike Gesicki","TE","3100","10.6" +"Ja'Marr Chase","WR","8600","21.3" +"Titans ","DST","3200","8.7" +"De'Von Achane","RB","6400","17.5" +"Bijan Robinson","RB","7400","18.8" +"Tyreek Hill","WR","7300","18.6" +"Geno Smith","QB","4800","13.9" +"Cardinals ","DST","2600","7.1" +"Justin Herbert","QB","5300","17.2" +"Malik Nabers","WR","7500","18.6" +"Kenneth Walker III","RB","7300","18.1" +"Jameis Winston","QB","5400","17.4" +"Gardner Minshew II","QB","4500","14.7" +"Saquon Barkley","RB","8200","19.9" +"David Njoku","TE","5500","14.4" +"Jakobi Meyers","WR","5300","14" +"Giants ","DST","2300","6.1" +"D'Andre Swift","RB","6400","16.1" +"Daniel Jones","QB","5200","16.6" +"LAC ","DST","3300","7.8" +"Trey McBride","TE","5800","14.7" +"Mason Rudolph","QB","4600","14.5" +"Eagles ","DST","3100","7.4" +"Ravens ","DST","3500","8" +"Dak Prescott","QB","6300","19.5" +"Saints ","DST","3800","8.5" +"Commanders ","DST","3400","7.8" +"Bryce Young","QB","4400","13.6" +"Cedric Tillman","WR","4300","11.5" +"James Cook","RB","7200","17" +"Jaxon Smith-Njigba","WR","6200","15" +"LAR ","DST","2800","6.3" +"Chuba Hubbard","RB","6500","15.5" +"Tyler Lockett","WR","5600","13.7" +"Lamar Jackson","QB","8000","24.3" +"Dalton Kincaid","TE","5000","12.5" +"Bo Nix","QB","5900","17.9" +"Alexander Mattison","RB","5700","13.9" +"Tony Pollard","RB","6800","16.1" +"BUF ","DST","3000","6.5" +"CIN ","DST","3700","7.9" +"Ladd McConkey","WR","5600","13.6" +"Tyrone Tracy Jr.","RB","5500","13.4" +"Darnell Mooney","WR","6000","14.3" +"Josh Allen","QB","7700","23.1" +"Matthew Stafford","QB","5700","17" +"Taysom Hill","TE","3800","9.9" +"CHI ","DST","2800","6" +"CLE ","DST","2900","6.1" +"LV ","DST","2400","5.2" +"Kyler Murray","QB","6600","19.7" +"Derrick Henry","RB","8300","18.7" +"Evan Engram","TE","5300","12.8" +"Brock Bowers","TE","6000","14.2" +"Calvin Ridley","WR","5700","13.6" +"Jayden Daniels","QB","7500","22.4" +"Cooper Kupp","WR","7700","17.4" +"Jalen Hurts","QB","7800","23.3" +"Joe Burrow","QB","6900","20.4" +"Jahmyr Gibbs","RB","7600","17.2" +"NE ","DST","3000","6.1" +"SEA ","DST","2600","5.3" +"Kirk Cousins","QB","6400","18.8" +"J.K. Dobbins","RB","7000","15.9" +"AJ Barner","TE","2600","7.2" diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..e1d6a60 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,109 @@ +import os + +import pytest + +from main import generate_lineup_files + + +@pytest.fixture(autouse=True) +def generate_files(): + generate_lineup_files() + + +def test_generate_lineup_files(): + assert os.path.exists('four_wr.csv') + assert os.path.exists('three_rb.csv') + assert os.path.exists('two_te.csv') + + +def test_four_wr(): + with open('four_wr.csv', 'r') as f: + four_wr = [f.readline().strip() for _ in range(10)] + + conditions = [ + len(four_wr) == 10, + four_wr[ + 0] == "1,DST,Cardinals,2600,7.1,QB,Dak Prescott,6300,19.5,RB,Alvin and the Chipmunks,7800,22.9,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,145.5", + four_wr[ + 1] == "2,DST,Titans,3200,8.7,QB,Dak Prescott,6300,19.5,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", + four_wr[ + 2] == "3,DST,Titans,3200,8.7,QB,Jameis Winston,5400,17.4,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,WR,Tyreek Hill,7300,18.6,50000,145.3", + four_wr[ + 3] == "4,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Chase from Paw Patrol,5900,17.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", + four_wr[ + 4] == "5,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Chase from Paw Patrol,5900,17.9,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", + four_wr[ + 5] == "6,DST,Titans,3200,8.7,QB,Dak Prescott,6300,19.5,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", + four_wr[ + 6] == "7,DST,Giants,2300,6.1,QB,Jameis Winston,5400,17.4,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Tyreek Hill,7300,18.6,50000,145.2", + four_wr[ + 7] == "8,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Austin Powers,5300,16.2,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.2", + four_wr[ + 8] == "9,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Austin Powers,5300,16.2,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.2", + four_wr[ + 9] == "10,DST,Giants,2300,6.1,QB,Jameis Winston,5400,17.4,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Tyreek Hill,7300,18.6,50000,145.2", + ] + + assert all(conditions) + + +def test_three_rb(): + with open('three_rb.csv', 'r') as f: + three_rb = [f.readline().strip() for _ in range(10)] + + conditions = [ + len(three_rb) == 10, + three_rb[ + 0] == "1,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Austin Powers,5300,16.2,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,148.2", + three_rb[ + 1] == "2,DST,Cardinals,2600,7.1,QB,Jameis Winston,5400,17.4,RB,Alvin and the Chipmunks,7800,22.9,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49900,148.0", + three_rb[ + 2] == "3,DST,Cardinals,2600,7.1,QB,Jameis Winston,5400,17.4,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49900,148.0", + three_rb[ + 3] == "4,DST,Titans,3200,8.7,QB,Jameis Winston,5400,17.4,RB,Alvin and the Chipmunks,7800,22.9,RB,Austin Powers,5300,16.2,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49900,147.9", + three_rb[ + 4] == "5,DST,Titans,3200,8.7,QB,Jameis Winston,5400,17.4,RB,Austin Powers,5300,16.2,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49900,147.9", + three_rb[ + 5] == "6,DST,Cardinals,2600,7.1,QB,Justin Herbert,5300,17.2,RB,Alvin and the Chipmunks,7800,22.9,RB,Austin Powers,5300,16.2,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,147.9", + three_rb[ + 6] == "7,DST,Cardinals,2600,7.1,QB,Gardner Minshew II,4500,14.7,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,49900,147.8", + three_rb[ + 7] == "8,DST,Cardinals,2600,7.1,QB,Justin Herbert,5300,17.2,RB,Alvin and the Chipmunks,7800,22.9,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,147.8", + three_rb[ + 8] == "9,DST,Cardinals,2600,7.1,QB,Justin Herbert,5300,17.2,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,147.8", + three_rb[ + 9] == "10,DST,Cardinals,2600,7.1,QB,Dak Prescott,6300,19.5,RB,Alvin and the Chipmunks,7800,22.9,RB,Austin Powers,5300,16.2,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,50000,147.7", + ] + + assert all(conditions) + + +def test_two_te(): + with open('two_te.csv', 'r') as f: + two_te = [f.readline().strip() for _ in range(10)] + + conditions = [ + len(two_te) == 10, + two_te[ + 0] == "1,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,TE,Taysom Hill,3800,9.9,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,50000,146.0", + two_te[ + 1] == "2,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,TE,Taysom Hill,3800,9.9,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,50000,146.0", + two_te[ + 2] == "3,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Matt Busche,7800,22.9,TE,AJ Barner,2600,7.2,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,146.0", + two_te[ + 3] == "4,DST,Titans,3200,8.7,QB,Justin Herbert,5300,17.2,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,David Njoku,5500,14.4,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,145.9", + two_te[ + 4] == "5,DST,Titans,3200,8.7,QB,Justin Herbert,5300,17.2,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,David Njoku,5500,14.4,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,145.9", + two_te[ + 5] == "6,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,AJ Barner,2600,7.2,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.8", + two_te[ + 6] == "7,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,AJ Barner,2600,7.2,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.8", + two_te[ + 7] == "8,DST,Titans,3200,8.7,QB,Dak Prescott,6300,19.5,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,David Njoku,5500,14.4,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,50000,145.7", + two_te[ + 8] == "9,DST,Titans,3200,8.7,QB,Dak Prescott,6300,19.5,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,David Njoku,5500,14.4,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,50000,145.7", + two_te[ + 9] == "10,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Chase from Paw Patrol,5900,17.9,RB,Matt Busche,7800,22.9,TE,David Njoku,5500,14.4,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,50000,145.7", + ] + + assert all(conditions) From 53508f9b7912739a5b47f446de864d3cae250429 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 13:21:52 -0600 Subject: [PATCH 2/8] ignore csv again --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6764e14..f63e7fd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.csv .idea/ +__pycache__/ From 848866cadc558891e0288dbf3e1cb91a5f6e34fb Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 13:32:55 -0600 Subject: [PATCH 3/8] add python path --- .github/workflows/pytest.yml | 3 ++- tests/{test.py => test_things.py} | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename tests/{test.py => test_things.py} (100%) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index a41cea2..80993df 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -17,8 +17,9 @@ jobs: - name: Install dependencies run: | + export PYTHONPATH=$PYTHONPATH:. python -m pip install --upgrade pip pip install -r requirements.txt - name: Run pytest - run: pytest + run: pytest tests/ diff --git a/tests/test.py b/tests/test_things.py similarity index 100% rename from tests/test.py rename to tests/test_things.py From b21d8b11f9b9ba9b593ebddedb94766bf0da3c8e Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 13:35:29 -0600 Subject: [PATCH 4/8] run tests --- .github/workflows/pytest.yml | 1 - tests/__init__.py | 0 2 files changed, 1 deletion(-) create mode 100644 tests/__init__.py diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 80993df..6a4c42d 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -17,7 +17,6 @@ jobs: - name: Install dependencies run: | - export PYTHONPATH=$PYTHONPATH:. python -m pip install --upgrade pip pip install -r requirements.txt diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 22cbcb70f8f4ff6eaad0e921aab7378286b657d9 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 13:37:49 -0600 Subject: [PATCH 5/8] Rename tests/draftkings.csv to draftkings.csv --- tests/draftkings.csv => draftkings.csv | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/draftkings.csv => draftkings.csv (100%) diff --git a/tests/draftkings.csv b/draftkings.csv similarity index 100% rename from tests/draftkings.csv rename to draftkings.csv From d61472cb4655db234b02ac85b7d1a888f144c810 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 15:37:39 -0600 Subject: [PATCH 6/8] make filename a param --- main.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index fde6330..b15b46e 100644 --- a/main.py +++ b/main.py @@ -16,25 +16,24 @@ "two_te": {"QB": 1, "RB": 2, "WR": 3, "TE": 2, "DST": 1} } -players = pd.read_csv("draftkings.csv", usecols=[PLAYER, POSITION, PROJECTION, SALARY]) -# trim whitespace from columns -players = players.apply(lambda x: x.str.strip() if x.dtype == "object" else x) +def calculate_lineups(lineup_type, output_file, csv_file): + players = pd.read_csv(csv_file, usecols=[PLAYER, POSITION, PROJECTION, SALARY]) + # trim whitespace from columns + players = players.apply(lambda x: x.str.strip() if x.dtype == "object" else x) + + # Group players by position + available_players = players.groupby([POSITION, PLAYER, PROJECTION, SALARY]).size().reset_index() + + # Create salary and points dicts by position + salaries = { + pos: available_players[available_players[POSITION] == pos].set_index(PLAYER)[SALARY].to_dict() + for pos in available_players[POSITION].unique() + } + points = { + pos: available_players[available_players[POSITION] == pos].set_index(PLAYER)[PROJECTION].to_dict() + for pos in available_players[POSITION].unique() + } -# Group players by position -available_players = players.groupby([POSITION, PLAYER, PROJECTION, SALARY]).size().reset_index() - -# Create salary and points dicts by position -salaries = { - pos: available_players[available_players[POSITION] == pos].set_index(PLAYER)[SALARY].to_dict() - for pos in available_players[POSITION].unique() -} -points = { - pos: available_players[available_players[POSITION] == pos].set_index(PLAYER)[PROJECTION].to_dict() - for pos in available_players[POSITION].unique() -} - - -def calculate_lineups(lineup_type, output_file): lineup_results = [] previous_lineups = [] @@ -87,12 +86,13 @@ def calculate_lineups(lineup_type, output_file): pd.DataFrame(lineup_results).to_csv(output_file + ".csv", index=False, header=False) -def generate_lineup_files(): +def generate_lineup_files(csv_file): for name, config in lineup_configs.items(): - calculate_lineups(config, name) + calculate_lineups(config, name, csv_file) print("Lineup files created") if __name__ == "__main__": - generate_lineup_files() + csv_file = "draftkings.csv" # You can change this to any CSV file name + generate_lineup_files(csv_file) From fae4ee13ed1171bd89160798efd0fd0c1d7bca95 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 15:37:51 -0600 Subject: [PATCH 7/8] pass in file --- tests/test_things.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_things.py b/tests/test_things.py index e1d6a60..1568d4b 100644 --- a/tests/test_things.py +++ b/tests/test_things.py @@ -7,7 +7,7 @@ @pytest.fixture(autouse=True) def generate_files(): - generate_lineup_files() + generate_lineup_files('./draftkings.csv') def test_generate_lineup_files(): From bb06c5ba9fa823cb86eb79268d4ace296c282a4b Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 15:41:46 -0600 Subject: [PATCH 8/8] work around test ordering --- tests/test_things.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/test_things.py b/tests/test_things.py index 1568d4b..5069f9e 100644 --- a/tests/test_things.py +++ b/tests/test_things.py @@ -20,28 +20,19 @@ def test_four_wr(): with open('four_wr.csv', 'r') as f: four_wr = [f.readline().strip() for _ in range(10)] + # because of the duplicate scores, the results are not always returned in the same order conditions = [ len(four_wr) == 10, - four_wr[ - 0] == "1,DST,Cardinals,2600,7.1,QB,Dak Prescott,6300,19.5,RB,Alvin and the Chipmunks,7800,22.9,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,50000,145.5", - four_wr[ - 1] == "2,DST,Titans,3200,8.7,QB,Dak Prescott,6300,19.5,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", - four_wr[ - 2] == "3,DST,Titans,3200,8.7,QB,Jameis Winston,5400,17.4,RB,Chase from Paw Patrol,5900,17.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,WR,Tyreek Hill,7300,18.6,50000,145.3", - four_wr[ - 3] == "4,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Chase from Paw Patrol,5900,17.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", - four_wr[ - 4] == "5,DST,Cardinals,2600,7.1,QB,Lamar Jackson,8000,24.3,RB,Chase from Paw Patrol,5900,17.9,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", - four_wr[ - 5] == "6,DST,Titans,3200,8.7,QB,Dak Prescott,6300,19.5,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.3", - four_wr[ - 6] == "7,DST,Giants,2300,6.1,QB,Jameis Winston,5400,17.4,RB,Alvin and the Chipmunks,7800,22.9,RB,Kyren Williams,7000,21.1,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Tyreek Hill,7300,18.6,50000,145.2", - four_wr[ - 7] == "8,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Alvin and the Chipmunks,7800,22.9,RB,Austin Powers,5300,16.2,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.2", - four_wr[ - 8] == "9,DST,Titans,3200,8.7,QB,Lamar Jackson,8000,24.3,RB,Austin Powers,5300,16.2,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Jakobi Meyers,5300,14.0,49800,145.2", - four_wr[ - 9] == "10,DST,Giants,2300,6.1,QB,Jameis Winston,5400,17.4,RB,Kyren Williams,7000,21.1,RB,Matt Busche,7800,22.9,TE,Mike Gesicki,3100,10.6,WR,Cedric Tillman,4300,11.5,WR,Chris Olave,6100,17.0,WR,Drake London,6700,20.0,WR,Tyreek Hill,7300,18.6,50000,145.2", + four_wr[0][-5:] == "145.5", + four_wr[1][-5:] == "145.3", + four_wr[2][-5:] == "145.3", + four_wr[3][-5:] == "145.3", + four_wr[4][-5:] == "145.3", + four_wr[5][-5:] == "145.3", + four_wr[6][-5:] == "145.2", + four_wr[7][-5:] == "145.2", + four_wr[8][-5:] == "145.2", + four_wr[9][-5:] == "145.2", ] assert all(conditions)