James McCool
commited on
Commit
·
ad5adce
1
Parent(s):
e1f40de
Refactor name matching logic in app.py for improved condition handling
Browse files- Updated the conditional check for contest file loading to ensure it handles both empty and valid file inputs effectively.
- Streamlined the name matching functions to enhance clarity and maintainability, ensuring proper data processing when both contest and projection files are present.
- Removed unnecessary debug output from the load_contest_file function to improve user experience.
- app.py +11 -10
- global_func/load_contest_file.py +0 -2
app.py
CHANGED
@@ -112,16 +112,17 @@ with tab1:
|
|
112 |
st.success('Projections file loaded successfully!')
|
113 |
st.dataframe(st.session_state['projections_df'].head(10))
|
114 |
|
115 |
-
if Contest_file
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
125 |
|
126 |
|
127 |
with tab2:
|
|
|
112 |
st.success('Projections file loaded successfully!')
|
113 |
st.dataframe(st.session_state['projections_df'].head(10))
|
114 |
|
115 |
+
if Contest_file or len(Contest_file) > 0:
|
116 |
+
if projections_file:
|
117 |
+
st.subheader("Name Matching functions")
|
118 |
+
if 'Adj_Contest' not in st.session_state:
|
119 |
+
try:
|
120 |
+
st.session_state['Adj_Contest'], st.session_state['Adj_projections_df'], st.session_state['Adj_ownership_df'], st.session_state['Adj_actual_df'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_df'], st.session_state['actual_df'])
|
121 |
+
except:
|
122 |
+
st.warning('Please manage name matching to move forward')
|
123 |
+
st.session_state['Adj_projections_df']['salary'] = (st.session_state['Adj_projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
124 |
+
st.session_state['ownership_dict'] = dict(zip(st.session_state['Adj_ownership_df']['Player'], st.session_state['Adj_ownership_df']['Own']))
|
125 |
+
st.session_state['actual_dict'] = dict(zip(st.session_state['Adj_actual_df']['Player'], st.session_state['Adj_actual_df']['FPTS']))
|
126 |
|
127 |
|
128 |
with tab2:
|
global_func/load_contest_file.py
CHANGED
@@ -19,8 +19,6 @@ def load_contest_file(upload, sport):
|
|
19 |
|
20 |
df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
|
21 |
df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
|
22 |
-
|
23 |
-
st.write(df.head(10))
|
24 |
|
25 |
# Split EntryName into base name and entry count
|
26 |
df['BaseName'] = df['EntryName'].str.replace(r'\s*\(\d+/\d+\)$', '', regex=True)
|
|
|
19 |
|
20 |
df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
|
21 |
df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
|
|
|
|
|
22 |
|
23 |
# Split EntryName into base name and entry count
|
24 |
df['BaseName'] = df['EntryName'].str.replace(r'\s*\(\d+/\d+\)$', '', regex=True)
|