James McCool commited on
Commit
1689df1
·
1 Parent(s): 1e8df5a

Refactor file upload sections in `app.py` for improved organization and clarity

Browse files

- Removed the CSV upload section for Draftkings/Fanduel, streamlining the interface.
- Adjusted column layout for contest and projections file uploads to enhance user experience.
- Updated the handling of uploaded files to ensure better data management and accessibility.

Files changed (2) hide show
  1. app.py +2 -32
  2. global_func/load_file.py +7 -1
app.py CHANGED
@@ -22,38 +22,8 @@ with tab1:
22
  st.session_state.clear()
23
  # Add file uploaders to your app
24
  col1, col2, col3 = st.columns(3)
25
-
26
- with col1:
27
- st.subheader("Draftkings/Fanduel CSV")
28
- st.info("Upload the player pricing CSV from the site you are playing on.")
29
-
30
- upload_csv_col, csv_template_col = st.columns([3, 1])
31
- with upload_csv_col:
32
- csv_file = st.file_uploader("Upload CSV File", type=['csv'])
33
- if 'csv_file' in st.session_state:
34
- del st.session_state['csv_file']
35
- with csv_template_col:
36
-
37
- csv_template_df = pd.DataFrame(columns=['Name', 'ID', 'Roster Position', 'Salary'])
38
-
39
- st.download_button(
40
- label="CSV Template",
41
- data=csv_template_df.to_csv(index=False),
42
- file_name="csv_template.csv",
43
- mime="text/csv"
44
- )
45
- st.session_state['csv_file'] = load_csv(csv_file)
46
- try:
47
- st.session_state['csv_file']['Salary'] = st.session_state['csv_file']['Salary'].astype(str).str.replace(',', '').astype(int)
48
- except:
49
- pass
50
-
51
- if csv_file:
52
- st.session_state['csv_file'] = st.session_state['csv_file'].drop_duplicates(subset=['Name'])
53
- st.success('Projections file loaded successfully!')
54
- st.dataframe(st.session_state['csv_file'].head(10))
55
 
56
- with col2:
57
  st.subheader("Contest File")
58
  st.info("Go ahead and upload a Contest file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
59
  Contest_file = st.file_uploader("Upload Contest File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
@@ -68,7 +38,7 @@ with tab1:
68
  st.success('Contest file loaded successfully!')
69
  st.dataframe(st.session_state['Contest'].head(10))
70
 
71
- with col3:
72
  st.subheader("Projections File")
73
  st.info("upload a projections file that has 'player_names', 'salary', 'median', 'ownership', and 'captain ownership' (Needed for Showdown) columns. Note that the salary for showdown needs to be the FLEX salary, not the captain salary.")
74
 
 
22
  st.session_state.clear()
23
  # Add file uploaders to your app
24
  col1, col2, col3 = st.columns(3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ with col1:
27
  st.subheader("Contest File")
28
  st.info("Go ahead and upload a Contest file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
29
  Contest_file = st.file_uploader("Upload Contest File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
 
38
  st.success('Contest file loaded successfully!')
39
  st.dataframe(st.session_state['Contest'].head(10))
40
 
41
+ with col2:
42
  st.subheader("Projections File")
43
  st.info("upload a projections file that has 'player_names', 'salary', 'median', 'ownership', and 'captain ownership' (Needed for Showdown) columns. Note that the salary for showdown needs to be the FLEX salary, not the captain salary.")
44
 
global_func/load_file.py CHANGED
@@ -21,6 +21,12 @@ def load_file(upload):
21
 
22
  df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
23
  df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
 
 
 
 
 
 
24
  # Split the lineup string by replacing position indicators with commas
25
  # We need to ensure we only replace position indicators that are at the start of a player entry
26
  # and not those that might appear within player names
@@ -33,7 +39,7 @@ def load_file(upload):
33
  df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
34
  position_dict = dict(zip(df['Player'], df['Pos']))
35
  ownership_dict = dict(zip(df['Player'], df['Own']))
36
- entry_list = list(set(df['EntryName']))
37
  entry_list.sort()
38
 
39
  return df, position_dict, ownership_dict, entry_list
 
21
 
22
  df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
23
  df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
24
+
25
+ # Split EntryName into base name and entry count
26
+ df['BaseName'] = df['EntryName'].str.replace(r'\s*\(\d+/\d+\)$', '', regex=True)
27
+ df['EntryCount'] = df['EntryName'].str.extract(r'\((\d+/\d+)\)')
28
+ df['EntryCount'] = df['EntryCount'].fillna('1/1') # Default to 1/1 if no entry count
29
+
30
  # Split the lineup string by replacing position indicators with commas
31
  # We need to ensure we only replace position indicators that are at the start of a player entry
32
  # and not those that might appear within player names
 
39
  df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
40
  position_dict = dict(zip(df['Player'], df['Pos']))
41
  ownership_dict = dict(zip(df['Player'], df['Own']))
42
+ entry_list = list(set(df['BaseName']))
43
  entry_list.sort()
44
 
45
  return df, position_dict, ownership_dict, entry_list