James McCool
commited on
Commit
·
ce6c2b2
1
Parent(s):
405e093
Refactor name matching and export dictionary handling in app.py: streamline the name-to-ID mapping process by ensuring it only occurs when necessary, and enhance match handling by fixing the conversion to match_dict, improving overall efficiency and user experience during exports.
Browse files
app.py
CHANGED
@@ -145,40 +145,42 @@ 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 |
-
# 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 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
st.write(st.session_state['export_dict'])
|
183 |
|
184 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|
|
|
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 |
+
if 'export_dict' not in st.session_state and csv_file is not None:
|
149 |
+
try:
|
150 |
+
name_id_map = dict(zip(
|
151 |
+
st.session_state['csv_file']['Name'],
|
152 |
+
st.session_state['csv_file']['Name + ID']
|
153 |
+
))
|
154 |
+
except:
|
155 |
+
name_id_map = dict(zip(
|
156 |
+
st.session_state['csv_file']['Nickname'],
|
157 |
+
st.session_state['csv_file']['Id']
|
158 |
+
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
+
# Get all names at once
|
161 |
+
names = projections['player_names'].tolist()
|
162 |
+
choices = list(name_id_map.keys())
|
163 |
+
|
164 |
+
# Process all names in one batch
|
165 |
+
matches = process.extract(
|
166 |
+
names,
|
167 |
+
choices,
|
168 |
+
scorer=fuzz.ratio,
|
169 |
+
score_cutoff=85,
|
170 |
+
limit=1 # Only get the best match
|
171 |
+
)
|
172 |
+
|
173 |
+
# Convert matches to dictionary - Fixed the match handling
|
174 |
+
match_dict = {}
|
175 |
+
for name, match_list in zip(names, matches):
|
176 |
+
if match_list and match_list[0][1] >= 85: # Check if we have a match and it meets threshold
|
177 |
+
match_dict[name] = name_id_map[match_list[0][0]] # Use the matched name to get the ID
|
178 |
+
else:
|
179 |
+
match_dict[name] = name # Keep original name if no good match
|
180 |
|
181 |
+
# Apply the matches
|
182 |
+
projections['upload_match'] = projections['player_names'].map(match_dict)
|
183 |
+
st.session_state['export_dict'] = match_dict # Use match_dict directly
|
184 |
st.write(st.session_state['export_dict'])
|
185 |
|
186 |
st.session_state['origin_portfolio'] = st.session_state['portfolio'].copy()
|