Spaces:
Sleeping
Sleeping
Jon Solow
commited on
Commit
·
b9bcaf8
1
Parent(s):
db7468c
Load data from dbt data
Browse files- src/dbt_data_client.py +42 -0
- src/pages/11_Next_Gen_Stats.py +3 -3
- src/pages/12_Depth_Charts.py +4 -4
- src/pages/7_Snap_Counts.py +3 -3
- src/pages/8_FTN_Charting.py +3 -3
src/dbt_data_client.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import duckdb
|
2 |
import os
|
|
|
3 |
import subprocess
|
4 |
import streamlit as st
|
5 |
|
@@ -8,6 +9,16 @@ DBT_DIR = os.path.join(os.path.dirname(__file__), "dbt_yfdash")
|
|
8 |
DUCKDB_PATH = os.path.join(DBT_DIR, "dev.duckdb")
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def get_db_conn():
|
12 |
return duckdb.connect(DUCKDB_PATH)
|
13 |
|
@@ -31,3 +42,34 @@ def execute_db_command_df(db_command: str):
|
|
31 |
def get_current_tables() -> list[str]:
|
32 |
current_tables_df = execute_db_command_df("SHOW TABLES")
|
33 |
return current_tables_df["name"].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import duckdb
|
2 |
import os
|
3 |
+
import pandas as pd
|
4 |
import subprocess
|
5 |
import streamlit as st
|
6 |
|
|
|
9 |
DUCKDB_PATH = os.path.join(DBT_DIR, "dev.duckdb")
|
10 |
|
11 |
|
12 |
+
FANTASY_POSITIONS = [
|
13 |
+
"QB",
|
14 |
+
"RB",
|
15 |
+
"WR",
|
16 |
+
"TE",
|
17 |
+
"FB",
|
18 |
+
"K",
|
19 |
+
]
|
20 |
+
|
21 |
+
|
22 |
def get_db_conn():
|
23 |
return duckdb.connect(DUCKDB_PATH)
|
24 |
|
|
|
42 |
def get_current_tables() -> list[str]:
|
43 |
current_tables_df = execute_db_command_df("SHOW TABLES")
|
44 |
return current_tables_df["name"].tolist()
|
45 |
+
|
46 |
+
|
47 |
+
def get_snap_counts() -> pd.DataFrame:
|
48 |
+
df = execute_db_command_df("SELECT * from raw_snap_counts")
|
49 |
+
df["fantasy_position"] = df["position"].isin(FANTASY_POSITIONS)
|
50 |
+
return df
|
51 |
+
|
52 |
+
|
53 |
+
def get_play_by_play() -> pd.DataFrame:
|
54 |
+
df = execute_db_command_df("SELECT * from raw_play_by_play")
|
55 |
+
return df
|
56 |
+
|
57 |
+
|
58 |
+
def get_player_stats() -> pd.DataFrame:
|
59 |
+
df = execute_db_command_df("SELECT * from raw_player_stats")
|
60 |
+
return df
|
61 |
+
|
62 |
+
|
63 |
+
def get_ftn_charting() -> pd.DataFrame:
|
64 |
+
df = execute_db_command_df("SELECT * from raw_ftn_charting")
|
65 |
+
return df
|
66 |
+
|
67 |
+
|
68 |
+
def get_depth_charts() -> pd.DataFrame:
|
69 |
+
df = execute_db_command_df("SELECT * from raw_depth_charts")
|
70 |
+
return df
|
71 |
+
|
72 |
+
|
73 |
+
def get_nextgen_stats(stat_category: str) -> pd.DataFrame:
|
74 |
+
df = execute_db_command_df(f"SELECT * from raw_ngs_{stat_category}")
|
75 |
+
return df
|
src/pages/11_Next_Gen_Stats.py
CHANGED
@@ -3,8 +3,8 @@ import streamlit as st
|
|
3 |
from config import DEFAULT_ICON
|
4 |
from shared_page import common_page_config
|
5 |
|
|
|
6 |
from streamlit_filter import get_multiselect_for_df_column
|
7 |
-
from queries.nflverse.github_data import get_nextgen_stats, get_current_tables, SEASON
|
8 |
|
9 |
|
10 |
hide_columns = [
|
@@ -19,7 +19,7 @@ hide_columns = [
|
|
19 |
|
20 |
|
21 |
def get_page():
|
22 |
-
page_title =
|
23 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
24 |
common_page_config()
|
25 |
st.title(page_title)
|
@@ -32,7 +32,7 @@ def get_page():
|
|
32 |
st.write("Data not loaded.")
|
33 |
st.write("Check loaded data [here](./Load_Data)")
|
34 |
return
|
35 |
-
data = get_nextgen_stats(
|
36 |
|
37 |
season_or_week = st.selectbox("Season or Weekly Stats", ["Season", "Week"])
|
38 |
if season_or_week == "Season":
|
|
|
3 |
from config import DEFAULT_ICON
|
4 |
from shared_page import common_page_config
|
5 |
|
6 |
+
from dbt_data_client import get_nextgen_stats, get_current_tables
|
7 |
from streamlit_filter import get_multiselect_for_df_column
|
|
|
8 |
|
9 |
|
10 |
hide_columns = [
|
|
|
19 |
|
20 |
|
21 |
def get_page():
|
22 |
+
page_title = "Next Gen Stats"
|
23 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
24 |
common_page_config()
|
25 |
st.title(page_title)
|
|
|
32 |
st.write("Data not loaded.")
|
33 |
st.write("Check loaded data [here](./Load_Data)")
|
34 |
return
|
35 |
+
data = get_nextgen_stats(stat_category)
|
36 |
|
37 |
season_or_week = st.selectbox("Season or Weekly Stats", ["Season", "Week"])
|
38 |
if season_or_week == "Season":
|
src/pages/12_Depth_Charts.py
CHANGED
@@ -3,8 +3,8 @@ import streamlit as st
|
|
3 |
from config import DEFAULT_ICON
|
4 |
from shared_page import common_page_config
|
5 |
|
|
|
6 |
from streamlit_filter import filter_dataframe
|
7 |
-
from queries.nflverse.github_data import get_depth_charts, get_current_tables, SEASON
|
8 |
|
9 |
|
10 |
hide_columns: list[str] = [
|
@@ -17,19 +17,19 @@ hide_columns: list[str] = [
|
|
17 |
|
18 |
|
19 |
def get_page():
|
20 |
-
page_title =
|
21 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
22 |
common_page_config()
|
23 |
st.title(page_title)
|
24 |
|
25 |
-
table_name =
|
26 |
current_tables_list = get_current_tables()
|
27 |
|
28 |
if table_name not in current_tables_list:
|
29 |
st.write("Data not loaded.")
|
30 |
st.write("Check loaded data [here](./Load_Data)")
|
31 |
return
|
32 |
-
data = get_depth_charts(
|
33 |
|
34 |
week_selection = st.slider(
|
35 |
"Filter Week Range:",
|
|
|
3 |
from config import DEFAULT_ICON
|
4 |
from shared_page import common_page_config
|
5 |
|
6 |
+
from dbt_data_client import get_depth_charts, get_current_tables
|
7 |
from streamlit_filter import filter_dataframe
|
|
|
8 |
|
9 |
|
10 |
hide_columns: list[str] = [
|
|
|
17 |
|
18 |
|
19 |
def get_page():
|
20 |
+
page_title = "Depth Charts"
|
21 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
22 |
common_page_config()
|
23 |
st.title(page_title)
|
24 |
|
25 |
+
table_name = "depth_charts"
|
26 |
current_tables_list = get_current_tables()
|
27 |
|
28 |
if table_name not in current_tables_list:
|
29 |
st.write("Data not loaded.")
|
30 |
st.write("Check loaded data [here](./Load_Data)")
|
31 |
return
|
32 |
+
data = get_depth_charts()
|
33 |
|
34 |
week_selection = st.slider(
|
35 |
"Filter Week Range:",
|
src/pages/7_Snap_Counts.py
CHANGED
@@ -4,12 +4,12 @@ import streamlit as st
|
|
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_snap_counts, get_current_tables, SEASON
|
9 |
|
10 |
|
11 |
def load_data():
|
12 |
-
data = get_snap_counts(
|
13 |
data = data[data.fantasy_position]
|
14 |
teams_list = sorted(data.team.unique())
|
15 |
position_list = data.position.unique()
|
@@ -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
|
|
|
4 |
from config import DEFAULT_ICON
|
5 |
from shared_page import common_page_config
|
6 |
|
7 |
+
from dbt_data_client import get_snap_counts, get_current_tables
|
8 |
from queries.footballguys.constants import YEAR
|
|
|
9 |
|
10 |
|
11 |
def load_data():
|
12 |
+
data = get_snap_counts()
|
13 |
data = data[data.fantasy_position]
|
14 |
teams_list = sorted(data.team.unique())
|
15 |
position_list = data.position.unique()
|
|
|
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 "snap_counts" not in get_current_tables():
|
27 |
st.write("Data not loaded.")
|
28 |
st.write("Check loaded data [here](./Load_Data)")
|
29 |
return
|
src/pages/8_FTN_Charting.py
CHANGED
@@ -4,12 +4,12 @@ import streamlit as st
|
|
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, get_current_tables, SEASON
|
9 |
|
10 |
|
11 |
def load_data():
|
12 |
-
data = get_ftn_charting(
|
13 |
data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p")
|
14 |
return data, data_load_time_str
|
15 |
|
@@ -19,7 +19,7 @@ def get_page():
|
|
19 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
20 |
common_page_config()
|
21 |
st.title(page_title)
|
22 |
-
if
|
23 |
st.write("Data not loaded.")
|
24 |
st.write("Check loaded data [here](./Load_Data)")
|
25 |
return
|
|
|
4 |
from config import DEFAULT_ICON
|
5 |
from shared_page import common_page_config
|
6 |
|
7 |
+
from dbt_data_client import get_ftn_charting, get_current_tables
|
8 |
from queries.footballguys.constants import YEAR
|
|
|
9 |
|
10 |
|
11 |
def load_data():
|
12 |
+
data = get_ftn_charting()
|
13 |
data_load_time_str = datetime.datetime.utcnow().strftime("%m/%d/%Y %I:%M %p")
|
14 |
return data, data_load_time_str
|
15 |
|
|
|
19 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
20 |
common_page_config()
|
21 |
st.title(page_title)
|
22 |
+
if "ftn_charting" not in get_current_tables():
|
23 |
st.write("Data not loaded.")
|
24 |
st.write("Check loaded data [here](./Load_Data)")
|
25 |
return
|