Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,39 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
-
import streamlit as st
|
| 5 |
import gspread
|
|
|
|
|
|
|
| 6 |
from itertools import combinations
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
credentials = {
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
| 29 |
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
|
@@ -33,69 +43,37 @@ player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_fi
|
|
| 33 |
|
| 34 |
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348'
|
| 35 |
|
| 36 |
-
@st.cache_data
|
| 37 |
-
def
|
| 38 |
sh = gc.open_by_url(all_dk_player_projections)
|
| 39 |
worksheet = sh.worksheet('Site_Info')
|
| 40 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
@st.cache_data
|
| 45 |
-
def player_stat_table():
|
| 46 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
| 47 |
worksheet = sh.worksheet('Player_Projections')
|
| 48 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
@st.cache_data
|
| 53 |
-
def load_dk_player_projections():
|
| 54 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
| 55 |
worksheet = sh.worksheet('DK_ROO')
|
| 56 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 57 |
load_display.replace('', np.nan, inplace=True)
|
| 58 |
raw_display = load_display.dropna(subset=['Median'])
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
@st.cache_data
|
| 63 |
-
def load_fd_player_projections():
|
| 64 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
| 65 |
worksheet = sh.worksheet('FD_ROO')
|
| 66 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 67 |
load_display.replace('', np.nan, inplace=True)
|
| 68 |
raw_display = load_display.dropna(subset=['Median'])
|
|
|
|
| 69 |
|
| 70 |
-
return
|
| 71 |
-
|
| 72 |
-
@st.cache_data
|
| 73 |
-
def load_dk_stacks():
|
| 74 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
| 75 |
-
worksheet = sh.worksheet('DK_Stacks')
|
| 76 |
-
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 77 |
-
raw_display = load_display
|
| 78 |
-
|
| 79 |
-
return raw_display
|
| 80 |
-
|
| 81 |
-
@st.cache_data
|
| 82 |
-
def load_fd_stacks():
|
| 83 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
| 84 |
-
worksheet = sh.worksheet('FD_Stacks')
|
| 85 |
-
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 86 |
-
raw_display = load_display
|
| 87 |
-
|
| 88 |
-
return raw_display
|
| 89 |
|
| 90 |
@st.cache_data
|
| 91 |
def convert_df_to_csv(df):
|
| 92 |
return df.to_csv().encode('utf-8')
|
| 93 |
|
| 94 |
-
player_stats =
|
| 95 |
-
dk_roo_raw = load_dk_player_projections()
|
| 96 |
-
fd_roo_raw = load_fd_player_projections()
|
| 97 |
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 98 |
-
site_slates = set_slate_teams()
|
| 99 |
col1, col2 = st.columns([1, 5])
|
| 100 |
|
| 101 |
tab1, tab2 = st.tabs(['Uploads and Info', 'Stack Finder'])
|
|
@@ -123,11 +101,8 @@ with tab2:
|
|
| 123 |
st.info(t_stamp)
|
| 124 |
if st.button("Load/Reset Data", key='reset1'):
|
| 125 |
st.cache_data.clear()
|
| 126 |
-
player_stats =
|
| 127 |
-
dk_roo_raw = load_dk_player_projections()
|
| 128 |
-
fd_roo_raw = load_fd_player_projections()
|
| 129 |
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 130 |
-
site_slates = set_slate_teams()
|
| 131 |
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate', 'User'), key='slate_var1')
|
| 132 |
site_var1 = st.radio("What site are you playing?", ('Draftkings', 'Fanduel'), key='site_var1')
|
| 133 |
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
st.set_page_config(layout="wide")
|
| 3 |
import numpy as np
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
import gspread
|
| 6 |
+
import pymongo
|
| 7 |
+
import streamlit as st
|
| 8 |
from itertools import combinations
|
| 9 |
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def init_conn():
|
| 12 |
+
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
| 13 |
|
| 14 |
+
credentials = {
|
| 15 |
+
"type": "service_account",
|
| 16 |
+
"project_id": "model-sheets-connect",
|
| 17 |
+
"private_key_id": "0e0bc2fdef04e771172fe5807392b9d6639d945e",
|
| 18 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23nZK3ZVvADYy8u/RUn/EDI82QKxTd/DizRLIV81JiNQ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m8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
|
| 19 |
+
"client_email": "gspread-connection@model-sheets-connect.iam.gserviceaccount.com",
|
| 20 |
+
"client_id": "100369174533302798535",
|
| 21 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 22 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 23 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 24 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
| 25 |
+
}
|
| 26 |
+
uri = "mongodb+srv://multichem:Xr1q5wZdXPbxdUmJ@testcluster.lgwtp5i.mongodb.net/?retryWrites=true&w=majority&appName=TestCluster"
|
| 27 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 28 |
+
db = client["testing_db"]
|
| 29 |
+
|
| 30 |
+
MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
|
| 31 |
|
| 32 |
+
gc_con = gspread.service_account_from_dict(credentials, scope)
|
| 33 |
|
| 34 |
+
return gc_con, db, MLB_Data
|
| 35 |
+
|
| 36 |
+
gc, db, MLB_Data = init_conn()
|
| 37 |
|
| 38 |
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
| 39 |
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
|
|
|
| 43 |
|
| 44 |
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348'
|
| 45 |
|
| 46 |
+
@st.cache_data(ttl = 599)
|
| 47 |
+
def init_baselines():
|
| 48 |
sh = gc.open_by_url(all_dk_player_projections)
|
| 49 |
worksheet = sh.worksheet('Site_Info')
|
| 50 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 51 |
+
site_slates = raw_display
|
| 52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
worksheet = sh.worksheet('Player_Projections')
|
| 54 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 55 |
+
player_stats = raw_display
|
| 56 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
worksheet = sh.worksheet('DK_ROO')
|
| 58 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 59 |
load_display.replace('', np.nan, inplace=True)
|
| 60 |
raw_display = load_display.dropna(subset=['Median'])
|
| 61 |
+
dk_roo_raw = raw_display
|
| 62 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
worksheet = sh.worksheet('FD_ROO')
|
| 64 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 65 |
load_display.replace('', np.nan, inplace=True)
|
| 66 |
raw_display = load_display.dropna(subset=['Median'])
|
| 67 |
+
fd_roo_raw = raw_display
|
| 68 |
|
| 69 |
+
return site_slates, player_stats, dk_roo_raw, fd_roo_raw
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
@st.cache_data
|
| 72 |
def convert_df_to_csv(df):
|
| 73 |
return df.to_csv().encode('utf-8')
|
| 74 |
|
| 75 |
+
site_slates, player_stats, dk_roo_raw, fd_roo_raw = init_baselines()
|
|
|
|
|
|
|
| 76 |
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
|
|
|
| 77 |
col1, col2 = st.columns([1, 5])
|
| 78 |
|
| 79 |
tab1, tab2 = st.tabs(['Uploads and Info', 'Stack Finder'])
|
|
|
|
| 101 |
st.info(t_stamp)
|
| 102 |
if st.button("Load/Reset Data", key='reset1'):
|
| 103 |
st.cache_data.clear()
|
| 104 |
+
site_slates, player_stats, dk_roo_raw, fd_roo_raw = init_baselines()
|
|
|
|
|
|
|
| 105 |
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
|
|
|
| 106 |
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate', 'User'), key='slate_var1')
|
| 107 |
site_var1 = st.radio("What site are you playing?", ('Draftkings', 'Fanduel'), key='site_var1')
|
| 108 |
|