import os import pandas as pd import streamlit as st from config import DEFAULT_ICON from shared_page import common_page_config from streamlit_filter import filter_dataframe KEEPER_DATA_URL = "../../tests/mocks/2023_keepers.csv" HEADSHOT_DATA_URL = "../../tests/mocks/2023_player_headshots.csv" 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_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") def get_keeper_app(): keeper_title = "Expert Consensus Rankings" st.set_page_config(page_title=keeper_title, page_icon=DEFAULT_ICON, layout="wide") common_page_config() st.title(keeper_title) data, ecr_type_list = load_data() with st.container(): filtered_ecr_dataframe(data, ecr_type_list) if __name__ == "__main__": get_keeper_app()