Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
b647ce4
1
Parent(s):
6a6dae7
Added lineups page
Browse files
app.py
CHANGED
|
@@ -36,15 +36,22 @@ def init_conn():
|
|
| 36 |
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 37 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 38 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
NBA_Data = st.secrets['NBA_Data']
|
| 41 |
|
| 42 |
gc = gspread.service_account_from_dict(credentials)
|
| 43 |
gc2 = gspread.service_account_from_dict(credentials2)
|
| 44 |
|
| 45 |
-
return gc, gc2, NBA_Data
|
| 46 |
|
| 47 |
-
gcservice_account, gcservice_account2, NBA_Data = init_conn()
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
@st.cache_data(ttl=300)
|
| 50 |
def load_overall_stats():
|
|
@@ -102,10 +109,41 @@ def load_overall_stats():
|
|
| 102 |
|
| 103 |
return dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
def convert_df_to_csv(df):
|
| 106 |
return df.to_csv().encode('utf-8')
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = load_overall_stats()
|
|
|
|
|
|
|
| 109 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 110 |
|
| 111 |
tab1, tab2 = st.tabs(['Range of Outcomes', 'Uploads and Info'])
|
|
@@ -117,11 +155,13 @@ with tab1:
|
|
| 117 |
with col1:
|
| 118 |
st.info(t_stamp)
|
| 119 |
if st.button("Load/Reset Data", key='reset1'):
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 126 |
if site_var2 == 'Draftkings':
|
| 127 |
site_baselines = roo_raw[roo_raw['site'] == 'Draftkings']
|
|
@@ -167,17 +207,69 @@ with tab1:
|
|
| 167 |
)
|
| 168 |
|
| 169 |
with tab2:
|
| 170 |
-
|
| 171 |
-
col1, col2 = st.columns([1, 5])
|
| 172 |
-
|
| 173 |
with col1:
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
with col2:
|
| 182 |
-
if
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 37 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 38 |
}
|
| 39 |
+
|
| 40 |
+
uri = st.secrets['mongo_uri']
|
| 41 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 42 |
+
db = client["NBA_DFS"]
|
| 43 |
|
| 44 |
NBA_Data = st.secrets['NBA_Data']
|
| 45 |
|
| 46 |
gc = gspread.service_account_from_dict(credentials)
|
| 47 |
gc2 = gspread.service_account_from_dict(credentials2)
|
| 48 |
|
| 49 |
+
return gc, gc2, db, NBA_Data
|
| 50 |
|
| 51 |
+
gcservice_account, gcservice_account2, db, NBA_Data = init_conn()
|
| 52 |
+
|
| 53 |
+
dk_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']
|
| 54 |
+
fd_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C1', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']
|
| 55 |
|
| 56 |
@st.cache_data(ttl=300)
|
| 57 |
def load_overall_stats():
|
|
|
|
| 109 |
|
| 110 |
return dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp
|
| 111 |
|
| 112 |
+
@st.cache_data(ttl = 300)
|
| 113 |
+
def init_DK_lineups():
|
| 114 |
+
|
| 115 |
+
collection = db["DK_NBA_seed_frame"]
|
| 116 |
+
cursor = collection.find()
|
| 117 |
+
|
| 118 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 119 |
+
raw_display = raw_display[['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 120 |
+
DK_seed = raw_display.head(10000).to_numpy()
|
| 121 |
+
|
| 122 |
+
return DK_seed
|
| 123 |
+
|
| 124 |
+
@st.cache_data(ttl = 300)
|
| 125 |
+
def init_FD_lineups():
|
| 126 |
+
|
| 127 |
+
collection = db["FD_NBA_seed_frame"]
|
| 128 |
+
cursor = collection.find()
|
| 129 |
+
|
| 130 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 131 |
+
raw_display = raw_display[['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C1', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 132 |
+
FD_seed = raw_display.head(10000).to_numpy()
|
| 133 |
+
|
| 134 |
+
return FD_seed
|
| 135 |
+
|
| 136 |
def convert_df_to_csv(df):
|
| 137 |
return df.to_csv().encode('utf-8')
|
| 138 |
|
| 139 |
+
@st.cache_data
|
| 140 |
+
def convert_df(array):
|
| 141 |
+
array = pd.DataFrame(array, columns=column_names)
|
| 142 |
+
return array.to_csv().encode('utf-8')
|
| 143 |
+
|
| 144 |
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = load_overall_stats()
|
| 145 |
+
dk_lineups = init_DK_lineups()
|
| 146 |
+
fd_lineups = init_FD_lineups()
|
| 147 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 148 |
|
| 149 |
tab1, tab2 = st.tabs(['Range of Outcomes', 'Uploads and Info'])
|
|
|
|
| 155 |
with col1:
|
| 156 |
st.info(t_stamp)
|
| 157 |
if st.button("Load/Reset Data", key='reset1'):
|
| 158 |
+
st.cache_data.clear()
|
| 159 |
+
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = load_overall_stats()
|
| 160 |
+
dk_lineups = init_DK_lineups()
|
| 161 |
+
fd_lineups = init_FD_lineups()
|
| 162 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 163 |
+
for key in st.session_state.keys():
|
| 164 |
+
del st.session_state[key]
|
| 165 |
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 166 |
if site_var2 == 'Draftkings':
|
| 167 |
site_baselines = roo_raw[roo_raw['site'] == 'Draftkings']
|
|
|
|
| 207 |
)
|
| 208 |
|
| 209 |
with tab2:
|
| 210 |
+
col1, col2 = st.columns([1, 7])
|
|
|
|
|
|
|
| 211 |
with col1:
|
| 212 |
+
if st.button("Load/Reset Data", key='reset1'):
|
| 213 |
+
st.cache_data.clear()
|
| 214 |
+
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = load_overall_stats()
|
| 215 |
+
dk_lineups = init_DK_lineups()
|
| 216 |
+
fd_lineups = init_FD_lineups()
|
| 217 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 218 |
+
for key in st.session_state.keys():
|
| 219 |
+
del st.session_state[key]
|
| 220 |
+
|
| 221 |
+
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Just the Main Slate'))
|
| 222 |
+
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'))
|
| 223 |
+
if site_var1 == 'Draftkings':
|
| 224 |
+
raw_baselines = dk_raw
|
| 225 |
+
column_names = dk_columns
|
| 226 |
+
|
| 227 |
+
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1')
|
| 228 |
+
if player_var1 == 'Specific Teams':
|
| 229 |
+
player_var2 = st.multiselect('Which players do you want?', options = dk_raw['Player'].unique())
|
| 230 |
+
elif player_var1 == 'Full Slate':
|
| 231 |
+
player_var2 = dk_raw.Player.values.tolist()
|
| 232 |
+
|
| 233 |
+
elif site_var1 == 'Fanduel':
|
| 234 |
+
raw_baselines = fd_raw
|
| 235 |
+
column_names = fd_columns
|
| 236 |
+
|
| 237 |
+
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1')
|
| 238 |
+
if player_var1 == 'Specific Teams':
|
| 239 |
+
player_var2 = st.multiselect('Which players do you want?', options = dk_raw['Player'].unique())
|
| 240 |
+
elif player_var1 == 'Full Slate':
|
| 241 |
+
player_var2 = dk_raw.Player.values.tolist()
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
if st.button("Prepare data export", key='data_export'):
|
| 245 |
+
data_export = st.session_state.working_seed.copy()
|
| 246 |
+
st.download_button(
|
| 247 |
+
label="Export optimals set",
|
| 248 |
+
data=convert_df(data_export),
|
| 249 |
+
file_name='NBA_optimals_export.csv',
|
| 250 |
+
mime='text/csv',
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
with col2:
|
| 254 |
+
if st.button("Load Lineups", key='load_data'):
|
| 255 |
+
if site_var1 == 'Draftkings':
|
| 256 |
+
if 'working_seed' in st.session_state:
|
| 257 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], player_var2)]
|
| 258 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:151], columns=column_names)
|
| 259 |
+
elif 'working_seed' not in st.session_state:
|
| 260 |
+
st.session_state.working_seed = dk_lineups.copy()
|
| 261 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], player_var2)]
|
| 262 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:151], columns=column_names)
|
| 263 |
+
|
| 264 |
+
elif site_var1 == 'Fanduel':
|
| 265 |
+
if 'working_seed' in st.session_state:
|
| 266 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 10], player_var2)]
|
| 267 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:151], columns=column_names)
|
| 268 |
+
elif 'working_seed' not in st.session_state:
|
| 269 |
+
st.session_state.working_seed = fd_lineups.copy()
|
| 270 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 10], player_var2)]
|
| 271 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:151], columns=column_names)
|
| 272 |
+
|
| 273 |
+
with st.container():
|
| 274 |
+
if 'data_export_display' in st.session_state:
|
| 275 |
+
st.dataframe(st.session_state.data_export_display.style.format(precision=2), use_container_width = True)
|