Spaces:
Running
Running
Jon Solow
commited on
Commit
•
e4a5a25
1
Parent(s):
b84b21c
Add ftn charting and team formations
Browse files
src/pages/8_FTN_Charting.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
from config import DEFAULT_ICON
|
5 |
+
from shared_page import common_page_config
|
6 |
+
|
7 |
+
from queries.footballguys.constants import YEAR
|
8 |
+
from queries.nflverse.github_data import get_ftn_charting
|
9 |
+
|
10 |
+
|
11 |
+
@st.cache_data(ttl=60 * 60 * 24)
|
12 |
+
def load_data():
|
13 |
+
data = get_ftn_charting(YEAR)
|
14 |
+
data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p")
|
15 |
+
return data, data_load_time_str
|
16 |
+
|
17 |
+
|
18 |
+
def get_page():
|
19 |
+
page_title = f"FTN Charting - {YEAR}"
|
20 |
+
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
21 |
+
common_page_config()
|
22 |
+
st.title(page_title)
|
23 |
+
if st.button("Refresh Data"):
|
24 |
+
st.cache_data.clear()
|
25 |
+
data, data_load_time_str = load_data()
|
26 |
+
st.write(f"Data loaded as of: {data_load_time_str} UTC")
|
27 |
+
|
28 |
+
with st.container():
|
29 |
+
filtered_data = data
|
30 |
+
st.dataframe(
|
31 |
+
filtered_data,
|
32 |
+
hide_index=True,
|
33 |
+
# height=35 * (len(filtered_data) + 1) + 12,
|
34 |
+
use_container_width=False,
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
get_page()
|
src/pages/9_Team_Formations.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
from config import DEFAULT_ICON
|
5 |
+
from shared_page import common_page_config
|
6 |
+
|
7 |
+
from queries.footballguys.constants import YEAR
|
8 |
+
from queries.nflverse.github_data import get_pbp_participation
|
9 |
+
|
10 |
+
|
11 |
+
@st.cache_data(ttl=60 * 60 * 24)
|
12 |
+
def load_data():
|
13 |
+
data = get_pbp_participation(YEAR)
|
14 |
+
# data = data[data.fantasy_position]
|
15 |
+
teams_list = sorted(filter(None, data.possession_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, data_load_time_str
|
20 |
+
|
21 |
+
|
22 |
+
def get_page():
|
23 |
+
page_title = f"Team Formations - {YEAR}"
|
24 |
+
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
25 |
+
common_page_config()
|
26 |
+
st.title(page_title)
|
27 |
+
if st.button("Refresh Data"):
|
28 |
+
st.cache_data.clear()
|
29 |
+
data, teams_list, data_load_time_str = load_data()
|
30 |
+
st.write(f"Data loaded as of: {data_load_time_str} UTC")
|
31 |
+
default_groups = [
|
32 |
+
"possession_team",
|
33 |
+
"offense_formation",
|
34 |
+
]
|
35 |
+
group_options = [
|
36 |
+
"possession_team",
|
37 |
+
"offense_formation",
|
38 |
+
"offense_personnel",
|
39 |
+
"number_of_pass_rushers",
|
40 |
+
"defenders_in_box",
|
41 |
+
"defense_personnel",
|
42 |
+
]
|
43 |
+
group_by_selected = st.multiselect("Group by:", group_options) or default_groups
|
44 |
+
teams_selected = st.multiselect("Team:", teams_list, placeholder="Select a team to filter") or teams_list
|
45 |
+
|
46 |
+
with st.container():
|
47 |
+
filtered_data = data[(data.possession_team.isin(teams_selected))]
|
48 |
+
grouped_data = filtered_data.groupby(group_by_selected).size()
|
49 |
+
st.dataframe(
|
50 |
+
grouped_data,
|
51 |
+
hide_index=False,
|
52 |
+
# height=35 * (len(filtered_data) + 1) + 12,
|
53 |
+
use_container_width=False,
|
54 |
+
# column_order=[
|
55 |
+
# "season",
|
56 |
+
# "game_type",
|
57 |
+
# "week",
|
58 |
+
# "player",
|
59 |
+
# "position",
|
60 |
+
# "team",
|
61 |
+
# "opponent",
|
62 |
+
# "offense_snaps",
|
63 |
+
# "offense_pct",
|
64 |
+
# "defense_snaps",
|
65 |
+
# "defense_pct",
|
66 |
+
# "st_snaps",
|
67 |
+
# "st_pct",
|
68 |
+
# ],
|
69 |
+
column_config={
|
70 |
+
"0": st.column_config.NumberColumn(label="Count"),
|
71 |
+
},
|
72 |
+
)
|
73 |
+
|
74 |
+
|
75 |
+
if __name__ == "__main__":
|
76 |
+
get_page()
|
src/queries/nflverse/github_data.py
CHANGED
@@ -29,3 +29,11 @@ def get_play_by_play(season_int: int) -> pd.DataFrame:
|
|
29 |
|
30 |
def get_player_stats(season_int: int) -> pd.DataFrame:
|
31 |
return get_parquet_github(season_int, "player_stats/player_stats")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
def get_player_stats(season_int: int) -> pd.DataFrame:
|
31 |
return get_parquet_github(season_int, "player_stats/player_stats")
|
32 |
+
|
33 |
+
|
34 |
+
def get_ftn_charting(season_int: int) -> pd.DataFrame:
|
35 |
+
return get_parquet_github(season_int, "ftn_charting/ftn_charting")
|
36 |
+
|
37 |
+
|
38 |
+
def get_pbp_participation(season_int: int) -> pd.DataFrame:
|
39 |
+
return get_parquet_github(season_int, "pbp_participation/pbp_participation")
|