From d61472cb4655db234b02ac85b7d1a888f144c810 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sun, 3 Nov 2024 15:37:39 -0600 Subject: [PATCH] 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)