James McCool
commited on
Commit
·
2e7d951
1
Parent(s):
1504942
Refactor export matching logic in app.py: move the name-to-ID mapping and best match application to a dedicated button, improving user interaction and streamlining the export process while removing redundant debug messages.
Browse files
app.py
CHANGED
@@ -144,35 +144,9 @@ with tab1:
|
|
144 |
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
145 |
|
146 |
# Update projections_df with any new matches
|
147 |
-
st.write('starting name matching')
|
148 |
st.session_state['projections_df'] = find_name_mismatches(st.session_state['portfolio'], st.session_state['projections_df'])
|
149 |
-
if csv_file is not None and 'export_dict' not in st.session_state:
|
150 |
-
if st.button('Prepare export matching'):
|
151 |
-
# Create a dictionary of Name to Name+ID from csv_file
|
152 |
-
try:
|
153 |
-
name_id_map = dict(zip(
|
154 |
-
st.session_state['csv_file']['Name'],
|
155 |
-
st.session_state['csv_file']['Name + ID']
|
156 |
-
))
|
157 |
-
except:
|
158 |
-
name_id_map = dict(zip(
|
159 |
-
st.session_state['csv_file']['Nickname'],
|
160 |
-
st.session_state['csv_file']['Id']
|
161 |
-
))
|
162 |
-
|
163 |
-
# Function to find best match
|
164 |
-
def find_best_match(name):
|
165 |
-
best_match = process.extractOne(name, name_id_map.keys())
|
166 |
-
if best_match and best_match[1] >= 85: # 85% match threshold
|
167 |
-
return name_id_map[best_match[0]]
|
168 |
-
return name # Return original name if no good match found
|
169 |
-
|
170 |
-
# Apply the matching
|
171 |
-
projections['upload_match'] = projections['player_names'].apply(find_best_match)
|
172 |
-
st.session_state['export_dict'] = dict(zip(projections['player_names'], projections['upload_match']))
|
173 |
|
174 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|
175 |
-
st.write('name matching complete')
|
176 |
|
177 |
# with tab2:
|
178 |
# if st.button('Clear data', key='reset2'):
|
@@ -881,6 +855,30 @@ with tab2:
|
|
881 |
)
|
882 |
st.session_state['portfolio'] = st.session_state['portfolio'][lock_mask]
|
883 |
st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
884 |
with st.expander("Download options"):
|
885 |
if stack_dict is not None:
|
886 |
download_type = st.selectbox("Simple or Advanced Download?", options=['Simple', 'Advanced'], key='download_choice')
|
|
|
144 |
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
145 |
|
146 |
# Update projections_df with any new matches
|
|
|
147 |
st.session_state['projections_df'] = find_name_mismatches(st.session_state['portfolio'], st.session_state['projections_df'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|
|
|
150 |
|
151 |
# with tab2:
|
152 |
# if st.button('Clear data', key='reset2'):
|
|
|
855 |
)
|
856 |
st.session_state['portfolio'] = st.session_state['portfolio'][lock_mask]
|
857 |
st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
|
858 |
+
if st.button('Prepare exports'):
|
859 |
+
# Create a dictionary of Name to Name+ID from csv_file
|
860 |
+
try:
|
861 |
+
name_id_map = dict(zip(
|
862 |
+
st.session_state['csv_file']['Name'],
|
863 |
+
st.session_state['csv_file']['Name + ID']
|
864 |
+
))
|
865 |
+
except:
|
866 |
+
name_id_map = dict(zip(
|
867 |
+
st.session_state['csv_file']['Nickname'],
|
868 |
+
st.session_state['csv_file']['Id']
|
869 |
+
))
|
870 |
+
|
871 |
+
# Function to find best match
|
872 |
+
def find_best_match(name):
|
873 |
+
best_match = process.extractOne(name, name_id_map.keys())
|
874 |
+
if best_match and best_match[1] >= 85: # 85% match threshold
|
875 |
+
return name_id_map[best_match[0]]
|
876 |
+
return name # Return original name if no good match found
|
877 |
+
|
878 |
+
# Apply the matching
|
879 |
+
projections['upload_match'] = projections['player_names'].apply(find_best_match)
|
880 |
+
st.session_state['export_dict'] = dict(zip(projections['player_names'], projections['upload_match']))
|
881 |
+
st.info('Click the above option after you have set up your portfolio if you want to export it as a set ready to upload to DFS sites')
|
882 |
with st.expander("Download options"):
|
883 |
if stack_dict is not None:
|
884 |
download_type = st.selectbox("Simple or Advanced Download?", options=['Simple', 'Advanced'], key='download_choice')
|