James McCool
commited on
Commit
·
90735b6
1
Parent(s):
9693c27
Enhance name matching logic in app.py and find_name_mismatches.py
Browse files- Updated app.py to check for existing session state before executing name matching functions, preventing unnecessary reprocessing and improving performance.
- Streamlined the return logic in find_name_mismatches.py to ensure accurate data handling while maintaining clarity and readability in the code.
- app.py +5 -4
- global_func/find_name_mismatches.py +1 -18
app.py
CHANGED
@@ -72,10 +72,11 @@ with tab1:
|
|
72 |
st.dataframe(projections.head(10))
|
73 |
|
74 |
if Contest_file and projections_file:
|
75 |
-
if
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
79 |
|
80 |
with tab2:
|
81 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
|
|
72 |
st.dataframe(projections.head(10))
|
73 |
|
74 |
if Contest_file and projections_file:
|
75 |
+
if 'Contest' not in st.session_state and 'projections_df' not in st.session_state:
|
76 |
+
if contest_base is not None and projections is not None:
|
77 |
+
st.subheader("Name Matching functions")
|
78 |
+
st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'] = find_name_mismatches(contest_base, projections, ownership_df, fpts_df)
|
79 |
+
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
80 |
|
81 |
with tab2:
|
82 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
global_func/find_name_mismatches.py
CHANGED
@@ -105,25 +105,8 @@ def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df):
|
|
105 |
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
106 |
|
107 |
st.success("All changes applied successfully!")
|
108 |
-
return contest_raw, projections_raw, ownership_dict, fpts_dict
|
109 |
|
110 |
# Return the current state if form hasn't been submitted yet
|
111 |
ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
|
112 |
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
113 |
-
return contest_raw, projections_raw, ownership_dict, fpts_dict
|
114 |
-
else:
|
115 |
-
st.success("All players have been automatically matched!")
|
116 |
-
# Apply automatic matches
|
117 |
-
for projection_name, contest_name in auto_matches.items():
|
118 |
-
for col in name_columns:
|
119 |
-
contest_raw[col] = contest_raw[col].replace(contest_name, projection_name)
|
120 |
-
|
121 |
-
if contest_name in ownership_raw:
|
122 |
-
ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
|
123 |
-
if contest_name in fpts_raw:
|
124 |
-
fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
|
125 |
-
|
126 |
-
ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
|
127 |
-
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
128 |
-
|
129 |
-
return contest_raw, projections_raw, ownership_dict, fpts_dict
|
|
|
105 |
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
106 |
|
107 |
st.success("All changes applied successfully!")
|
|
|
108 |
|
109 |
# Return the current state if form hasn't been submitted yet
|
110 |
ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
|
111 |
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
112 |
+
return contest_raw, projections_raw, ownership_dict, fpts_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|