YFDashboard / src /ecr.py
JonSolow
Draft page (#19)
0ed8b3a unverified
import os
import pandas as pd
import streamlit as st
from streamlit_filter import filter_dataframe
def load_adp() -> pd.DataFrame:
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_fpecr_latest.csv")
df["ranking_type"] = df["fp_page"].apply(lambda x: os.path.split(x)[-1].replace(".php", ""))
return df
@st.cache_data(ttl=60 * 60 * 24)
def load_adp_data():
# Merge ADP
data = load_adp()
ranking_type_list = sorted(list(data.ranking_type.unique()))
return data, ranking_type_list
def filtered_ecr_dataframe(data: pd.DataFrame, ranking_type_list: list[str]):
default_ix = ranking_type_list.index("ppr-superflex-cheatsheets")
ranking_type_selected = st.selectbox("ECR Format:", ranking_type_list, index=default_ix)
ranking_type_filter = data["ranking_type"] == ranking_type_selected
is_advanced = st.checkbox("Show Advanced View")
id_cols = [
# "player_square_image_url",
"player",
"pos",
"team",
]
id_cols_advanced = [
"bye",
"player_owned_yahoo",
]
adp_cols: list[str] = [
"ecr",
]
adp_cols_advanced = ["sd", "best", "worst"]
if is_advanced:
show_columns = id_cols + id_cols_advanced + adp_cols + adp_cols_advanced
else:
show_columns = id_cols + adp_cols
data_filtered_by_ranking_type = data.loc[ranking_type_filter]
latest_scrape_date = data_filtered_by_ranking_type.scrape_date.max()
st.write(f"Scraped data as of: {latest_scrape_date}")
filtered_data = filter_dataframe(data.loc[ranking_type_filter, show_columns])
st.dataframe(
filtered_data,
hide_index=True,
height=35 * (len(filtered_data) + 1) + 12,
use_container_width=True,
column_config={
# "player_square_image_url": st.column_config.ImageColumn(label="", help="Player image"),
},
)
st.write("Source: https://github.com/dynastyprocess/data")