James McCool
commited on
Commit
·
3dcdcb7
1
Parent(s):
7d83d23
Enhance player matching process in find_name_mismatches function
Browse files- Improved the user interface for manual player matching by ensuring that all players needing manual matching are processed through a tabbed form layout.
- Streamlined the logic for applying both automatic and manual name matches, ensuring accurate updates to contest, ownership, and points data.
- Added success messages to confirm changes applied, enhancing user feedback during the matching process.
- Included a success message for cases where all players are automatically matched, improving user experience.
global_func/find_name_mismatches.py
CHANGED
|
@@ -43,58 +43,72 @@ def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df):
|
|
| 43 |
else:
|
| 44 |
players_to_process.append(player)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# Create a form for batch processing
|
| 49 |
-
with st.form("name_matching_form"):
|
| 50 |
-
# Create tabs for each player
|
| 51 |
-
tabs = st.tabs([f"Player {i+1}" for i in range(len(players_to_process))])
|
| 52 |
-
|
| 53 |
-
# Dictionary to store selections
|
| 54 |
-
selections = {}
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
selections[player] = st.radio(
|
| 69 |
-
f"Select correct match:",
|
| 70 |
-
options,
|
| 71 |
-
key=f"radio_{player}"
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
# Submit button for the entire form
|
| 75 |
-
submitted = st.form_submit_button("Apply All Changes")
|
| 76 |
-
|
| 77 |
-
if submitted:
|
| 78 |
-
# Process automatic matches
|
| 79 |
-
for projection_name, contest_name in auto_matches.items():
|
| 80 |
-
for col in name_columns:
|
| 81 |
-
contest_raw[col] = contest_raw[col].replace(contest_name, projection_name)
|
| 82 |
-
ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
|
| 83 |
-
fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
for
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
else:
|
| 44 |
players_to_process.append(player)
|
| 45 |
|
| 46 |
+
if players_to_process:
|
| 47 |
+
st.warning(f"Found {len(players_to_process)} players that need manual matching")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Create a form for batch processing
|
| 50 |
+
with st.form("name_matching_form"):
|
| 51 |
+
# Create tabs for each player
|
| 52 |
+
tabs = st.tabs([f"Player {i+1}" for i in range(len(players_to_process))])
|
| 53 |
+
|
| 54 |
+
# Dictionary to store selections
|
| 55 |
+
selections = {}
|
| 56 |
+
|
| 57 |
+
# Populate each tab
|
| 58 |
+
for i, player in enumerate(players_to_process):
|
| 59 |
+
with tabs[i]:
|
| 60 |
+
st.write(f"**Projection Name:** {player}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# Find the top 3 closest matches
|
| 63 |
+
closest_matches = process.extract(player, portfolio_players_list, limit=3)
|
| 64 |
+
|
| 65 |
+
# Create radio buttons for selection
|
| 66 |
+
options = [f"{match[0]} ({match[1]}%)" for match in closest_matches]
|
| 67 |
+
options.append("None of these")
|
| 68 |
+
|
| 69 |
+
selections[player] = st.radio(
|
| 70 |
+
f"Select correct match:",
|
| 71 |
+
options,
|
| 72 |
+
key=f"radio_{player}"
|
| 73 |
+
)
|
| 74 |
|
| 75 |
+
# Submit button for the entire form
|
| 76 |
+
submitted = st.form_submit_button("Apply All Changes")
|
| 77 |
|
| 78 |
+
if submitted:
|
| 79 |
+
# Process automatic matches
|
| 80 |
+
for projection_name, contest_name in auto_matches.items():
|
| 81 |
+
for col in name_columns:
|
| 82 |
+
contest_raw[col] = contest_raw[col].replace(contest_name, projection_name)
|
| 83 |
+
ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
|
| 84 |
+
fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
|
| 85 |
+
st.write(contest_name + ' ' + projection_name)
|
| 86 |
+
|
| 87 |
+
# Process manual selections
|
| 88 |
+
for projection_name, selection in selections.items():
|
| 89 |
+
if selection != "None of these":
|
| 90 |
+
selected_name = selection.split(" (")[0]
|
| 91 |
+
for col in name_columns:
|
| 92 |
+
contest_raw[col] = contest_raw[col].replace(selected_name, projection_name)
|
| 93 |
+
ownership_raw['Player'] = ownership_raw['Player'].replace(selected_name, projection_name)
|
| 94 |
+
fpts_raw['Player'] = fpts_raw['Player'].replace(selected_name, projection_name)
|
| 95 |
+
st.write(contest_name + ' ' + projection_name)
|
| 96 |
+
st.success(f"Replaced '{selected_name}' with '{projection_name}'")
|
| 97 |
+
|
| 98 |
+
ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
|
| 99 |
+
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
| 100 |
+
|
| 101 |
+
st.success("All changes applied successfully!")
|
| 102 |
+
return contest_raw, projections_raw, ownership_dict, fpts_dict
|
| 103 |
+
else:
|
| 104 |
+
st.success("All players have been automatically matched!")
|
| 105 |
+
# Apply automatic matches
|
| 106 |
+
for projection_name, contest_name in auto_matches.items():
|
| 107 |
+
for col in name_columns:
|
| 108 |
+
contest_raw[col] = contest_raw[col].replace(contest_name, projection_name)
|
| 109 |
+
ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
|
| 110 |
+
fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
|
| 111 |
+
st.write(contest_name + ' ' + projection_name)
|
| 112 |
+
ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
|
| 113 |
+
fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
|
| 114 |
+
return contest_raw, projections_raw, ownership_dict, fpts_dict
|