-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
145 lines (123 loc) · 3.95 KB
/
app.py
File metadata and controls
145 lines (123 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import streamlit as st
from streamlit_extras.badges import badge
from auxiliary import (
match_dict,
matches,
create_timestring,
get_event_dict,
create_plot,
shot_freeze_frame,
)
from statsbombpy import sb
import pandas as pd
st.set_page_config(
page_title="Euro 2024: StatsBomb 360° Data Explorer",
page_icon="https://raw.githubusercontent.com/AKapich/StatsBomb360_App/main/logos/eurologo.ico",
)
st.title("Euro 2024: StatsBomb 360° Tool")
st.markdown(
"*Platform providing insight into StatsBomb 360° data for every Euro 2024 match*"
)
st.markdown("---")
st.sidebar.image(
"https://raw.githubusercontent.com/AKapich/StatsBomb360_App/main/logos/EURO2024.png"
)
# dropdown for choosing the match
st.sidebar.title("Select Match")
selected_match = st.sidebar.selectbox("Match:", match_dict.keys(), index=1)
mode = st.sidebar.selectbox("Choose mode:", ["Timestamp Slider", "Shot Freeze Frame"])
match_id = match_dict[selected_match]
home_team = selected_match.split(" - ")[0]
away_team = selected_match.split(" - ")[1]
competition_stage = matches[matches["match_id"] == match_id].iloc[0][
"competition_stage"
]
# data
frame_df = sb.frames(match_id=match_id, fmt="dataframe")
frame_df = frame_df.rename(columns={"location": "player_location"})
event_df = sb.events(match_id=match_id)
event_df["timestring"] = event_df.apply(create_timestring, axis=1)
df = pd.merge(frame_df, event_df, on="id", how="right")
df = df.sort_values("timestring")
if mode == "Timestamp Slider":
chosen_timestamp = st.select_slider(
"Select timestamp",
options=df[(df["visible_area"].notna()) | (df["type"] == "Shot")][
"timestring"
].unique(),
)
event_dict = get_event_dict(df=df, chosen_timestamp=chosen_timestamp)
displayed_event = st.selectbox("Select event", options=event_dict.keys())
voronoi = st.checkbox("Highlight controlled space")
st.pyplot(
create_plot(
df,
event_dict,
chosen_timestamp,
displayed_event,
voronoi,
home_team,
away_team,
)
)
elif mode == "Shot Freeze Frame":
tab1, tab2 = st.tabs(["📈 Charts", "📄 Shot Info"])
shot_info = event_df[event_df["shot_outcome"].notna()][
[
"player",
"timestring",
"shot_outcome",
"shot_statsbomb_xg",
"shot_technique",
"shot_body_part",
]
]
shot_info.index = range(1, len(shot_info) + 1)
with tab1:
shot_cols = [
"player",
"team",
"timestring",
"shot_outcome",
"shot_freeze_frame",
"location",
"shot_end_location",
]
shot_df = event_df[event_df["shot_outcome"].notna()][shot_cols]
shot_df["tag"] = (
shot_df["player"]
+ " - "
+ shot_df["timestring"]
+ " ( "
+ shot_df["shot_outcome"]
+ " )"
)
tag = st.selectbox("Choose shot", options=shot_df["tag"].to_list())
keeper_cone = st.checkbox("Highlight Keeper Cone View")
st.pyplot(shot_freeze_frame(shot_df, tag, home_team, away_team, keeper_cone))
with tab2:
shot_info.columns = [
"Player",
"Timestamp",
"Shot Outcome",
"xG",
"Technique",
"Body Part",
]
st.dataframe(shot_info)
st.markdown("---")
st.image(
"https://raw.githubusercontent.com/AKapich/StatsBomb360_App/main/logos/sb_icon.png",
caption="App made by Aleks Kapich. Data powered by StatsBomb",
use_container_width=True,
)
# signature
st.sidebar.markdown("---")
col1, col2 = st.columns(2)
with col1:
st.sidebar.markdown("App made by **Aleks Kapich**")
with col2:
with st.sidebar:
badge(type="twitter", name="AKapich")
badge(type="github", name="AKapich")
badge(type="buymeacoffee", name="akapich")