James McCool
commited on
Commit
·
2c1be4a
1
Parent(s):
3909ec7
Refactor name matching logic in `find_name_mismatches.py` to improve data handling
Browse files- Updated the function to return both `contest_df` and `projections_df` for better data management.
- Enhanced name matching by ensuring all occurrences in `contest_df` are updated when a match is found.
- Improved user feedback messages to clarify the matching process and outcomes.
global_func/find_name_mismatches.py
CHANGED
@@ -7,12 +7,13 @@ from fuzzywuzzy import process
|
|
7 |
def find_name_mismatches(contest_df, projections_df):
|
8 |
# Create a copy of the projections dataframe to avoid modifying the original
|
9 |
projections_df = projections_df.copy()
|
|
|
10 |
|
11 |
name_columns = [col for col in contest_df.columns if not col in ['BaseName', 'EntryCount']]
|
12 |
|
13 |
if 'player_names' not in projections_df.columns:
|
14 |
st.error("No 'player_names' column found in projections file")
|
15 |
-
return projections_df
|
16 |
|
17 |
# Get unique player names from portfolio and projections
|
18 |
portfolio_players = set()
|
@@ -33,8 +34,10 @@ def find_name_mismatches(contest_df, projections_df):
|
|
33 |
closest_matches = process.extract(player, projection_players_list, limit=1)
|
34 |
if closest_matches[0][1] == 100: # If perfect match found
|
35 |
match_name = closest_matches[0][0]
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
else:
|
39 |
players_to_process.append(player)
|
40 |
|
@@ -73,9 +76,11 @@ def find_name_mismatches(contest_df, projections_df):
|
|
73 |
if st.button("Confirm Selection"):
|
74 |
if selected_option != "None of these":
|
75 |
selected_name = selected_option.split(" (")[0]
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
80 |
# Move to next player
|
81 |
st.session_state.current_player_index += 1
|
@@ -88,4 +93,4 @@ def find_name_mismatches(contest_df, projections_df):
|
|
88 |
else:
|
89 |
st.success("All portfolio players found in projections!")
|
90 |
|
91 |
-
return projections_df
|
|
|
7 |
def find_name_mismatches(contest_df, projections_df):
|
8 |
# Create a copy of the projections dataframe to avoid modifying the original
|
9 |
projections_df = projections_df.copy()
|
10 |
+
contest_df = contest_df.copy()
|
11 |
|
12 |
name_columns = [col for col in contest_df.columns if not col in ['BaseName', 'EntryCount']]
|
13 |
|
14 |
if 'player_names' not in projections_df.columns:
|
15 |
st.error("No 'player_names' column found in projections file")
|
16 |
+
return contest_df, projections_df
|
17 |
|
18 |
# Get unique player names from portfolio and projections
|
19 |
portfolio_players = set()
|
|
|
34 |
closest_matches = process.extract(player, projection_players_list, limit=1)
|
35 |
if closest_matches[0][1] == 100: # If perfect match found
|
36 |
match_name = closest_matches[0][0]
|
37 |
+
# Update all occurrences in contest_df
|
38 |
+
for col in name_columns:
|
39 |
+
contest_df[col] = contest_df[col].replace(player, match_name)
|
40 |
+
st.success(f"Automatically matched '{player}' with '{match_name}' (100% match)")
|
41 |
else:
|
42 |
players_to_process.append(player)
|
43 |
|
|
|
76 |
if st.button("Confirm Selection"):
|
77 |
if selected_option != "None of these":
|
78 |
selected_name = selected_option.split(" (")[0]
|
79 |
+
# Update all occurrences in contest_df
|
80 |
+
for col in name_columns:
|
81 |
+
contest_df[col] = contest_df[col].replace(current_player, selected_name)
|
82 |
+
st.success(f"Replaced '{current_player}' with '{selected_name}'")
|
83 |
+
st.session_state['contest_df'] = contest_df
|
84 |
|
85 |
# Move to next player
|
86 |
st.session_state.current_player_index += 1
|
|
|
93 |
else:
|
94 |
st.success("All portfolio players found in projections!")
|
95 |
|
96 |
+
return contest_df, projections_df
|