Spaces:
Running
Running
Jon Solow
commited on
Commit
·
7df9386
1
Parent(s):
dfae8a4
Completely remove previous nflverse
Browse files
src/dbt_data_client.py
CHANGED
@@ -73,3 +73,8 @@ def get_depth_charts() -> pd.DataFrame:
|
|
73 |
def get_nextgen_stats(stat_category: str) -> pd.DataFrame:
|
74 |
df = execute_db_command_df(f"SELECT * from ngs_{stat_category}")
|
75 |
return df
|
|
|
|
|
|
|
|
|
|
|
|
73 |
def get_nextgen_stats(stat_category: str) -> pd.DataFrame:
|
74 |
df = execute_db_command_df(f"SELECT * from ngs_{stat_category}")
|
75 |
return df
|
76 |
+
|
77 |
+
|
78 |
+
def get_pbp_participation() -> pd.DataFrame:
|
79 |
+
# TODO - wire this up to actual play by play participation
|
80 |
+
return pd.DataFrame()
|
src/pages/9_Team_Formations.py
CHANGED
@@ -5,8 +5,8 @@ import streamlit as st
|
|
5 |
from config import DEFAULT_ICON
|
6 |
from shared_page import common_page_config
|
7 |
|
|
|
8 |
from queries.footballguys.constants import YEAR
|
9 |
-
from queries.nflverse.github_data import get_pbp_participation, get_current_tables, SEASON
|
10 |
|
11 |
|
12 |
def load_data():
|
@@ -23,7 +23,7 @@ def get_page():
|
|
23 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
24 |
common_page_config()
|
25 |
st.title(page_title)
|
26 |
-
if
|
27 |
st.write("Data not loaded.")
|
28 |
st.write("Check loaded data [here](./Load_Data)")
|
29 |
return
|
|
|
5 |
from config import DEFAULT_ICON
|
6 |
from shared_page import common_page_config
|
7 |
|
8 |
+
from dbt_data_client import get_pbp_participation, get_current_tables
|
9 |
from queries.footballguys.constants import YEAR
|
|
|
10 |
|
11 |
|
12 |
def load_data():
|
|
|
23 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
24 |
common_page_config()
|
25 |
st.title(page_title)
|
26 |
+
if "ftn_charting" not in get_current_tables():
|
27 |
st.write("Data not loaded.")
|
28 |
st.write("Check loaded data [here](./Load_Data)")
|
29 |
return
|
src/queries/nflverse/__init__.py
DELETED
File without changes
|
src/queries/nflverse/github_data.py
DELETED
@@ -1,145 +0,0 @@
|
|
1 |
-
import duckdb
|
2 |
-
import pandas as pd
|
3 |
-
import os
|
4 |
-
import streamlit as st
|
5 |
-
from typing import Callable
|
6 |
-
|
7 |
-
|
8 |
-
duckdb.default_connection.execute("SET GLOBAL pandas_analyze_sample=100000")
|
9 |
-
|
10 |
-
BASE_URL = "https://github.com/nflverse/nflverse-data/releases/download/"
|
11 |
-
|
12 |
-
|
13 |
-
FANTASY_POSITIONS = [
|
14 |
-
"QB",
|
15 |
-
"RB",
|
16 |
-
"WR",
|
17 |
-
"TE",
|
18 |
-
"FB",
|
19 |
-
"K",
|
20 |
-
]
|
21 |
-
|
22 |
-
|
23 |
-
def get_snap_counts(season_int: int) -> pd.DataFrame:
|
24 |
-
df = duckdb.sql(f"SELECT * from snap_counts_snap_counts_{season_int}").df()
|
25 |
-
df["fantasy_position"] = df["position"].isin(FANTASY_POSITIONS)
|
26 |
-
return df
|
27 |
-
|
28 |
-
|
29 |
-
def get_play_by_play(season_int: int) -> pd.DataFrame:
|
30 |
-
df = duckdb.sql(f"SELECT * from pbp_play_by_play_{season_int}").df()
|
31 |
-
return df
|
32 |
-
|
33 |
-
|
34 |
-
def get_player_stats(season_int: int) -> pd.DataFrame:
|
35 |
-
df = duckdb.sql("SELECT * from player_stats_player_stats").df()
|
36 |
-
return df
|
37 |
-
|
38 |
-
|
39 |
-
def get_ftn_charting(season_int: int) -> pd.DataFrame:
|
40 |
-
df = duckdb.sql(f"SELECT * from ftn_charting_ftn_charting_{season_int}").df()
|
41 |
-
return df
|
42 |
-
|
43 |
-
|
44 |
-
def get_pbp_participation(season_int: int) -> pd.DataFrame:
|
45 |
-
df = duckdb.sql(
|
46 |
-
f"""
|
47 |
-
SELECT
|
48 |
-
a.*
|
49 |
-
, b.week
|
50 |
-
, b.down
|
51 |
-
, b.qtr
|
52 |
-
, b.ydstogo
|
53 |
-
, b.play_type
|
54 |
-
, b.pass_length
|
55 |
-
, b.pass_location
|
56 |
-
, 1 as count_col
|
57 |
-
from pbp_participation_pbp_participation_{season_int} a
|
58 |
-
left join pbp_play_by_play_{season_int} b
|
59 |
-
on a.play_id = b.play_id
|
60 |
-
and a.nflverse_game_id = b.game_id
|
61 |
-
where b.week is not null
|
62 |
-
"""
|
63 |
-
).df()
|
64 |
-
return df
|
65 |
-
|
66 |
-
|
67 |
-
def get_depth_charts(season_int: int) -> pd.DataFrame:
|
68 |
-
df = duckdb.sql(
|
69 |
-
f"""
|
70 |
-
SELECT
|
71 |
-
*
|
72 |
-
from depth_charts_depth_charts_{season_int}
|
73 |
-
"""
|
74 |
-
).df()
|
75 |
-
return df
|
76 |
-
|
77 |
-
|
78 |
-
def get_nextgen_stats(season_int: int, stat_category: str) -> pd.DataFrame:
|
79 |
-
df = duckdb.sql(f"SELECT * from nextgen_stats_ngs_{stat_category} where season = {season_int}").df()
|
80 |
-
return df
|
81 |
-
|
82 |
-
|
83 |
-
SEASON = "2024"
|
84 |
-
|
85 |
-
NFLVERSE_ASSETS = [
|
86 |
-
("ftn_charting", f"ftn_charting_{SEASON}.parquet"),
|
87 |
-
("espn_data", "qbr_season_level.parquet"),
|
88 |
-
("espn_data", "qbr_week_level.parquet"),
|
89 |
-
("players", "players.parquet"),
|
90 |
-
("pbp_participation", f"pbp_participation_{SEASON}.parquet"),
|
91 |
-
("snap_counts", f"snap_counts_{SEASON}.parquet"),
|
92 |
-
("player_stats", f"player_stats_{SEASON}.parquet"),
|
93 |
-
("player_stats", f"player_stats_def_{SEASON}.parquet"),
|
94 |
-
("player_stats", f"player_stats_kicking_{SEASON}.parquet"),
|
95 |
-
("pfr_advstats", "advstats_season_def.parquet"),
|
96 |
-
("pfr_advstats", "advstats_season_pass.parquet"),
|
97 |
-
("pfr_advstats", "advstats_season_rec.parquet"),
|
98 |
-
("pfr_advstats", "advstats_season_rush.parquet"),
|
99 |
-
("pfr_advstats", f"advstats_week_def_{SEASON}.parquet"),
|
100 |
-
("pfr_advstats", f"advstats_week_pass_{SEASON}.parquet"),
|
101 |
-
("pfr_advstats", f"advstats_week_rec_{SEASON}.parquet"),
|
102 |
-
("pfr_advstats", f"advstats_week_rush_{SEASON}.parquet"),
|
103 |
-
("pbp", f"play_by_play_{SEASON}.parquet"),
|
104 |
-
("nextgen_stats", "ngs_passing.parquet"),
|
105 |
-
("nextgen_stats", "ngs_receiving.parquet"),
|
106 |
-
("nextgen_stats", "ngs_rushing.parquet"),
|
107 |
-
("depth_charts", f"depth_charts_{SEASON}.parquet"),
|
108 |
-
]
|
109 |
-
|
110 |
-
|
111 |
-
class NflVerseDataAsset:
|
112 |
-
def __init__(
|
113 |
-
self,
|
114 |
-
release_tag: str,
|
115 |
-
asset_name: str,
|
116 |
-
dataframe_mutation_fxn: Callable[[pd.DataFrame], pd.DataFrame] = lambda x: x,
|
117 |
-
):
|
118 |
-
self.release_tag = release_tag
|
119 |
-
self.asset_name = asset_name
|
120 |
-
self.dataframe_mutation_fxn = dataframe_mutation_fxn
|
121 |
-
self.table_name = f"{release_tag}_{asset_name.rsplit('.', 1)[0]}"
|
122 |
-
|
123 |
-
def load_parquet_asset_to_df(self) -> pd.DataFrame:
|
124 |
-
location = os.path.join(BASE_URL, self.release_tag, self.asset_name)
|
125 |
-
df = pd.read_parquet(location)
|
126 |
-
return df
|
127 |
-
|
128 |
-
def register_asset_to_duckdb(self) -> None:
|
129 |
-
df = self.load_parquet_asset_to_df()
|
130 |
-
df = self.dataframe_mutation_fxn(df)
|
131 |
-
duckdb.register(self.table_name, df)
|
132 |
-
|
133 |
-
|
134 |
-
def load_assets():
|
135 |
-
for tag, asset in NFLVERSE_ASSETS:
|
136 |
-
try:
|
137 |
-
asset = NflVerseDataAsset(tag, asset)
|
138 |
-
asset.register_asset_to_duckdb()
|
139 |
-
except Exception:
|
140 |
-
st.write(f"{tag} failed to load")
|
141 |
-
|
142 |
-
|
143 |
-
def get_current_tables(duckdb_conn=duckdb) -> list[str]:
|
144 |
-
current_tables_df = duckdb_conn.sql("SHOW TABLES").df()
|
145 |
-
return current_tables_df["name"].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|