File size: 2,512 Bytes
e4a5a25
a4ba037
e4a5a25
 
 
 
 
 
130c598
e4a5a25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130c598
 
 
 
e4a5a25
 
 
a4ba037
 
 
e4a5a25
 
13fb024
fc4508d
 
 
 
 
 
e4a5a25
 
 
 
 
 
 
 
a4ba037
 
 
 
 
 
 
 
e4a5a25
 
a4ba037
 
 
 
 
 
e4a5a25
a4ba037
 
 
 
 
 
 
 
e4a5a25
 
 
 
 
 
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
import datetime
import pandas as pd
import streamlit as st

from config import DEFAULT_ICON
from shared_page import common_page_config

from queries.footballguys.constants import YEAR
from queries.nflverse.github_data import get_pbp_participation, get_current_tables, SEASON


def load_data():
    data = get_pbp_participation(YEAR)
    teams_list = sorted(filter(None, data.possession_team.unique()))
    # position_list = data.position.unique()
    # weeks_list = sorted(data.week.unique())
    data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p")
    return data, teams_list, data_load_time_str


def get_page():
    page_title = f"Team Formations - {YEAR}"
    st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
    common_page_config()
    st.title(page_title)
    if f"ftn_charting_ftn_charting_{SEASON}" not in get_current_tables():
        st.write("Data not loaded.")
        st.write("Check loaded data [here](./Load_Data)")
        return
    data, teams_list, data_load_time_str = load_data()
    st.write(f"Data loaded as of: {data_load_time_str} UTC")
    default_groups = [
        "down",
        "play_type",
        "offense_personnel",
    ]
    group_options = [
        "week",
        "down",
        "qtr",
        "ydstogo",
        "play_type",
        "pass_length",
        "pass_location",
        "possession_team",
        "offense_formation",
        "offense_personnel",
        "number_of_pass_rushers",
        "defenders_in_box",
        "defense_personnel",
    ]
    group_by_selected = st.multiselect("Group by:", group_options) or default_groups
    team_selected = st.selectbox("Team:", teams_list)
    week_selection = st.slider(
        "Filter Week Range:",
        min_value=data["week"].min(),
        max_value=data["week"].max(),
        value=(data["week"].min(), data["week"].max()),
        step=1,
    )

    with st.container():
        filtered_data = data[
            (data.possession_team == team_selected)
            & (data.play_type.isin(["pass", "run"]))
            & (data["week"].between(*week_selection))
        ]

        st.dataframe(
            pd.pivot_table(
                filtered_data,
                values="count_col",
                index=group_by_selected,
                columns="week",
                aggfunc={"count_col": "sum"},
                # margins=True,
            ),
            use_container_width=False,
        )


if __name__ == "__main__":
    get_page()