YFDashboard / src /pages /11_Next_Gen_Stats.py
Jon Solow
Apply formatting
243b60e
raw
history blame
2.22 kB
import streamlit as st
from config import DEFAULT_ICON
from shared_page import common_page_config
from streamlit_filter import get_multiselect_for_df_column
from queries.nflverse.github_data import get_nextgen_stats, get_current_tables, SEASON
hide_columns = [
"season",
"season_type",
"player_gsis_id",
"player_first_name",
"player_last_name",
"player_jersey_number",
"player_short_name",
]
def get_page():
page_title = f"Next Gen Stats - {SEASON}"
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
common_page_config()
st.title(page_title)
stat_category = st.selectbox("Stat Category", ["Passing", "Rushing", "Receiving"])
ngs_table_name = f"nextgen_stats_ngs_{stat_category.lower()}"
current_tables_list = get_current_tables()
if ngs_table_name not in current_tables_list:
st.write("Data not loaded.")
st.write("Check loaded data [here](./Load_Data)")
return
data = get_nextgen_stats(SEASON, stat_category)
season_or_week = st.selectbox("Season or Weekly Stats", ["Season", "Week"])
if season_or_week == "Season":
data = data[data["week"] == 0]
data.drop(columns=["week"], inplace=True)
else:
data = data[data["week"] > 0]
week_selection = st.slider(
"Filter Week Range:",
min_value=data["week"].min(),
max_value=data["week"].max(),
value=(data["week"].min(), data["week"].max()),
step=1,
)
data = data[data["week"].between(*week_selection)]
data.drop(columns=hide_columns, inplace=True)
positions_selected = get_multiselect_for_df_column(data, "player_position")
teams_selected = get_multiselect_for_df_column(data, "team_abbr")
data = data[(data["player_position"].isin(positions_selected) & data["team_abbr"].isin(teams_selected))]
with st.container():
filtered_data = data
st.dataframe(
filtered_data,
hide_index=True,
# height=35 * (len(filtered_data) + 1) + 12,
use_container_width=False,
column_config={},
)
if __name__ == "__main__":
get_page()