Spaces:
Running
Running
Jon Solow
commited on
Commit
·
949a661
1
Parent(s):
2e0b4a6
Add adp data and extra optional filters
Browse files- src/pages/1_Keepers.py +37 -10
- src/streamlit_filter.py +1 -1
src/pages/1_Keepers.py
CHANGED
@@ -3,9 +3,22 @@ import pandas as pd
|
|
3 |
import streamlit as st
|
4 |
|
5 |
from config import DEFAULT_ICON, LEAGUE_NAME
|
|
|
6 |
|
7 |
|
8 |
KEEPER_DATA_URL = "../../tests/mocks/2023_keepers.csv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
@st.cache_data
|
@@ -15,6 +28,15 @@ def load_data():
|
|
15 |
data["position"] = data["eligible_positions"].apply(lambda x: eval(x)[0])
|
16 |
data.columns = data.columns.str.lower()
|
17 |
teams_list = sorted(list(data["team_name"].unique()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
return data, teams_list
|
19 |
|
20 |
|
@@ -22,19 +44,24 @@ def filtered_keeper_dataframe(data: pd.DataFrame, teams_list: list[str]):
|
|
22 |
teams_selected = st.multiselect("Team:", teams_list)
|
23 |
teams_filter = data["team_name"].isin(teams_selected) if teams_selected else data["team_name"].isin(teams_list)
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
st.dataframe(
|
27 |
-
filtered_data,
|
28 |
hide_index=True,
|
29 |
use_container_width=True,
|
30 |
-
column_order=[
|
31 |
-
"team_name",
|
32 |
-
"name",
|
33 |
-
"position",
|
34 |
-
"keeper_cost",
|
35 |
-
"years_eligible",
|
36 |
-
"eligible",
|
37 |
-
],
|
38 |
column_config={},
|
39 |
)
|
40 |
|
|
|
3 |
import streamlit as st
|
4 |
|
5 |
from config import DEFAULT_ICON, LEAGUE_NAME
|
6 |
+
from streamlit_filter import filter_dataframe
|
7 |
|
8 |
|
9 |
KEEPER_DATA_URL = "../../tests/mocks/2023_keepers.csv"
|
10 |
+
HEADSHOT_DATA_URL = "../../tests/mocks/2023_player_headshots.csv"
|
11 |
+
|
12 |
+
|
13 |
+
def load_player_ids() -> pd.DataFrame:
|
14 |
+
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv")
|
15 |
+
df["merge_id"] = df["yahoo_id"].combine_first(df["stats_id"])
|
16 |
+
return df
|
17 |
+
|
18 |
+
|
19 |
+
def load_adp() -> pd.DataFrame:
|
20 |
+
df = pd.read_csv(r"https://raw.githubusercontent.com/dynastyprocess/data/master/files/values-players.csv")
|
21 |
+
return df
|
22 |
|
23 |
|
24 |
@st.cache_data
|
|
|
28 |
data["position"] = data["eligible_positions"].apply(lambda x: eval(x)[0])
|
29 |
data.columns = data.columns.str.lower()
|
30 |
teams_list = sorted(list(data["team_name"].unique()))
|
31 |
+
|
32 |
+
# Merge player ids
|
33 |
+
df_player_ids = load_player_ids()
|
34 |
+
data = data.merge(df_player_ids, how="left", left_on="player_id", right_on="merge_id", suffixes=("", "_ids"))
|
35 |
+
|
36 |
+
# Merge ADP
|
37 |
+
df_adp = load_adp()
|
38 |
+
data = data.merge(df_adp, how="left", left_on="fantasypros_id", right_on="fp_id", suffixes=("", "_adp"))
|
39 |
+
|
40 |
return data, teams_list
|
41 |
|
42 |
|
|
|
44 |
teams_selected = st.multiselect("Team:", teams_list)
|
45 |
teams_filter = data["team_name"].isin(teams_selected) if teams_selected else data["team_name"].isin(teams_list)
|
46 |
|
47 |
+
show_columns = [
|
48 |
+
"team_name",
|
49 |
+
"name",
|
50 |
+
"team",
|
51 |
+
"position",
|
52 |
+
"keeper_cost",
|
53 |
+
"years_eligible",
|
54 |
+
"eligible",
|
55 |
+
"ecr_1qb",
|
56 |
+
"ecr_2qb",
|
57 |
+
"ecr_pos",
|
58 |
+
]
|
59 |
+
|
60 |
+
filtered_data = data.loc[teams_filter, show_columns]
|
61 |
st.dataframe(
|
62 |
+
filter_dataframe(filtered_data),
|
63 |
hide_index=True,
|
64 |
use_container_width=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
column_config={},
|
66 |
)
|
67 |
|
src/streamlit_filter.py
CHANGED
@@ -20,7 +20,7 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
|
20 |
Returns:
|
21 |
pd.DataFrame: Filtered dataframe
|
22 |
"""
|
23 |
-
modify = st.checkbox("Add filters")
|
24 |
|
25 |
if not modify:
|
26 |
return df
|
|
|
20 |
Returns:
|
21 |
pd.DataFrame: Filtered dataframe
|
22 |
"""
|
23 |
+
modify = st.checkbox("Add more filters")
|
24 |
|
25 |
if not modify:
|
26 |
return df
|