James McCool commited on
Commit
e253b51
·
1 Parent(s): e79a7d9

Enhance manual name matching process in find_name_mismatches function

Browse files

- Streamlined the user interface for manual player matching by implementing a tabbed form layout, allowing users to select from the top 3 closest name matches.
- Improved the logic for processing 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.

Files changed (1) hide show
  1. global_func/find_name_mismatches.py +52 -57
global_func/find_name_mismatches.py CHANGED
@@ -42,71 +42,66 @@ def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df):
42
  st.success(f"Automatically matched '{player}' with '{match_name}' ({closest_matches[0][1]}% match)")
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
-
84
- if contest_name in ownership_raw:
85
- ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
86
 
87
- if contest_name in fpts_raw:
88
- fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
89
-
90
- # Process manual selections
91
- for projection_name, selection in selections.items():
92
- if selection != "None of these":
93
- selected_name = selection.split(" (")[0]
94
- for col in name_columns:
95
- contest_raw[col] = contest_raw[col].replace(selected_name, projection_name)
96
-
97
- if contest_name in ownership_raw:
98
- ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
99
- if contest_name in fpts_raw:
100
- fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
101
 
102
- st.success(f"Replaced '{selected_name}' with '{projection_name}'")
103
-
104
- ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
105
- fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
106
-
107
- st.success("All changes applied successfully!")
108
 
109
- # Return the current state if form hasn't been submitted yet
110
  ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
111
  fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
 
 
112
  return contest_raw, projections_raw, ownership_dict, fpts_dict
 
42
  st.success(f"Automatically matched '{player}' with '{match_name}' ({closest_matches[0][1]}% match)")
43
  else:
44
  players_to_process.append(player)
45
+
46
+ st.warning(f"Found {len(players_to_process)} players that need manual matching")
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
+ # Populate each tab
57
+ for i, player in enumerate(players_to_process):
58
+ with tabs[i]:
59
+ st.write(f"**Projection Name:** {player}")
60
+
61
+ # Find the top 3 closest matches
62
+ closest_matches = process.extract(player, portfolio_players_list, limit=3)
63
+
64
+ # Create radio buttons for selection
65
+ options = [f"{match[0]} ({match[1]}%)" for match in closest_matches]
66
+ options.append("None of these")
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
 
83
+ if contest_name in ownership_raw:
84
+ ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
85
+
86
+ if contest_name in fpts_raw:
87
+ fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
 
 
 
 
 
 
88
 
89
+ # Process manual selections
90
+ for projection_name, selection in selections.items():
91
+ if selection != "None of these":
92
+ selected_name = selection.split(" (")[0]
 
 
 
 
 
 
 
 
93
  for col in name_columns:
94
+ contest_raw[col] = contest_raw[col].replace(selected_name, projection_name)
 
 
 
95
 
96
+ if contest_name in ownership_raw:
97
+ ownership_raw['Player'] = ownership_raw['Player'].replace(contest_name, projection_name)
98
+ if contest_name in fpts_raw:
99
+ fpts_raw['Player'] = fpts_raw['Player'].replace(contest_name, projection_name)
 
 
 
 
 
 
 
 
 
 
100
 
101
+ st.success(f"Replaced '{selected_name}' with '{projection_name}'")
 
 
 
 
 
102
 
 
103
  ownership_dict = dict(zip(ownership_raw['Player'], ownership_raw['Own']))
104
  fpts_dict = dict(zip(fpts_raw['Player'], fpts_raw['FPTS']))
105
+
106
+ st.success("All changes applied successfully!")
107
  return contest_raw, projections_raw, ownership_dict, fpts_dict