import datetime import streamlit as st from config import DEFAULT_ICON from shared_page import common_page_config from queries.footballguys.constants import YEAR from queries.nflverse.github_data import get_snap_counts @st.cache_data(ttl=60 * 60 * 24) def load_data(): data = get_snap_counts(YEAR) data = data[data.fantasy_position] teams_list = sorted(data.team.unique()) position_list = data.position.unique() weeks_list = sorted(data.week.unique()) data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p") return data, teams_list, position_list, weeks_list, data_load_time_str def get_page(): page_title = f"Snap Counts and Percentages - {YEAR}" st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide") common_page_config() st.title(page_title) if st.button("Refresh Data"): st.cache_data.clear() data, teams_list, position_list, weeks_list, data_load_time_str = load_data() st.write(f"Data loaded as of: {data_load_time_str} UTC") teams_selected = st.multiselect("Team:", teams_list, placeholder="Select a team to filter") or teams_list positions_selected = ( st.multiselect("Position:", position_list, placeholder="Select a position to filter") or position_list ) weeks_selected = st.multiselect("Week:", weeks_list, placeholder="Select a week to filter") or weeks_list with st.container(): filtered_data = data[ (data.team.isin(teams_selected) & data.position.isin(positions_selected) & data.week.isin(weeks_selected)) ] st.dataframe( filtered_data, hide_index=True, # height=35 * (len(filtered_data) + 1) + 12, use_container_width=False, column_order=[ "season", "game_type", "week", "player", "position", "team", "opponent", "offense_snaps", "offense_pct", "defense_snaps", "defense_pct", "st_snaps", "st_pct", ], column_config={ "season": st.column_config.TextColumn(help="Year of NFL Season"), }, ) if __name__ == "__main__": get_page()