Spaces:
Sleeping
Sleeping
File size: 1,909 Bytes
91793e3 a3b2378 91793e3 7c958be 91793e3 2a3d770 91793e3 a3b2378 91793e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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 = "targets"
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 Targets - {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()
|