James McCool commited on
Commit
7852820
·
1 Parent(s): bf8ac3e

Add support for DraftKings/Fanduel file uploads in app.py: implement a new upload option for processing lineups, integrating a dedicated loading function for enhanced compatibility with different data sources.

Browse files
Files changed (2) hide show
  1. app.py +16 -10
  2. global_func/load_dk_fd_file.py +34 -0
app.py CHANGED
@@ -10,6 +10,7 @@ import random
10
  from global_func.clean_player_name import clean_player_name
11
  from global_func.load_file import load_file
12
  from global_func.load_ss_file import load_ss_file
 
13
  from global_func.find_name_mismatches import find_name_mismatches
14
  from global_func.predict_dupes import predict_dupes
15
  from global_func.highlight_rows import highlight_changes, highlight_changes_winners, highlight_changes_losers
@@ -62,15 +63,14 @@ with tab1:
62
  with col2:
63
  st.subheader("Portfolio File")
64
  st.info("Go ahead and upload a portfolio file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
65
- saber_toggle = st.radio("Are you uploading from SaberSim?", options=['No', 'Yes'])
66
- st.info("If you are uploading from SaberSim, you will need to upload a CSV file for the slate for name matching.")
67
- if saber_toggle == 'Yes':
68
- if csv_file is not None:
69
- portfolio_file = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
70
- if 'portfolio' in st.session_state:
71
- del st.session_state['portfolio']
72
- if 'export_portfolio' in st.session_state:
73
- del st.session_state['export_portfolio']
74
 
75
  else:
76
  portfolio_file = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
@@ -80,12 +80,18 @@ with tab1:
80
  del st.session_state['export_portfolio']
81
  if 'portfolio' not in st.session_state:
82
  if portfolio_file:
83
- if saber_toggle == 'Yes':
84
  st.session_state['export_portfolio'], st.session_state['portfolio'] = load_ss_file(portfolio_file, st.session_state['csv_file'])
85
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
86
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
87
  st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
88
  st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
 
 
 
 
 
 
89
  else:
90
  st.session_state['export_portfolio'], st.session_state['portfolio'] = load_file(portfolio_file)
91
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
 
10
  from global_func.clean_player_name import clean_player_name
11
  from global_func.load_file import load_file
12
  from global_func.load_ss_file import load_ss_file
13
+ from global_func.load_dk_fd_file import load_dk_fd_file
14
  from global_func.find_name_mismatches import find_name_mismatches
15
  from global_func.predict_dupes import predict_dupes
16
  from global_func.highlight_rows import highlight_changes, highlight_changes_winners, highlight_changes_losers
 
63
  with col2:
64
  st.subheader("Portfolio File")
65
  st.info("Go ahead and upload a portfolio file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
66
+
67
+ upload_toggle = st.selectbox("What source are you uploading from?", options=['SaberSim (Just IDs)', 'Draftkings/Fanduel (Names + IDs)', 'Other (Just Names)'])
68
+ if upload_toggle == 'SaberSim (Just IDs)' or upload_toggle == 'Draftkings/Fanduel (Names + IDs)':
69
+ portfolio_file = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
70
+ if 'portfolio' in st.session_state:
71
+ del st.session_state['portfolio']
72
+ if 'export_portfolio' in st.session_state:
73
+ del st.session_state['export_portfolio']
 
74
 
75
  else:
76
  portfolio_file = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
 
80
  del st.session_state['export_portfolio']
81
  if 'portfolio' not in st.session_state:
82
  if portfolio_file:
83
+ if upload_toggle == 'SaberSim (Just IDs)':
84
  st.session_state['export_portfolio'], st.session_state['portfolio'] = load_ss_file(portfolio_file, st.session_state['csv_file'])
85
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
86
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
87
  st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
88
  st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
89
+ elif upload_toggle == 'Draftkings/Fanduel (Names + IDs)':
90
+ st.session_state['export_portfolio'], st.session_state['portfolio'] = load_dk_fd_file(portfolio_file, st.session_state['csv_file'])
91
+ st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
92
+ st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
93
+ st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
94
+ st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
95
  else:
96
  st.session_state['export_portfolio'], st.session_state['portfolio'] = load_file(portfolio_file)
97
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
global_func/load_dk_fd_file.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import time
5
+ from fuzzywuzzy import process
6
+
7
+ def load_dk_fd_file(lineups, csv_file):
8
+ df = csv_file.copy()
9
+ try:
10
+ name_dict = dict(zip(df['Name + ID'], df['Name']))
11
+ except:
12
+ name_dict = dict(zip(df['Id'], df['Nickname']))
13
+
14
+ # Now load and process the lineups file
15
+ try:
16
+ if lineups.name.endswith('.csv'):
17
+ lineups_df = pd.read_csv(lineups)
18
+ elif lineups.name.endswith(('.xls', '.xlsx')):
19
+ lineups_df = pd.read_excel(lineups)
20
+ else:
21
+ st.error('Please upload either a CSV or Excel file for lineups')
22
+ return None, None
23
+
24
+ export_df = lineups_df.copy()
25
+
26
+ # Map the IDs to names
27
+ for col in lineups_df.columns:
28
+ lineups_df[col] = lineups_df[col].map(name_dict)
29
+
30
+ return export_df, lineups_df
31
+
32
+ except Exception as e:
33
+ st.error(f'Error loading lineups file: {str(e)}')
34
+ return None, None