James McCool commited on
Commit
7ac9771
·
1 Parent(s): fa47128

Enhance player and team filtering logic in 'app.py' for Showdown mode by implementing CPT/FLEX/Overall focus handling, improving clarity and consistency while maintaining performance.

Browse files
Files changed (1) hide show
  1. app.py +98 -26
app.py CHANGED
@@ -1395,41 +1395,113 @@ if selected_tab == 'Manage Portfolio':
1395
  st.session_state['settings_base'] = False
1396
  parsed_frame = st.session_state['export_base'].copy()
1397
  if player_remove:
1398
- # Create mask for lineups that contain any of the removed players
1399
- remove_mask = parsed_frame[st.session_state['player_columns']].apply(
1400
- lambda row: not any(player in list(row) for player in player_remove), axis=1
1401
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
1402
  parsed_frame = parsed_frame[remove_mask]
1403
 
1404
  if player_lock:
1405
-
1406
- lock_mask = parsed_frame[st.session_state['player_columns']].apply(
1407
- lambda row: all(player in list(row) for player in player_lock), axis=1
1408
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
1409
  parsed_frame = parsed_frame[lock_mask]
1410
 
1411
  if team_include:
1412
- # Create a copy of the frame with player names replaced by teams, excluding SP1 and SP2
1413
- filtered_player_columns = [col for col in st.session_state['player_columns'] if col not in ['SP1', 'SP2']]
1414
- team_frame = parsed_frame[filtered_player_columns].apply(
1415
- lambda x: x.map(st.session_state['map_dict']['team_map'])
1416
- )
1417
- # Create mask for lineups that contain any of the included teams
1418
- include_mask = team_frame.apply(
1419
- lambda row: any(team in list(row) for team in team_include), axis=1
1420
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1421
  parsed_frame = parsed_frame[include_mask]
1422
 
1423
  if team_remove:
1424
- # Create a copy of the frame with player names replaced by teams, excluding SP1 and SP2
1425
- filtered_player_columns = [col for col in st.session_state['player_columns'] if col not in ['SP1', 'SP2']]
1426
- team_frame = parsed_frame[filtered_player_columns].apply(
1427
- lambda x: x.map(st.session_state['map_dict']['team_map'])
1428
- )
1429
- # Create mask for lineups that don't contain any of the removed teams
1430
- remove_mask = team_frame.apply(
1431
- lambda row: not any(team in list(row) for team in team_remove), axis=1
1432
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1433
  parsed_frame = parsed_frame[remove_mask]
1434
 
1435
  if size_include:
 
1395
  st.session_state['settings_base'] = False
1396
  parsed_frame = st.session_state['export_base'].copy()
1397
  if player_remove:
1398
+ if type_var == 'Showdown':
1399
+ if cpt_flex_focus == 'CPT':
1400
+ remove_mask = parsed_frame.iloc[:, 0].apply(
1401
+ lambda player: not any(remove_player in str(player) for remove_player in player_remove)
1402
+ )
1403
+ elif cpt_flex_focus == 'FLEX':
1404
+ remove_mask = parsed_frame.iloc[:, 1:].apply(
1405
+ lambda row: not any(player in list(row) for player in player_remove), axis=1
1406
+ )
1407
+ elif cpt_flex_focus == 'Overall':
1408
+ remove_mask = parsed_frame[st.session_state['player_columns']].apply(
1409
+ lambda row: not any(player in list(row) for player in player_remove), axis=1
1410
+ )
1411
+ else:
1412
+ remove_mask = parsed_frame[st.session_state['player_columns']].apply(
1413
+ lambda row: not any(player in list(row) for player in player_remove), axis=1
1414
+ )
1415
  parsed_frame = parsed_frame[remove_mask]
1416
 
1417
  if player_lock:
1418
+ if type_var == 'Showdown':
1419
+ if cpt_flex_focus == 'CPT':
1420
+ lock_mask = parsed_frame.iloc[:, 0].apply(
1421
+ lambda player: any(lock_player in str(player) for lock_player in player_lock)
1422
+ )
1423
+ elif cpt_flex_focus == 'FLEX':
1424
+ lock_mask = parsed_frame.iloc[:, 1:].apply(
1425
+ lambda row: all(player in list(row) for player in player_lock), axis=1
1426
+ )
1427
+ elif cpt_flex_focus == 'Overall':
1428
+ lock_mask = parsed_frame[st.session_state['player_columns']].apply(
1429
+ lambda row: all(player in list(row) for player in player_lock), axis=1
1430
+ )
1431
+ else:
1432
+ lock_mask = parsed_frame[st.session_state['player_columns']].apply(
1433
+ lambda row: all(player in list(row) for player in player_lock), axis=1
1434
+ )
1435
  parsed_frame = parsed_frame[lock_mask]
1436
 
1437
  if team_include:
1438
+ if type_var == 'Showdown':
1439
+ if cpt_flex_focus == 'CPT':
1440
+ team_frame = parsed_frame.iloc[:, 0].apply(
1441
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1442
+ )
1443
+ include_mask = team_frame.apply(
1444
+ lambda row: any(team in list(row) for team in team_include), axis=1
1445
+ )
1446
+ elif cpt_flex_focus == 'FLEX':
1447
+ team_frame = parsed_frame.iloc[:, 1:].apply(
1448
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1449
+ )
1450
+ include_mask = team_frame.apply(
1451
+ lambda row: any(team in list(row) for team in team_include), axis=1
1452
+ )
1453
+ elif cpt_flex_focus == 'Overall':
1454
+ team_frame = parsed_frame[st.session_state['player_columns']].apply(
1455
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1456
+ )
1457
+ include_mask = team_frame.apply(
1458
+ lambda row: any(team in list(row) for team in team_include), axis=1
1459
+ )
1460
+ else:
1461
+ # Create a copy of the frame with player names replaced by teams, excluding SP1 and SP2
1462
+ filtered_player_columns = [col for col in st.session_state['player_columns'] if col not in ['SP1', 'SP2']]
1463
+ team_frame = parsed_frame[filtered_player_columns].apply(
1464
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1465
+ )
1466
+ # Create mask for lineups that contain any of the included teams
1467
+ include_mask = team_frame.apply(
1468
+ lambda row: any(team in list(row) for team in team_include), axis=1
1469
+ )
1470
  parsed_frame = parsed_frame[include_mask]
1471
 
1472
  if team_remove:
1473
+ if type_var == 'Showdown':
1474
+ if cpt_flex_focus == 'CPT':
1475
+ team_frame = parsed_frame.iloc[:, 0].apply(
1476
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1477
+ )
1478
+ remove_mask = team_frame.apply(
1479
+ lambda row: not any(team in list(row) for team in team_remove), axis=1
1480
+ )
1481
+ elif cpt_flex_focus == 'FLEX':
1482
+ team_frame = parsed_frame.iloc[:, 1:].apply(
1483
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1484
+ )
1485
+ remove_mask = team_frame.apply(
1486
+ lambda row: not any(team in list(row) for team in team_remove), axis=1
1487
+ )
1488
+ elif cpt_flex_focus == 'Overall':
1489
+ team_frame = parsed_frame[st.session_state['player_columns']].apply(
1490
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1491
+ )
1492
+ remove_mask = team_frame.apply(
1493
+ lambda row: not any(team in list(row) for team in team_remove), axis=1
1494
+ )
1495
+ else:
1496
+ # Create a copy of the frame with player names replaced by teams, excluding SP1 and SP2
1497
+ filtered_player_columns = [col for col in st.session_state['player_columns'] if col not in ['SP1', 'SP2']]
1498
+ team_frame = parsed_frame[filtered_player_columns].apply(
1499
+ lambda x: x.map(st.session_state['map_dict']['team_map'])
1500
+ )
1501
+ # Create mask for lineups that don't contain any of the removed teams
1502
+ remove_mask = team_frame.apply(
1503
+ lambda row: not any(team in list(row) for team in team_remove), axis=1
1504
+ )
1505
  parsed_frame = parsed_frame[remove_mask]
1506
 
1507
  if size_include: