James McCool
commited on
Commit
·
1504942
1
Parent(s):
1501d6f
Implement button for export matching in app.py: add a button to initiate the creation of a name-to-ID mapping and apply best match logic, enhancing user interaction and functionality during the export process.
Browse files
app.py
CHANGED
@@ -147,28 +147,29 @@ with tab1:
|
|
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 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
172 |
|
173 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|
174 |
st.write('name matching complete')
|
|
|
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')
|