import datetime import numpy as np import streamlit as st from config import DEFAULT_ICON from shared_page import common_page_config from queries.footballguys.constants import YEAR from queries.footballguys.refresh import request_stat from streamlit_filter import filter_dataframe @st.cache_data(ttl=60 * 60 * 24) def load_data(): stat_name = "redzone" data = request_stat(stat_name) data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p") return data, data_load_time_str def get_page(): page_title = f"Player Redzone Opportunities - {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, data_load_time_str = load_data() st.write(f"Data loaded as of: {data_load_time_str} UTC") selected_subtotals = st.selectbox("Show:", ["Player Totals", "Position Totals"], index=0) if selected_subtotals == "Player Totals": data = data[~data.name.str.contains(" Totals")] elif selected_subtotals == "Position Totals": data = data[data.name.str.contains(" Totals")] value_types = st.selectbox("Counts / Percent:", ["Counts", "Percent"], index=0) if value_types == "Percent": numerical_data = data.select_dtypes(include=np.number) numerical_cols = numerical_data.columns df_percent_values = numerical_data / data.groupby("TEAM").transform(sum).select_dtypes(include=np.number) data.loc[:, numerical_cols] = df_percent_values with st.container(): filtered_data = filter_dataframe(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()