File size: 2,217 Bytes
4569c98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243b60e
4569c98
 
 
 
 
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
import streamlit as st

from config import DEFAULT_ICON
from shared_page import common_page_config

from streamlit_filter import get_multiselect_for_df_column
from queries.nflverse.github_data import get_nextgen_stats, get_current_tables, SEASON


hide_columns = [
    "season",
    "season_type",
    "player_gsis_id",
    "player_first_name",
    "player_last_name",
    "player_jersey_number",
    "player_short_name",
]


def get_page():
    page_title = f"Next Gen Stats - {SEASON}"
    st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
    common_page_config()
    st.title(page_title)

    stat_category = st.selectbox("Stat Category", ["Passing", "Rushing", "Receiving"])
    ngs_table_name = f"nextgen_stats_ngs_{stat_category.lower()}"
    current_tables_list = get_current_tables()

    if ngs_table_name not in current_tables_list:
        st.write("Data not loaded.")
        st.write("Check loaded data [here](./Load_Data)")
        return
    data = get_nextgen_stats(SEASON, stat_category)

    season_or_week = st.selectbox("Season or Weekly Stats", ["Season", "Week"])
    if season_or_week == "Season":
        data = data[data["week"] == 0]
        data.drop(columns=["week"], inplace=True)
    else:
        data = data[data["week"] > 0]
        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,
        )
        data = data[data["week"].between(*week_selection)]

    data.drop(columns=hide_columns, inplace=True)
    positions_selected = get_multiselect_for_df_column(data, "player_position")
    teams_selected = get_multiselect_for_df_column(data, "team_abbr")

    data = data[(data["player_position"].isin(positions_selected) & data["team_abbr"].isin(teams_selected))]

    with st.container():
        filtered_data = data
        st.dataframe(
            filtered_data,
            hide_index=True,
            # height=35 * (len(filtered_data) + 1) + 12,
            use_container_width=False,
            column_config={},
        )


if __name__ == "__main__":
    get_page()