James McCool
commited on
Commit
·
f70d907
1
Parent(s):
53b891e
Add database connection module and refactor Streamlit app to utilize it, improving code organization and data handling for simulations.
Browse files- src/database.py +15 -0
- src/sim_func_hold/regular_functions.py +1 -2
- src/sim_func_hold/showdown_functions.py +4 -3
- src/streamlit_app.py +1 -12
src/database.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pymongo
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def init_conn():
|
| 7 |
+
uri = os.getenv('MONGO_URI')
|
| 8 |
+
if not uri:
|
| 9 |
+
uri = st.secrets['mongo_uri']
|
| 10 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 11 |
+
db = client["NFL_Database"]
|
| 12 |
+
return db
|
| 13 |
+
|
| 14 |
+
# Initialize the database connection
|
| 15 |
+
db = init_conn()
|
src/sim_func_hold/regular_functions.py
CHANGED
|
@@ -2,8 +2,7 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from pymongo import MongoClient
|
| 5 |
-
|
| 6 |
-
from streamlit_app import db
|
| 7 |
|
| 8 |
@st.cache_data(ttl = 600)
|
| 9 |
def init_DK_seed_frames(slate_var, sharp_split):
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from pymongo import MongoClient
|
| 5 |
+
from database import db
|
|
|
|
| 6 |
|
| 7 |
@st.cache_data(ttl = 600)
|
| 8 |
def init_DK_seed_frames(slate_var, sharp_split):
|
src/sim_func_hold/showdown_functions.py
CHANGED
|
@@ -2,9 +2,10 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from pymongo import MongoClient
|
|
|
|
| 5 |
|
| 6 |
@st.cache_data(ttl = 599)
|
| 7 |
-
def init_DK_SD_seed_frames(slate, split
|
| 8 |
if slate == 'Main Slate':
|
| 9 |
collection = db[f"DK_NFL_SD_seed_frame"]
|
| 10 |
elif slate == 'Secondary Slate':
|
|
@@ -21,7 +22,7 @@ def init_DK_SD_seed_frames(slate, split, db):
|
|
| 21 |
return DK_seed
|
| 22 |
|
| 23 |
@st.cache_data(ttl = 599)
|
| 24 |
-
def init_FD_SD_seed_frames(slate, split
|
| 25 |
if slate == 'Main Slate':
|
| 26 |
collection = db[f"FD_NFL_SD_seed_frame"]
|
| 27 |
elif slate == 'Secondary Slate':
|
|
@@ -38,7 +39,7 @@ def init_FD_SD_seed_frames(slate, split, db):
|
|
| 38 |
return FD_seed
|
| 39 |
|
| 40 |
@st.cache_data(ttl = 599)
|
| 41 |
-
def init_SD_baselines(slate_var
|
| 42 |
collection = db['DK_SD_NFL_ROO']
|
| 43 |
cursor = collection.find()
|
| 44 |
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from pymongo import MongoClient
|
| 5 |
+
from database import db
|
| 6 |
|
| 7 |
@st.cache_data(ttl = 599)
|
| 8 |
+
def init_DK_SD_seed_frames(slate, split):
|
| 9 |
if slate == 'Main Slate':
|
| 10 |
collection = db[f"DK_NFL_SD_seed_frame"]
|
| 11 |
elif slate == 'Secondary Slate':
|
|
|
|
| 22 |
return DK_seed
|
| 23 |
|
| 24 |
@st.cache_data(ttl = 599)
|
| 25 |
+
def init_FD_SD_seed_frames(slate, split):
|
| 26 |
if slate == 'Main Slate':
|
| 27 |
collection = db[f"FD_NFL_SD_seed_frame"]
|
| 28 |
elif slate == 'Secondary Slate':
|
|
|
|
| 39 |
return FD_seed
|
| 40 |
|
| 41 |
@st.cache_data(ttl = 599)
|
| 42 |
+
def init_SD_baselines(slate_var):
|
| 43 |
collection = db['DK_SD_NFL_ROO']
|
| 44 |
cursor = collection.find()
|
| 45 |
|
src/streamlit_app.py
CHANGED
|
@@ -9,18 +9,7 @@ from itertools import combinations
|
|
| 9 |
|
| 10 |
st.set_page_config(layout="wide")
|
| 11 |
|
| 12 |
-
|
| 13 |
-
def init_conn():
|
| 14 |
-
uri = os.getenv('MONGO_URI')
|
| 15 |
-
if not uri:
|
| 16 |
-
uri = st.secrets['mongo_uri']
|
| 17 |
-
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 18 |
-
db = client["NFL_Database"]
|
| 19 |
-
|
| 20 |
-
return db
|
| 21 |
-
|
| 22 |
-
db = init_conn()
|
| 23 |
-
|
| 24 |
from sim_func_hold.regular_functions import *
|
| 25 |
from sim_func_hold.showdown_functions import *
|
| 26 |
|
|
|
|
| 9 |
|
| 10 |
st.set_page_config(layout="wide")
|
| 11 |
|
| 12 |
+
from database import db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from sim_func_hold.regular_functions import *
|
| 14 |
from sim_func_hold.showdown_functions import *
|
| 15 |
|