Spaces:
Sleeping
Sleeping
Jon Solow
commited on
Commit
·
b84b21c
1
Parent(s):
fb558a3
Add fantasy positions filter and set explicit filters on snap counts
Browse files
src/pages/7_Snap_Counts.py
CHANGED
@@ -6,14 +6,17 @@ from shared_page import common_page_config
|
|
6 |
|
7 |
from queries.footballguys.constants import YEAR
|
8 |
from queries.nflverse.github_data import get_snap_counts
|
9 |
-
from streamlit_filter import filter_dataframe
|
10 |
|
11 |
|
12 |
@st.cache_data(ttl=60 * 60 * 24)
|
13 |
def load_data():
|
14 |
data = get_snap_counts(YEAR)
|
|
|
|
|
|
|
|
|
15 |
data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p")
|
16 |
-
return data, data_load_time_str
|
17 |
|
18 |
|
19 |
def get_page():
|
@@ -23,11 +26,18 @@ def get_page():
|
|
23 |
st.title(page_title)
|
24 |
if st.button("Refresh Data"):
|
25 |
st.cache_data.clear()
|
26 |
-
data, data_load_time_str = load_data()
|
27 |
st.write(f"Data loaded as of: {data_load_time_str} UTC")
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
with st.container():
|
30 |
-
filtered_data =
|
|
|
|
|
31 |
st.dataframe(
|
32 |
filtered_data,
|
33 |
hide_index=True,
|
|
|
6 |
|
7 |
from queries.footballguys.constants import YEAR
|
8 |
from queries.nflverse.github_data import get_snap_counts
|
|
|
9 |
|
10 |
|
11 |
@st.cache_data(ttl=60 * 60 * 24)
|
12 |
def load_data():
|
13 |
data = get_snap_counts(YEAR)
|
14 |
+
data = data[data.fantasy_position]
|
15 |
+
teams_list = sorted(data.team.unique())
|
16 |
+
position_list = data.position.unique()
|
17 |
+
weeks_list = sorted(data.week.unique())
|
18 |
data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p")
|
19 |
+
return data, teams_list, position_list, weeks_list, data_load_time_str
|
20 |
|
21 |
|
22 |
def get_page():
|
|
|
26 |
st.title(page_title)
|
27 |
if st.button("Refresh Data"):
|
28 |
st.cache_data.clear()
|
29 |
+
data, teams_list, position_list, weeks_list, data_load_time_str = load_data()
|
30 |
st.write(f"Data loaded as of: {data_load_time_str} UTC")
|
31 |
+
teams_selected = st.multiselect("Team:", teams_list, placeholder="Select a team to filter") or teams_list
|
32 |
+
positions_selected = (
|
33 |
+
st.multiselect("Position:", position_list, placeholder="Select a position to filter") or position_list
|
34 |
+
)
|
35 |
+
weeks_selected = st.multiselect("Week:", weeks_list, placeholder="Select a week to filter") or weeks_list
|
36 |
|
37 |
with st.container():
|
38 |
+
filtered_data = data[
|
39 |
+
(data.team.isin(teams_selected) & data.position.isin(positions_selected) & data.week.isin(weeks_selected))
|
40 |
+
]
|
41 |
st.dataframe(
|
42 |
filtered_data,
|
43 |
hide_index=True,
|
src/queries/nflverse/github_data.py
CHANGED
@@ -7,8 +7,20 @@ def get_parquet_github(season_int: int, parquet_prefix: str):
|
|
7 |
return df
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def get_snap_counts(season_int: int) -> pd.DataFrame:
|
11 |
-
|
|
|
|
|
12 |
|
13 |
|
14 |
def get_play_by_play(season_int: int) -> pd.DataFrame:
|
|
|
7 |
return df
|
8 |
|
9 |
|
10 |
+
FANTASY_POSITIONS = [
|
11 |
+
"QB",
|
12 |
+
"RB",
|
13 |
+
"WR",
|
14 |
+
"TE",
|
15 |
+
"FB",
|
16 |
+
"K",
|
17 |
+
]
|
18 |
+
|
19 |
+
|
20 |
def get_snap_counts(season_int: int) -> pd.DataFrame:
|
21 |
+
df = get_parquet_github(season_int, "snap_counts/snap_counts")
|
22 |
+
df["fantasy_position"] = df["position"].isin(FANTASY_POSITIONS)
|
23 |
+
return df
|
24 |
|
25 |
|
26 |
def get_play_by_play(season_int: int) -> pd.DataFrame:
|