Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,42 +18,13 @@ from time import sleep as time_sleep
|
|
| 18 |
|
| 19 |
@st.cache_resource
|
| 20 |
def init_conn():
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"private_key_id": st.secrets['model_sheets_connect_pk'],
|
| 27 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23nZK3ZVvADYy8u/RUn/EDI82QKxTd/DizRLIV81JiNQxDJXSzgkbwKYEDm\n48E8zGvupU8+Nk76xNPakrQKy2Y8+VJlq5psBtGchJTuUSHcXU5Mg2JhQsB376PJ\nsCw552K6Pw8fpeMDJDZuxpKSkaJR6k9G5Dhf5q8HDXnC5Rh/PRFuKJ2GGRpX7n+2\nhT/sCax0J8jfdTy/MDGiDfJqfQrOPrMKELtsGHR9Iv6F4vKiDqXpKfqH+02E9ptz\nBk+MNcbZ3m90M8ShfRu28ebebsASfarNMzc3dk7tb3utHOGXKCf4tF8yYKo7x8BZ\noO9X4gSfAgMBAAECggEAU8ByyMpSKlTCF32TJhXnVJi/kS+IhC/Qn5JUDMuk4LXr\naAEWsWO6kV/ZRVXArjmuSzuUVrXumISapM9Ps5Ytbl95CJmGDiLDwRL815nvv6k3\nUyAS8EGKjz74RpoIoH6E7EWCAzxlnUgTn+5oP9Flije97epYk3H+e2f1f5e1Nn1d\nYNe8U+1HqJgILcxA1TAUsARBfoD7+K3z/8DVPHI8IpzAh6kTHqhqC23Rram4XoQ6\nzj/ZdVBjvnKuazETfsD+Vl3jGLQA8cKQVV70xdz3xwLcNeHsbPbpGBpZUoF73c65\nkAXOrjYl0JD5yAk+hmYhXr6H9c6z5AieuZGDrhmlFQKBgQDzV6LRXmjn4854DP/J\nI82oX2GcI4eioDZPRukhiQLzYerMQBmyqZIRC+/LTCAhYQSjNgMa+ZKyvLqv48M0\n/x398op/+n3xTs+8L49SPI48/iV+mnH7k0WI/ycd4OOKh8rrmhl/0EWb9iitwJYe\nMjTV/QxNEpPBEXfR1/mvrN/lVQKBgQDuhomOxUhWVRVH6x03slmyRBn0Oiw4MW+r\nrt1hlNgtVmTc5Mu+4G0USMZwYuOB7F8xG4Foc7rIlwS7Ic83jMJxemtqAelwOLdV\nXRLrLWJfX8+O1z/UE15l2q3SUEnQ4esPHbQnZowHLm0mdL14qSVMl1mu1XfsoZ3z\nJZTQb48CIwKBgEWbzQRtKD8lKDupJEYqSrseRbK/ax43DDITS77/DWwHl33D3FYC\nMblUm8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
|
| 28 |
-
"client_email": "gspread-connection@model-sheets-connect.iam.gserviceaccount.com",
|
| 29 |
-
"client_id": "100369174533302798535",
|
| 30 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 31 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 32 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 33 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
credentials2 = {
|
| 37 |
-
"type": "service_account",
|
| 38 |
-
"project_id": "sheets-api-connect-378620",
|
| 39 |
-
"private_key_id": st.secrets['sheets_api_connect_pk'],
|
| 40 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5EvqkZvSyMJHV0EEahZStwhjCfnDB/cxyix\nZ+kFhv4y9eK+kFpUAhBy5nX6T0O+2T6WvzAwbmbVsZ+X8kJyPuF9m8ldcPlD0sce\ntj8NwVq1ys52eosqs7zi2vjt+eMcaY393l4ls+vNq8Yf27cfyFw45W45CH/97/Nu\n5AmuzlCOAfFF+z4OC5g4rei4E/Qgpxa7/uom+BVfv9G0DIGW/tU6Sne0+37uoGKt\nW6DzhgtebUtoYkG7ZJ05BTXGp2lwgVcNRoPwnKJDxQKBgQDT5wYPUBDW+FHbvZSp\nd1m1UQuXyerqOTA9smFaM8sr/UraeH85DJPEIEk8qsntMBVMhvD3Pw8uIUeFNMYj\naLmZFObsL+WctepXrVo5NB6RtLB/jZYxiKMatMLUJIYtcKIp+2z/YtKiWcLnwotB\nWdCjVnPTxpkurmF2fWP/eewZ+wKBgQDRMtJg7etjvKyjYNQ5fARnCc+XsI3gkBe1\nX9oeXfhyfZFeBXWnZzN1ITgFHplDznmBdxAyYGiQdbbkdKQSghviUQ0igBvoDMYy\n1rWcy+a17Mj98uyNEfmb3X2cC6WpvOZaGHwg9+GY67BThwI3FqHIbyk6Ko09WlTX\nQpRQjMzU7QKBgAfi1iflu+q0LR+3a3vvFCiaToskmZiD7latd9AKk2ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
| 41 |
-
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
| 42 |
-
"client_id": "106625872877651920064",
|
| 43 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 44 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 45 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 46 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
NHL_Data = st.secrets['NHL_Data']
|
| 50 |
-
|
| 51 |
-
gc = gspread.service_account_from_dict(credentials)
|
| 52 |
-
gc2 = gspread.service_account_from_dict(credentials2)
|
| 53 |
-
|
| 54 |
-
return gc, gc2, NHL_Data
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
prop_table_options = ['NHL_GAME_PLAYER_SHOTS_ON_GOAL', 'NHL_GAME_PLAYER_POINTS', 'NHL_GAME_PLAYER_SHOTS_BLOCKED', 'NHL_GAME_PLAYER_ASSISTS']
|
| 59 |
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
|
@@ -64,14 +35,11 @@ sim_all_hold = pd.DataFrame(columns=['Player', 'Prop Type', 'Prop', 'Mean_Outcom
|
|
| 64 |
|
| 65 |
@st.cache_resource(ttl=200)
|
| 66 |
def pull_baselines():
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
raw_display = pd.DataFrame(
|
| 70 |
prop_display = raw_display[raw_display['Player'] != ""]
|
| 71 |
prop_display['Player Blocks'].replace("", np.nan, inplace=True)
|
| 72 |
-
prop_display['SOG Edge'].replace("", np.nan, inplace=True)
|
| 73 |
-
prop_display['Assist Edge'].replace("", np.nan, inplace=True)
|
| 74 |
-
prop_display['TP Edge'].replace("", np.nan, inplace=True)
|
| 75 |
prop_table = prop_display[['Player', 'Position', 'Team', 'Opp', 'Team_Total', 'Player SOG', 'Player Goals', 'Player Assists',
|
| 76 |
'Player TP', 'Player Blocks', 'Player Saves']]
|
| 77 |
prop_table['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
|
|
@@ -82,26 +50,27 @@ def pull_baselines():
|
|
| 82 |
for stat in stat_columns:
|
| 83 |
prop_table[stat] = prop_table[stat].astype(float)
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
|
|
|
| 87 |
raw_display.replace('', np.nan, inplace=True)
|
| 88 |
prop_trends = raw_display.dropna(subset='Player')
|
| 89 |
prop_trends['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
|
| 90 |
['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
| 94 |
raw_display.replace('', np.nan, inplace=True)
|
| 95 |
pick_frame = raw_display.dropna(subset='Player')
|
| 96 |
pick_frame['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
|
| 97 |
['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
|
|
|
|
| 98 |
|
| 99 |
team_dict = dict(zip(prop_table['Player'], prop_table['Team']))
|
| 100 |
-
|
| 101 |
-
worksheet = sh.worksheet('Timestamp')
|
| 102 |
-
timestamp = worksheet.acell('A1').value
|
| 103 |
|
| 104 |
-
return prop_table, prop_trends, pick_frame,
|
| 105 |
|
| 106 |
def calculate_poisson(row):
|
| 107 |
mean_val = row['Mean_Outcome']
|
|
@@ -113,8 +82,7 @@ def calculate_poisson(row):
|
|
| 113 |
def convert_df_to_csv(df):
|
| 114 |
return df.to_csv().encode('utf-8')
|
| 115 |
|
| 116 |
-
prop_display, prop_trends, pick_frame,
|
| 117 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 118 |
|
| 119 |
tab1, tab2, tab3 = st.tabs(["Player Stat Table", 'Prop Trend Table', 'Stat Specific Simulations'])
|
| 120 |
|
|
@@ -122,7 +90,7 @@ with tab1:
|
|
| 122 |
st.info(t_stamp)
|
| 123 |
if st.button("Reset Data", key='reset1'):
|
| 124 |
st.cache_data.clear()
|
| 125 |
-
prop_display, prop_trends, pick_frame,
|
| 126 |
prop_frame = prop_display
|
| 127 |
st.dataframe(prop_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 128 |
|
|
@@ -138,8 +106,7 @@ with tab2:
|
|
| 138 |
st.info(t_stamp)
|
| 139 |
if st.button("Reset Data", key='reset3'):
|
| 140 |
st.cache_data.clear()
|
| 141 |
-
prop_display, prop_trends, pick_frame,
|
| 142 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 143 |
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
| 144 |
if split_var5 == 'Specific Teams':
|
| 145 |
team_var5 = st.multiselect('Which teams would you like to include in the tables?', options = prop_trends['Team'].unique(), key='team_var5')
|
|
@@ -168,8 +135,7 @@ with tab3:
|
|
| 168 |
st.info('The Over and Under percentages are a composite percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
| 169 |
if st.button("Reset Data/Load Data", key='reset5'):
|
| 170 |
st.cache_data.clear()
|
| 171 |
-
prop_display, prop_trends, pick_frame,
|
| 172 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 173 |
|
| 174 |
settings_container = st.container()
|
| 175 |
df_hold_container = st.empty()
|
|
|
|
| 18 |
|
| 19 |
@st.cache_resource
|
| 20 |
def init_conn():
|
| 21 |
+
uri = st.secrets['mongo_uri']
|
| 22 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 23 |
+
db = client["NHL_Database"]
|
| 24 |
+
|
| 25 |
+
return db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
db = init_conn()
|
| 28 |
|
| 29 |
prop_table_options = ['NHL_GAME_PLAYER_SHOTS_ON_GOAL', 'NHL_GAME_PLAYER_POINTS', 'NHL_GAME_PLAYER_SHOTS_BLOCKED', 'NHL_GAME_PLAYER_ASSISTS']
|
| 30 |
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
|
|
|
| 35 |
|
| 36 |
@st.cache_resource(ttl=200)
|
| 37 |
def pull_baselines():
|
| 38 |
+
collection = db["Prop_Betting_Table"]
|
| 39 |
+
cursor = collection.find()
|
| 40 |
+
raw_display = pd.DataFrame(cursor)
|
| 41 |
prop_display = raw_display[raw_display['Player'] != ""]
|
| 42 |
prop_display['Player Blocks'].replace("", np.nan, inplace=True)
|
|
|
|
|
|
|
|
|
|
| 43 |
prop_table = prop_display[['Player', 'Position', 'Team', 'Opp', 'Team_Total', 'Player SOG', 'Player Goals', 'Player Assists',
|
| 44 |
'Player TP', 'Player Blocks', 'Player Saves']]
|
| 45 |
prop_table['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
|
|
|
|
| 50 |
for stat in stat_columns:
|
| 51 |
prop_table[stat] = prop_table[stat].astype(float)
|
| 52 |
|
| 53 |
+
collection = db["prop_trends"]
|
| 54 |
+
cursor = collection.find()
|
| 55 |
+
raw_display = pd.DataFrame(cursor)
|
| 56 |
raw_display.replace('', np.nan, inplace=True)
|
| 57 |
prop_trends = raw_display.dropna(subset='Player')
|
| 58 |
prop_trends['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
|
| 59 |
['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
|
| 60 |
+
prop_trends = prop_trends.drop(columns=['_id', 'index'])
|
| 61 |
|
| 62 |
+
collection = db["Pick6_ingest"]
|
| 63 |
+
cursor = collection.find()
|
| 64 |
+
raw_display = pd.DataFrame(cursor)
|
| 65 |
raw_display.replace('', np.nan, inplace=True)
|
| 66 |
pick_frame = raw_display.dropna(subset='Player')
|
| 67 |
pick_frame['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
|
| 68 |
['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
|
| 69 |
+
pick_frame = pick_frame.drop(columns=['_id', 'index'])
|
| 70 |
|
| 71 |
team_dict = dict(zip(prop_table['Player'], prop_table['Team']))
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
return prop_table, prop_trends, pick_frame, team_dict
|
| 74 |
|
| 75 |
def calculate_poisson(row):
|
| 76 |
mean_val = row['Mean_Outcome']
|
|
|
|
| 82 |
def convert_df_to_csv(df):
|
| 83 |
return df.to_csv().encode('utf-8')
|
| 84 |
|
| 85 |
+
prop_display, prop_trends, pick_frame, team_dict = pull_baselines()
|
|
|
|
| 86 |
|
| 87 |
tab1, tab2, tab3 = st.tabs(["Player Stat Table", 'Prop Trend Table', 'Stat Specific Simulations'])
|
| 88 |
|
|
|
|
| 90 |
st.info(t_stamp)
|
| 91 |
if st.button("Reset Data", key='reset1'):
|
| 92 |
st.cache_data.clear()
|
| 93 |
+
prop_display, prop_trends, pick_frame, team_dict = pull_baselines()
|
| 94 |
prop_frame = prop_display
|
| 95 |
st.dataframe(prop_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 96 |
|
|
|
|
| 106 |
st.info(t_stamp)
|
| 107 |
if st.button("Reset Data", key='reset3'):
|
| 108 |
st.cache_data.clear()
|
| 109 |
+
prop_display, prop_trends, pick_frame, team_dict = pull_baselines()
|
|
|
|
| 110 |
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
| 111 |
if split_var5 == 'Specific Teams':
|
| 112 |
team_var5 = st.multiselect('Which teams would you like to include in the tables?', options = prop_trends['Team'].unique(), key='team_var5')
|
|
|
|
| 135 |
st.info('The Over and Under percentages are a composite percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
| 136 |
if st.button("Reset Data/Load Data", key='reset5'):
|
| 137 |
st.cache_data.clear()
|
| 138 |
+
prop_display, prop_trends, pick_frame, team_dict = pull_baselines()
|
|
|
|
| 139 |
|
| 140 |
settings_container = st.container()
|
| 141 |
df_hold_container = st.empty()
|