Jon Solow
commited on
Commit
·
d16c97d
1
Parent(s):
1bb1936
Load nflverse data using cache of 24 hours
Browse files
src/queries/nflverse/github_data.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import duckdb
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
|
|
|
| 4 |
from typing import Callable
|
| 5 |
|
| 6 |
from domain.constants import SEASON
|
|
@@ -138,6 +139,7 @@ class NflVerseDataAsset:
|
|
| 138 |
duckdb.register(self.table_name, df)
|
| 139 |
|
| 140 |
|
|
|
|
| 141 |
def load_assets():
|
| 142 |
for tag, asset in NFLVERSE_ASSETS:
|
| 143 |
asset = NflVerseDataAsset(tag, asset)
|
|
@@ -147,8 +149,3 @@ def load_assets():
|
|
| 147 |
def get_current_tables() -> list[str]:
|
| 148 |
current_tables_df = duckdb.sql("SHOW TABLES").df()
|
| 149 |
return current_tables_df["name"].tolist()
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
def load_assets_if_no_tables():
|
| 153 |
-
if not len(get_current_tables()):
|
| 154 |
-
load_assets()
|
|
|
|
| 1 |
import duckdb
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
+
import streamlit as st
|
| 5 |
from typing import Callable
|
| 6 |
|
| 7 |
from domain.constants import SEASON
|
|
|
|
| 139 |
duckdb.register(self.table_name, df)
|
| 140 |
|
| 141 |
|
| 142 |
+
@st.cache_data(ttl=60 * 60 * 24)
|
| 143 |
def load_assets():
|
| 144 |
for tag, asset in NFLVERSE_ASSETS:
|
| 145 |
asset = NflVerseDataAsset(tag, asset)
|
|
|
|
| 149 |
def get_current_tables() -> list[str]:
|
| 150 |
current_tables_df = duckdb.sql("SHOW TABLES").df()
|
| 151 |
return current_tables_df["name"].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/shared_page.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
-
from queries.nflverse.github_data import
|
| 5 |
from data_storage import initialize_data_storage, login_by_token
|
| 6 |
|
| 7 |
|
|
@@ -29,5 +29,5 @@ def login_token_arg_if_exists():
|
|
| 29 |
def common_page_config():
|
| 30 |
initialize_data_storage()
|
| 31 |
local_css()
|
| 32 |
-
|
| 33 |
login_token_arg_if_exists()
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
+
from queries.nflverse.github_data import load_assets
|
| 5 |
from data_storage import initialize_data_storage, login_by_token
|
| 6 |
|
| 7 |
|
|
|
|
| 29 |
def common_page_config():
|
| 30 |
initialize_data_storage()
|
| 31 |
local_css()
|
| 32 |
+
load_assets()
|
| 33 |
login_token_arg_if_exists()
|