James McCool
commited on
Commit
·
d61cf96
1
Parent(s):
1c93e3f
Refactor name-to-ID mapping and matching logic in app.py: streamline the process by consolidating the mapping and matching steps, improving efficiency and maintaining user experience during exports.
Browse files
app.py
CHANGED
|
@@ -145,39 +145,38 @@ with tab1:
|
|
| 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 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
)
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|
| 182 |
|
| 183 |
# with tab2:
|
|
|
|
| 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 |
+
try:
|
| 149 |
+
name_id_map = dict(zip(
|
| 150 |
+
st.session_state['csv_file']['Name'],
|
| 151 |
+
st.session_state['csv_file']['Name + ID']
|
| 152 |
+
))
|
| 153 |
+
except:
|
| 154 |
+
name_id_map = dict(zip(
|
| 155 |
+
st.session_state['csv_file']['Nickname'],
|
| 156 |
+
st.session_state['csv_file']['Id']
|
| 157 |
+
))
|
| 158 |
+
|
| 159 |
+
# Get all names at once
|
| 160 |
+
names = projections['player_names'].tolist()
|
| 161 |
+
choices = list(name_id_map.keys())
|
| 162 |
+
|
| 163 |
+
# Process all names in one batch
|
| 164 |
+
matches = process.extract(
|
| 165 |
+
names,
|
| 166 |
+
choices,
|
| 167 |
+
scorer=fuzz.ratio,
|
| 168 |
+
score_cutoff=85,
|
| 169 |
+
limit=1 # Only get the best match
|
| 170 |
+
)
|
|
|
|
| 171 |
|
| 172 |
+
# Convert matches to dictionary
|
| 173 |
+
match_dict = {name: name_id_map[match[0][0]] if match else name
|
| 174 |
+
for name, match in zip(names, matches)}
|
| 175 |
|
| 176 |
+
# Apply the matches
|
| 177 |
+
projections['upload_match'] = projections['player_names'].map(match_dict)
|
| 178 |
+
st.session_state['export_dict'] = dict(zip(projections['player_names'], projections['upload_match']))
|
| 179 |
+
|
| 180 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|
| 181 |
|
| 182 |
# with tab2:
|