James McCool
commited on
Commit
·
14ac337
1
Parent(s):
b60e0d6
Enhance name matching logic in app.py: improve clarity of output messages by specifying the source of matches for both portfolio and projections, and update projections DataFrame in session state with matched names for better data consistency.
Browse files
app.py
CHANGED
@@ -155,8 +155,6 @@ with tab1:
|
|
155 |
# Initialize projections_df in session state if it doesn't exist
|
156 |
# Get unique names from portfolio
|
157 |
portfolio_names = get_portfolio_names(st.session_state['portfolio'])
|
158 |
-
|
159 |
-
# Get names from projections
|
160 |
csv_names = st.session_state['csv_file']['Name'].tolist()
|
161 |
projection_names = projections['player_names'].tolist()
|
162 |
|
@@ -172,7 +170,7 @@ with tab1:
|
|
172 |
if match:
|
173 |
portfolio_match_dict[portfolio_name] = match[0]
|
174 |
if match[1] < 100:
|
175 |
-
st.write(f"{portfolio_name} matched to site csv {match[0]} with a score of {match[1]}%")
|
176 |
else:
|
177 |
portfolio_match_dict[portfolio_name] = portfolio_name
|
178 |
unmatched_names.append(portfolio_name)
|
@@ -199,7 +197,31 @@ with tab1:
|
|
199 |
if match:
|
200 |
projections_match_dict[projections_name] = match[0]
|
201 |
if match[1] < 100:
|
202 |
-
st.write(f"{projections_name} matched to site csv {match[0]} with a score of {match[1]}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
else:
|
204 |
projections_match_dict[projections_name] = projections_name
|
205 |
unmatched_proj_names.append(projections_name)
|
|
|
155 |
# Initialize projections_df in session state if it doesn't exist
|
156 |
# Get unique names from portfolio
|
157 |
portfolio_names = get_portfolio_names(st.session_state['portfolio'])
|
|
|
|
|
158 |
csv_names = st.session_state['csv_file']['Name'].tolist()
|
159 |
projection_names = projections['player_names'].tolist()
|
160 |
|
|
|
170 |
if match:
|
171 |
portfolio_match_dict[portfolio_name] = match[0]
|
172 |
if match[1] < 100:
|
173 |
+
st.write(f"{portfolio_name} matched from portfolio to site csv {match[0]} with a score of {match[1]}%")
|
174 |
else:
|
175 |
portfolio_match_dict[portfolio_name] = portfolio_name
|
176 |
unmatched_names.append(portfolio_name)
|
|
|
197 |
if match:
|
198 |
projections_match_dict[projections_name] = match[0]
|
199 |
if match[1] < 100:
|
200 |
+
st.write(f"{projections_name} matched from projections to site csv {match[0]} with a score of {match[1]}%")
|
201 |
+
else:
|
202 |
+
projections_match_dict[projections_name] = projections_name
|
203 |
+
unmatched_proj_names.append(projections_name)
|
204 |
+
|
205 |
+
# Update projections with matched names
|
206 |
+
projections['player_names'] = projections['player_names'].map(lambda x: projections_match_dict.get(x, x))
|
207 |
+
st.session_state['projections_df'] = projections
|
208 |
+
|
209 |
+
projections_names = st.session_state['projections_df']['player_names'].tolist()
|
210 |
+
portfolio_names = get_portfolio_names(st.session_state['portfolio'])
|
211 |
+
|
212 |
+
# Create match dictionary for portfolio names to projection names
|
213 |
+
projections_match_dict = {}
|
214 |
+
unmatched_proj_names = []
|
215 |
+
for projections_name in projection_names:
|
216 |
+
match = process.extractOne(
|
217 |
+
projections_name,
|
218 |
+
portfolio_names,
|
219 |
+
score_cutoff=85
|
220 |
+
)
|
221 |
+
if match:
|
222 |
+
projections_match_dict[projections_name] = match[0]
|
223 |
+
if match[1] < 100:
|
224 |
+
st.write(f"{projections_name} matched from portfolio to projections {match[0]} with a score of {match[1]}%")
|
225 |
else:
|
226 |
projections_match_dict[projections_name] = projections_name
|
227 |
unmatched_proj_names.append(projections_name)
|