James McCool commited on
Commit
a404fe6
·
1 Parent(s): a7ffcd8

test conditionals manager combos

Browse files
Files changed (1) hide show
  1. app.py +152 -0
app.py CHANGED
@@ -2532,6 +2532,158 @@ if selected_tab == 'Manage Portfolio':
2532
  else: # Remove
2533
  parsed_frame = parsed_frame[~alpha_mask]
2534
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2535
  st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
2536
  st.session_state['export_merge'] = st.session_state['export_base'].copy()
2537
 
 
2532
  else: # Remove
2533
  parsed_frame = parsed_frame[~alpha_mask]
2534
 
2535
+ st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
2536
+ st.session_state['export_merge'] = st.session_state['export_base'].copy()
2537
+
2538
+ with st.expander('Conditionals Manager (combos)'):
2539
+ # a set of functions for replacing players in lineups containing specific other players
2540
+ with st.form(key='conditional_combos_form'):
2541
+ player_names = set()
2542
+ for col in st.session_state['working_frame'].columns:
2543
+ if col not in excluded_cols:
2544
+ player_names.update(st.session_state['working_frame'][col].unique())
2545
+
2546
+ replace_player = st.selectbox("Replace player:", options=sorted(list(player_names)), key='replace_player')
2547
+ replace_slot = st.selectbox("In slot:", options=['Overall', 'CPT', 'FLEX'], index=0, key='replace_slot')
2548
+ containing_player = st.selectbox("In Lineups containing:", options=sorted(list(player_names)), key='containing_player')
2549
+ containing_slot = st.selectbox("In slot:", options=['Overall', 'CPT', 'FLEX'], index=0, key='containing_slot')
2550
+
2551
+ specific_replacements_combo = st.multiselect("Specific replacements?", options=sorted(list(player_names)), default=[], key='specific_replacements_combo')
2552
+ specific_exclusions_combo = st.multiselect("Specific exclusions?", options=sorted(list(player_names)), default=[], key='specific_exclusions_combo')
2553
+
2554
+ comp_salary_below_combo = st.number_input("Comp Salary Below", value=-5000, min_value=-5000, max_value=0, step=100, key='comp_salary_below_combo')
2555
+ comp_salary_above_combo = st.number_input("Comp Salary Above", value=5000, min_value=0, max_value=5000, step=100, key='comp_salary_above_combo')
2556
+
2557
+ submitted_col, export_col = st.columns(2)
2558
+ st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
2559
+ with submitted_col:
2560
+ reg_submitted = st.form_submit_button("Portfolio")
2561
+ with export_col:
2562
+ exp_submitted = st.form_submit_button("Export")
2563
+
2564
+ if reg_submitted:
2565
+ st.session_state['settings_base'] = False
2566
+ parsed_frame = st.session_state['working_frame'].copy()
2567
+
2568
+ # Check if we have both replace and containing players selected
2569
+ if replace_player and containing_player and replace_player != containing_player:
2570
+ # Find rows that contain the containing_player in the specified slot
2571
+ containing_mask = pd.Series([False] * len(parsed_frame), index=parsed_frame.index)
2572
+
2573
+ if type_var == 'Showdown':
2574
+ if containing_slot == 'Overall':
2575
+ containing_mask = parsed_frame.apply(lambda row: containing_player in row.values, axis=1)
2576
+ elif containing_slot == 'CPT':
2577
+ containing_mask = parsed_frame.iloc[:, 0].apply(lambda row: containing_player in row)
2578
+ elif containing_slot == 'FLEX':
2579
+ containing_mask = parsed_frame.iloc[:, 1:].apply(lambda row: containing_player in row.values, axis=1)
2580
+ else:
2581
+ containing_mask = parsed_frame.apply(lambda row: containing_player in row.values, axis=1)
2582
+
2583
+ # Filter to only rows containing the target player
2584
+ target_rows = parsed_frame[containing_mask]
2585
+
2586
+ if not target_rows.empty:
2587
+ # Prepare DataFrame for exposure_spread to avoid categorical issues
2588
+ target_rows_prepared = prepare_dataframe_for_exposure_spread(target_rows, st.session_state['player_columns'])
2589
+
2590
+ # Use exposure_spread logic to replace the player in these specific rows
2591
+ # Set exposure_target to 0 to remove all instances of replace_player
2592
+ modified_rows = exposure_spread(
2593
+ target_rows_prepared,
2594
+ replace_player,
2595
+ 0, # exposure_target = 0 means remove all instances
2596
+ comp_salary_below_combo,
2597
+ comp_salary_above_combo,
2598
+ [], # ignore_stacks
2599
+ [], # remove_teams_exposure
2600
+ specific_replacements_combo,
2601
+ specific_exclusions_combo,
2602
+ st.session_state['player_columns'] if replace_slot == 'Overall' else
2603
+ ([st.session_state['player_columns'][0]] if replace_slot == 'CPT' else st.session_state['player_columns'][1:]),
2604
+ st.session_state['portfolio_inc_proj'],
2605
+ sport_var,
2606
+ type_var,
2607
+ salary_max,
2608
+ stacking_sports
2609
+ )
2610
+
2611
+ # Update the original dataframe with the modified rows
2612
+ parsed_frame.loc[containing_mask] = modified_rows
2613
+
2614
+ # Use consolidated calculation function
2615
+ parsed_frame = calculate_lineup_metrics(
2616
+ parsed_frame,
2617
+ st.session_state['player_columns'],
2618
+ st.session_state['map_dict'],
2619
+ type_var,
2620
+ sport_var,
2621
+ st.session_state['portfolio_inc_proj']
2622
+ )
2623
+
2624
+ st.session_state['working_frame'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
2625
+ st.session_state['export_merge'] = st.session_state['working_frame'].copy()
2626
+
2627
+ elif exp_submitted:
2628
+ st.session_state['settings_base'] = False
2629
+ parsed_frame = st.session_state['export_base'].copy()
2630
+
2631
+ # Check if we have both replace and containing players selected
2632
+ if replace_player and containing_player and replace_player != containing_player:
2633
+ # Find rows that contain the containing_player in the specified slot
2634
+ containing_mask = pd.Series([False] * len(parsed_frame), index=parsed_frame.index)
2635
+
2636
+ if type_var == 'Showdown':
2637
+ if containing_slot == 'Overall':
2638
+ containing_mask = parsed_frame.apply(lambda row: containing_player in row.values, axis=1)
2639
+ elif containing_slot == 'CPT':
2640
+ containing_mask = parsed_frame.iloc[:, 0].apply(lambda row: containing_player in row)
2641
+ elif containing_slot == 'FLEX':
2642
+ containing_mask = parsed_frame.iloc[:, 1:].apply(lambda row: containing_player in row.values, axis=1)
2643
+ else:
2644
+ containing_mask = parsed_frame.apply(lambda row: containing_player in row.values, axis=1)
2645
+
2646
+ # Filter to only rows containing the target player
2647
+ target_rows = parsed_frame[containing_mask]
2648
+
2649
+ if not target_rows.empty:
2650
+ # Prepare DataFrame for exposure_spread to avoid categorical issues
2651
+ target_rows_prepared = prepare_dataframe_for_exposure_spread(target_rows, st.session_state['player_columns'])
2652
+
2653
+ # Use exposure_spread logic to replace the player in these specific rows
2654
+ # Set exposure_target to 0 to remove all instances of replace_player
2655
+ modified_rows = exposure_spread(
2656
+ target_rows_prepared,
2657
+ replace_player,
2658
+ 0, # exposure_target = 0 means remove all instances
2659
+ comp_salary_below_combo,
2660
+ comp_salary_above_combo,
2661
+ [], # ignore_stacks
2662
+ [], # remove_teams_exposure
2663
+ specific_replacements_combo,
2664
+ specific_exclusions_combo,
2665
+ st.session_state['player_columns'] if replace_slot == 'Overall' else
2666
+ ([st.session_state['player_columns'][0]] if replace_slot == 'CPT' else st.session_state['player_columns'][1:]),
2667
+ st.session_state['portfolio_inc_proj'],
2668
+ sport_var,
2669
+ type_var,
2670
+ salary_max,
2671
+ stacking_sports
2672
+ )
2673
+
2674
+ # Update the original dataframe with the modified rows
2675
+ parsed_frame.loc[containing_mask] = modified_rows
2676
+
2677
+ # Use consolidated calculation function for export
2678
+ parsed_frame = calculate_lineup_metrics(
2679
+ parsed_frame,
2680
+ st.session_state['player_columns'],
2681
+ st.session_state['map_dict'],
2682
+ type_var,
2683
+ sport_var,
2684
+ st.session_state['portfolio_inc_proj']
2685
+ )
2686
+
2687
  st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
2688
  st.session_state['export_merge'] = st.session_state['export_base'].copy()
2689