Jon Solow
		
	commited on
		
		
					Commit 
							
							·
						
						f625376
	
1
								Parent(s):
							
							050fd9f
								
Add a filter for nfl teams for player selection
Browse files- src/pages/10_Set_Your_Lineup.py +22 -12
    	
        src/pages/10_Set_Your_Lineup.py
    CHANGED
    
    | @@ -39,11 +39,18 @@ def format_player_option(player_opt: PlayerOption) -> str: | |
| 39 |  | 
| 40 |  | 
| 41 | 
             
            def position_cell(
         | 
| 42 | 
            -
                week: str, | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 43 | 
             
            ):
         | 
| 44 | 
             
                pos_label = f"{week}-{pos_str}-{pos_idx}"
         | 
| 45 | 
             
                selected_id = existing_selection_map.get(pos_label)
         | 
| 46 | 
             
                options_list = options_map[pos_str][int(week)]
         | 
|  | |
|  | |
| 47 | 
             
                non_locked_options = [x for x in options_list if not x.is_locked()]
         | 
| 48 | 
             
                disabled = False
         | 
| 49 | 
             
                # get selected player by id from options
         | 
| @@ -100,25 +107,25 @@ def update_and_save_selection(pos_label: str, selection_id: str): | |
| 100 | 
             
                st.rerun()
         | 
| 101 |  | 
| 102 |  | 
| 103 | 
            -
            def week_selections(week, player_options, existing_selections):
         | 
| 104 | 
             
                selection_cols = st.columns(8)
         | 
| 105 |  | 
| 106 | 
             
                with selection_cols[0]:
         | 
| 107 | 
            -
                    position_cell(week, "QB", 1, player_options, existing_selections)
         | 
| 108 | 
             
                with selection_cols[1]:
         | 
| 109 | 
            -
                    position_cell(week, "RB", 1, player_options, existing_selections)
         | 
| 110 | 
             
                with selection_cols[2]:
         | 
| 111 | 
            -
                    position_cell(week, "RB", 2, player_options, existing_selections)
         | 
| 112 | 
             
                with selection_cols[3]:
         | 
| 113 | 
            -
                    position_cell(week, "WR", 1, player_options, existing_selections)
         | 
| 114 | 
             
                with selection_cols[4]:
         | 
| 115 | 
            -
                    position_cell(week, "WR", 2, player_options, existing_selections)
         | 
| 116 | 
             
                with selection_cols[5]:
         | 
| 117 | 
            -
                    position_cell(week, "TE", 1, player_options, existing_selections)
         | 
| 118 | 
             
                with selection_cols[6]:
         | 
| 119 | 
            -
                    position_cell(week, "K", 1, player_options, existing_selections)
         | 
| 120 | 
             
                with selection_cols[7]:
         | 
| 121 | 
            -
                    position_cell(week, "DEF", 1, player_options, existing_selections)
         | 
| 122 |  | 
| 123 |  | 
| 124 | 
             
            def get_page():
         | 
| @@ -146,15 +153,18 @@ def get_page(): | |
| 146 | 
             
                    st.stop()
         | 
| 147 |  | 
| 148 | 
             
                player_options = load_options()
         | 
|  | |
|  | |
|  | |
| 149 |  | 
| 150 | 
             
                for week in range(1, 5):
         | 
| 151 | 
             
                    existing_week_selections = {k: v for k, v in existing_selections.items() if k[0] == str(week)}
         | 
| 152 | 
             
                    st.header(PLAYOFF_WEEK_TO_NAME[week])
         | 
| 153 | 
             
                    if week < CURRENT_PLAYOFF_WEEK:
         | 
| 154 | 
             
                        with st.expander("Show Previous Week"):
         | 
| 155 | 
            -
                            week_selections(week, player_options, existing_week_selections)
         | 
| 156 | 
             
                    else:
         | 
| 157 | 
            -
                        week_selections(week, player_options, existing_week_selections)
         | 
| 158 |  | 
| 159 | 
             
                set_selectbox_readonly()
         | 
