Spaces:
Sleeping
Sleeping
Jon Solow
commited on
Commit
·
051e12d
1
Parent(s):
1749eaf
Add ECR page
Browse files- src/pages/3_ECR.py +86 -0
src/pages/3_ECR.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pandas as pd
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
from config import DEFAULT_ICON
|
6 |
+
from login_component import get_authorization_button
|
7 |
+
from streamlit_filter import filter_dataframe
|
8 |
+
|
9 |
+
|
10 |
+
KEEPER_DATA_URL = "../../tests/mocks/2023_keepers.csv"
|
11 |
+
HEADSHOT_DATA_URL = "../../tests/mocks/2023_player_headshots.csv"
|
12 |
+
|
13 |
+
|
14 |
+
def load_adp() -> pd.DataFrame:
|
15 |
+
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_fpecr_latest.csv")
|
16 |
+
df["ranking_type"] = df["fp_page"].apply(lambda x: os.path.split(x)[-1].replace(".php", ""))
|
17 |
+
return df
|
18 |
+
|
19 |
+
|
20 |
+
@st.cache_data(ttl=60 * 60 * 24)
|
21 |
+
def load_data():
|
22 |
+
# Merge ADP
|
23 |
+
data = load_adp()
|
24 |
+
ranking_type_list = sorted(list(data.ranking_type.unique()))
|
25 |
+
latest_scrape_date = data.scrape_date.max()
|
26 |
+
return data, ranking_type_list, latest_scrape_date
|
27 |
+
|
28 |
+
|
29 |
+
def filtered_keeper_dataframe(data: pd.DataFrame, ranking_type_list: list[str], latest_scrape_date: str):
|
30 |
+
st.write(f"Scraped data as of: {latest_scrape_date}")
|
31 |
+
default_ix = ranking_type_list.index("ppr-superflex-cheatsheets")
|
32 |
+
ranking_type_selected = st.selectbox("ECR Format:", ranking_type_list, index=default_ix)
|
33 |
+
ranking_type_filter = data["ranking_type"] == ranking_type_selected
|
34 |
+
|
35 |
+
is_advanced = st.checkbox("Show Advanced View")
|
36 |
+
|
37 |
+
id_cols = [
|
38 |
+
"player_square_image_url",
|
39 |
+
"player",
|
40 |
+
"pos",
|
41 |
+
"team",
|
42 |
+
]
|
43 |
+
|
44 |
+
id_cols_advanced = [
|
45 |
+
"bye",
|
46 |
+
"player_owned_yahoo",
|
47 |
+
]
|
48 |
+
|
49 |
+
adp_cols: list[str] = [
|
50 |
+
"ecr",
|
51 |
+
]
|
52 |
+
|
53 |
+
adp_cols_advanced = ["sd", "best", "worst"]
|
54 |
+
|
55 |
+
if is_advanced:
|
56 |
+
show_columns = id_cols + id_cols_advanced + adp_cols + adp_cols_advanced
|
57 |
+
else:
|
58 |
+
show_columns = id_cols + adp_cols
|
59 |
+
|
60 |
+
filtered_data = filter_dataframe(data.loc[ranking_type_filter, show_columns])
|
61 |
+
st.dataframe(
|
62 |
+
filtered_data,
|
63 |
+
hide_index=True,
|
64 |
+
height=35 * (len(filtered_data) + 1) + 12,
|
65 |
+
use_container_width=True,
|
66 |
+
column_config={
|
67 |
+
"player_square_image_url": st.column_config.ImageColumn(label="", help="Player image"),
|
68 |
+
},
|
69 |
+
)
|
70 |
+
|
71 |
+
st.write("Source: https://github.com/dynastyprocess/data")
|
72 |
+
|
73 |
+
|
74 |
+
def get_keeper_app():
|
75 |
+
keeper_title = "Expert Consensus Rankings"
|
76 |
+
st.set_page_config(page_title=keeper_title, page_icon=DEFAULT_ICON, layout="wide")
|
77 |
+
get_authorization_button()
|
78 |
+
st.title(keeper_title)
|
79 |
+
data, ecr_type_list, latest_scrape_date = load_data()
|
80 |
+
|
81 |
+
with st.container():
|
82 |
+
filtered_keeper_dataframe(data, ecr_type_list, latest_scrape_date)
|
83 |
+
|
84 |
+
|
85 |
+
if __name__ == "__main__":
|
86 |
+
get_keeper_app()
|