James McCool commited on
Commit
39b94b7
·
1 Parent(s): 73d06c0

Refactor position and team filtering logic to improve accuracy and clarity. Introduced regex for position matching and combined masks for filtering, enhancing user experience in portfolio management.

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -1044,7 +1044,21 @@ def parse_portfolio_on_mapped(portfolio, map_dict, map_key, filter_keys_pos, fil
1044
  mask = low_mask & high_mask
1045
  else:
1046
  # String mapping - filter by inclusion in filter_keys
1047
- mask = mapping_port.str.contains(filter_keys_pos) | mapping_port.isin(filter_keys_team)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1048
 
1049
  return portfolio[mask]
1050
 
 
1044
  mask = low_mask & high_mask
1045
  else:
1046
  # String mapping - filter by inclusion in filter_keys
1047
+ pos_mask = False
1048
+ team_mask = False
1049
+
1050
+ # Handle position filtering (for multi-position players like PG/SG)
1051
+ if filter_keys_pos:
1052
+ # Create a regex pattern that matches any of the selected positions
1053
+ pos_pattern = '|'.join([f'\\b{pos}\\b' for pos in filter_keys_pos])
1054
+ pos_mask = mapping_port.str.contains(pos_pattern, case=False, na=False, regex=True)
1055
+
1056
+ # Handle team filtering
1057
+ if filter_keys_team:
1058
+ team_mask = mapping_port.isin(filter_keys_team)
1059
+
1060
+ # Combine masks with OR logic
1061
+ mask = pos_mask | team_mask
1062
 
1063
  return portfolio[mask]
1064