| 160 |  | 
|  | |
| 39 |  | 
| 40 |  | 
| 41 | 
             
            def position_cell(
         | 
| 42 | 
            +
                week: str,
         | 
| 43 | 
            +
                pos_str: str,
         | 
| 44 | 
            +
                pos_idx: int,
         | 
| 45 | 
            +
                options_map: dict[str, dict[int, list[PlayerOption]]],
         | 
| 46 | 
            +
                existing_selection_map,
         | 
| 47 | 
            +
                team_filter: list[str],
         | 
| 48 | 
             
            ):
         | 
| 49 | 
             
                pos_label = f"{week}-{pos_str}-{pos_idx}"
         | 
| 50 | 
             
                selected_id = existing_selection_map.get(pos_label)
         | 
| 51 | 
             
                options_list = options_map[pos_str][int(week)]
         | 
| 52 | 
            +
                if team_filter:
         | 
| 53 | 
            +
                    options_list = [x for x in options_list if x.team in team_filter or str(selected_id) == str(x.gsis_id)]
         | 
| 54 | 
             
                non_locked_options = [x for x in options_list if not x.is_locked()]
         | 
| 55 | 
             
                disabled = False
         | 
| 56 | 
             
                # get selected player by id from options
         | 
|  | |
| 107 | 
             
                st.rerun()
         | 
| 108 |  | 
| 109 |  | 
| 110 | 
            +
            def week_selections(week, player_options, existing_selections, team_filter: list[str]):
         | 
| 111 | 
             
                selection_cols = st.columns(8)
         | 
| 112 |  | 
| 113 | 
             
                with selection_cols[0]:
         | 
| 114 | 
            +
                    position_cell(week, "QB", 1, player_options, existing_selections, team_filter)
         | 
| 115 | 
             
                with selection_cols[1]:
         | 
| 116 | 
            +
                    position_cell(week, "RB", 1, player_options, existing_selections, team_filter)
         | 
| 117 | 
             
                with selection_cols[2]:
         | 
| 118 | 
            +
                    position_cell(week, "RB", 2, player_options, existing_selections, team_filter)
         | 
| 119 | 
             
                with selection_cols[3]:
         | 
| 120 | 
            +
                    position_cell(week, "WR", 1, player_options, existing_selections, team_filter)
         | 
| 121 | 
             
                with selection_cols[4]:
         | 
| 122 | 
            +
                    position_cell(week, "WR", 2, player_options, existing_selections, team_filter)
         | 
| 123 | 
             
                with selection_cols[5]:
         | 
| 124 | 
            +
                    position_cell(week, "TE", 1, player_options, existing_selections, team_filter)
         | 
| 125 | 
             
                with selection_cols[6]:
         | 
| 126 | 
            +
                    position_cell(week, "K", 1, player_options, existing_selections, team_filter)
         | 
| 127 | 
             
                with selection_cols[7]:
         | 
| 128 | 
            +
                    position_cell(week, "DEF", 1, player_options, existing_selections, team_filter)
         | 
| 129 |  | 
| 130 |  | 
| 131 | 
             
            def get_page():
         | 
|  | |
| 153 | 
             
                    st.stop()
         | 
| 154 |  | 
| 155 | 
             
                player_options = load_options()
         | 
| 156 | 
            +
                # TODO - make more robust than just picking week 1 defenses but should work for now
         | 
| 157 | 
            +
                team_options_for_filter = sorted([x.team for x in player_options["DEF"][1]])
         | 
| 158 | 
            +
                team_filter = st.multiselect("Filter for NFL teams", team_options_for_filter)
         | 
| 159 |  | 
| 160 | 
             
                for week in range(1, 5):
         | 
| 161 | 
             
                    existing_week_selections = {k: v for k, v in existing_selections.items() if k[0] == str(week)}
         | 
| 162 | 
             
                    st.header(PLAYOFF_WEEK_TO_NAME[week])
         | 
| 163 | 
             
                    if week < CURRENT_PLAYOFF_WEEK:
         | 
| 164 | 
             
                        with st.expander("Show Previous Week"):
         | 
| 165 | 
            +
                            week_selections(week, player_options, existing_week_selections, team_filter)
         | 
| 166 | 
             
                    else:
         | 
| 167 | 
            +
                        week_selections(week, player_options, existing_week_selections, team_filter)
         | 
| 168 |  | 
| 169 | 
             
                set_selectbox_readonly()
         | 
| 170 |  |