File size: 27,811 Bytes
6fe8715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a5a3f1
 
 
 
 
6fe8715
aaa98a9
6fe8715
 
 
 
b93cb59
3b90fa6
01460fc
 
 
da1160a
 
8eb2700
 
ff585c2
6fe8715
8a5a3f1
 
 
 
8eb2700
 
8a5a3f1
ce44ad1
 
 
 
 
 
 
fe6597f
 
6fe8715
 
 
ce44ad1
6fe8715
 
 
 
ce44ad1
8958900
6fe8715
8a5a3f1
6fe8715
 
8958900
6fe8715
 
ce44ad1
6fe8715
 
 
 
a123bdd
6fe8715
 
 
a123bdd
6fe8715
 
 
8a5a3f1
 
 
ce44ad1
8a5a3f1
 
 
 
 
 
 
 
 
 
 
 
 
 
161a311
8a5a3f1
 
 
 
 
 
 
 
 
ce44ad1
8a5a3f1
 
 
 
 
 
 
 
 
 
ce44ad1
 
 
 
 
 
 
 
 
 
 
 
 
8a5a3f1
 
 
 
 
 
 
 
 
 
c816c37
 
 
 
 
8a5a3f1
 
 
 
 
 
 
 
8939390
8a5a3f1
8d05170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a5a3f1
 
 
 
a18e2f3
7dd5e48
a18e2f3
 
 
 
8a5a3f1
 
 
 
 
 
 
4e8fdc8
8a5a3f1
 
 
 
 
 
 
 
 
4e8fdc8
8a5a3f1
 
 
 
 
 
 
 
 
4e8fdc8
8a5a3f1
 
 
 
 
 
 
 
 
4e8fdc8
8a5a3f1
 
f3bf5f2
8a5a3f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe6597f
8a5a3f1
fe6597f
8a5a3f1
 
 
 
 
 
 
 
 
 
 
 
161a311
8a5a3f1
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
import streamlit as st
st.set_page_config(layout="wide")

for name in dir():
    if not name.startswith('_'):
        del globals()[name]

import numpy as np
import pandas as pd
import streamlit as st
import gspread

@st.cache_resource
def init_conn():
          scope = ['https://www.googleapis.com/auth/spreadsheets',
                    "https://www.googleapis.com/auth/drive"]
          
          credentials = {
            "type": "service_account",
            "project_id": "sheets-api-connect-378620",
            "private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
            "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",
            "client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
            "client_id": "106625872877651920064",
            "auth_uri": "https://accounts.google.com/o/oauth2/auth",
            "token_uri": "https://oauth2.googleapis.com/token",
            "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
            "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
          }

          gc = gspread.service_account_from_dict(credentials)
          return gc

gspreadcon = init_conn()

master_hold = 'https://docs.google.com/spreadsheets/d/1NmKa-b-2D3w7rRxwMPSchh31GKfJ1XcDI2GU8rXWnHI/edit#gid=195454038'
prop_table_options = ['SOG', 'points', 'blocked_shots', 'assists']
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
               'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
all_sim_vars = ['SOG', 'points', 'blocked_shots', 'assists']
sim_all_hold = pd.DataFrame(columns=['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])

@st.cache_resource(ttl=300)
def pull_baselines():
    sh = gspreadcon.open_by_url(master_hold)
    worksheet = sh.worksheet('Prop_Betting_Table')
    raw_display = pd.DataFrame(worksheet.get_all_records())
    prop_display = raw_display.loc[raw_display['Player'] != ""]
    prop_display['Player Blocks'].replace("", np.nan, inplace=True)
    prop_display['SOG Edge'].replace("", np.nan, inplace=True)
    prop_display['Assist Edge'].replace("", np.nan, inplace=True)
    prop_display['TP Edge'].replace("", np.nan, inplace=True)
    prop_table = prop_display[['Player', 'Position', 'Team', 'Opp', 'Team_Total', 'Player SOG', 'Player Goals', 'Player Assists',
                               'Player TP', 'Player Blocks', 'Player Saves']]
    prop_table['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
                                  ['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
    prop_table['Player'] = prop_table['Player'].str.strip()
    
    worksheet = sh.worksheet('prop_trends')
    raw_display = pd.DataFrame(worksheet.get_all_records())
    raw_display.replace('', np.nan, inplace=True)
    prop_trends = raw_display.dropna(subset='Player')
    prop_trends['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
                                  ['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
    
    worksheet = sh.worksheet('Pick6_ingest')
    raw_display = pd.DataFrame(worksheet.get_all_records())
    raw_display.replace('', np.nan, inplace=True)
    pick_frame = raw_display.dropna(subset='Player')
    pick_frame['Player'].replace(['JJ Peterka', 'Alexander Killorn', 'Matt Boldy', 'Nick Paul', 'Alex Kerfoot'],
                                  ['John-Jason Peterka', 'Alex Killorn', 'Matthew Boldy', 'Nicholas Paul', 'Alexander Kerfoot'], inplace=True)
    
    team_dict = dict(zip(prop_table['Player'], prop_table['Team']))
    
    worksheet = sh.worksheet('Timestamp')
    timestamp = worksheet.acell('A1').value

    return prop_table, prop_trends, pick_frame, timestamp, team_dict

def convert_df_to_csv(df):
    return df.to_csv().encode('utf-8')

prop_display, prop_trends, pick_frame, timestamp, team_dict = pull_baselines()
t_stamp = f"Last Update: " + str(timestamp) + f" CST"

tab1, tab2, tab3 = st.tabs(["Player Stat Table", 'Prop Trend Table', 'Stat Specific Simulations'])

with tab1:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset1'):
              st.cache_data.clear()
              prop_display, prop_trends, pick_frame, timestamp, team_dict = pull_baselines()
    prop_frame = prop_display
    st.dataframe(prop_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
    
    st.download_button(
        label="Export Table",
        data=convert_df_to_csv(prop_frame),
        file_name='NHL_prop_stat_export.csv',
        mime='text/csv',
        key='prop_export',
    )

with tab2:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset3'):
              st.cache_data.clear()
              prop_display, prop_trends, pick_frame, timestamp, team_dict = pull_baselines()
              t_stamp = f"Last Update: " + str(timestamp) + f" CST"
    split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
    if split_var5 == 'Specific Teams':
        team_var5 = st.multiselect('Which teams would you like to include in the tables?', options = prop_trends['Team'].unique(), key='team_var5')
    elif split_var5 == 'All':
        team_var5 = prop_trends.Team.values.tolist()
    prop_type_var2 = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options)
    prop_frame_disp = prop_trends[prop_trends['Team'].isin(team_var5)]
    prop_frame_disp = prop_frame_disp[prop_frame_disp['prop_type'] == prop_type_var2]
    prop_frame_disp = prop_frame_disp.set_index('Player')
    prop_frame_disp = prop_frame_disp.sort_values(by='Trending Over', ascending=False)
    st.dataframe(prop_frame_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(prop_format, precision=2), use_container_width = True)
    st.download_button(
        label="Export Prop Trends Model",
        data=convert_df_to_csv(prop_frame_disp),
        file_name='NHL_prop_trends_export.csv',
        mime='text/csv',
    )

with tab3:
    st.info(t_stamp)
    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.')
    if st.button("Reset Data/Load Data", key='reset5'):
              st.cache_data.clear()
              prop_display, prop_trends, pick_frame, timestamp, team_dict = pull_baselines()
              t_stamp = f"Last Update: " + str(timestamp) + f" CST"
    col1, col2 = st.columns([1, 5])
    
    with col2:
        df_hold_container = st.empty()
        info_hold_container = st.empty()
        plot_hold_container = st.empty()
        export_container = st.empty()
    
    with col1:
        game_select_var = st.selectbox('Select prop source', options = ['Draftkings', 'Pick6'])
        if game_select_var == 'Draftkings':
            prop_df = prop_trends[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
        elif game_select_var == 'Pick6':
            prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
            prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
        st.download_button(
            label="Download Prop Source",
            data=convert_df_to_csv(prop_df),
            file_name='Nba_prop_source.csv',
            mime='text/csv',
            key='prop_source',
        )
        prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'SOG', 'points', 'blocked_shots', 'assists'])
        if prop_type_var == 'All Props':
            st.info('please note that the All Props run can take some time, you will see progress as tables show up in the sim area to the right')

        if st.button('Simulate Prop Category'):
            with col2:
                    with df_hold_container.container():
                        if prop_type_var == 'All Props':
                            for prop in all_sim_vars:
                                
                                if game_select_var == 'Draftkings':
                                    prop_df = prop_trends[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
                                elif game_select_var == 'Pick6':
                                    prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
                                    prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
                                prop_df = prop_df.loc[prop_df['prop_type'] == prop]
                                prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
                                prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
                                prop_df = prop_df.loc[prop_df['Prop'] != 0]
                                st.table(prop_df)
                                prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
                                prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
                                df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                                if len(prop_df) > 0:
                                
                                    prop_dict = dict(zip(df.Player, df.Prop))
                                    over_dict = dict(zip(df.Player, df.Over))
                                    under_dict = dict(zip(df.Player, df.Under))
                                    
                                    total_sims = 5000
            
                                    df.replace("", 0, inplace=True)
            
                                    if prop == 'points':
                                        df['Median'] = df['Player TP']
                                    elif prop == 'SOG':
                                        df['Median'] = df['Player SOG']
                                    elif prop == 'assists':
                                        df['Median'] = df['Player Assists']
                                    elif prop == 'blocked_shots':
                                        df['Median'] = df['Player Blocks']
            
                                    flex_file = df
                                    flex_file['Floor'] = (flex_file['Median'] * .15)
                                    flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .85)
                                    flex_file['STD'] = (flex_file['Median']/3)
                                    flex_file['Prop'] = flex_file['Player'].map(prop_dict)
                                    flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
            
                                    hold_file = flex_file
                                    overall_file = flex_file
                                    prop_file = flex_file
                                          
                                    overall_players = overall_file[['Player']]
            
                                    for x in range(0,total_sims):    
                                        prop_file[x] = prop_file['Prop']
            
                                    prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
            
                                    for x in range(0,total_sims):
                                        overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
            
                                    overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
            
                                    players_only = hold_file[['Player']]
            
                                    player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
            
                                    prop_check = (overall_file - prop_file)
            
                                    players_only['Mean_Outcome'] = overall_file.mean(axis=1)
                                    players_only['10%'] = overall_file.quantile(0.1, axis=1)
                                    players_only['90%'] = overall_file.quantile(0.9, axis=1)
                                    players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
                                    players_only['Imp Over'] = players_only['Player'].map(over_dict)
                                    players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
                                    players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
                                    players_only['Imp Under'] = players_only['Player'].map(under_dict)
                                    players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
                                    players_only['Prop'] = players_only['Player'].map(prop_dict)
                                    players_only['Prop_avg'] = players_only['Prop'].mean() / 100
                                    players_only['prop_threshold'] = .10
                                    players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
                                    players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
                                    players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
                                    players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
                                    players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
                                    players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
                                    players_only['Edge'] = players_only['Bet_check']
                                    players_only['Prop type'] = prop
            
                                    players_only['Player'] = hold_file[['Player']]
                                    players_only['Team'] = players_only['Player'].map(team_dict)
            
                                    leg_outcomes = players_only[['Player', 'Team', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
                                    
                                    sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
                                
                                final_outcomes = sim_all_hold

                        elif prop_type_var != 'All Props':
                            if game_select_var == 'Draftkings':
                                prop_df = prop_trends[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
                            elif game_select_var == 'Pick6':
                                prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
                                prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
                            if prop_type_var == "SOG":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'SOG']
                                prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
                                prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
                                prop_df = prop_df.loc[prop_df['Prop'] != 0]
                                st.table(prop_df)
                                prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
                                prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
                                prop = 'SOG'
                                df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "points":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'points']
                                prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
                                prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
                                prop_df = prop_df.loc[prop_df['Prop'] != 0]
                                st.table(prop_df)
                                prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
                                prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
                                prop = 'points'
                                df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "assists":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'assists']
                                prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
                                prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
                                prop_df = prop_df.loc[prop_df['Prop'] != 0]
                                st.table(prop_df)
                                prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
                                prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
                                prop = 'assists'
                                df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "blocked_shots":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'blocked_shots']
                                prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
                                prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
                                prop_df = prop_df.loc[prop_df['Prop'] != 0]
                                st.table(prop_df)
                                prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
                                prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
                                prop = 'blocked_shots'
                                df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            
                            st.table(df)
                            prop_dict = dict(zip(df.Player, df.Prop))
                            over_dict = dict(zip(df.Player, df.Over))
                            under_dict = dict(zip(df.Player, df.Under))
                            
                            total_sims = 5000
    
                            df.replace("", 0, inplace=True)
    
                            if prop == 'points':
                                df['Median'] = df['Player TP']
                            elif prop == 'SOG':
                                df['Median'] = df['Player SOG']
                            elif prop == 'assists':
                                df['Median'] = df['Player Assists']
                            elif prop == 'blocked_shots':
                                df['Median'] = df['Player Blocks']
    
                            flex_file = df
                            flex_file['Floor'] = (flex_file['Median'] * .15)
                            flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .85)
                            flex_file['STD'] = (flex_file['Median']/3)
                            flex_file['Prop'] = flex_file['Player'].map(prop_dict)
                            flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
    
                            hold_file = flex_file
                            overall_file = flex_file
                            prop_file = flex_file
                                  
                            overall_players = overall_file[['Player']]
    
                            for x in range(0,total_sims):    
                                prop_file[x] = prop_file['Prop']
    
                            prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
    
                            for x in range(0,total_sims):
                                overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
    
                            overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
    
                            players_only = hold_file[['Player']]
    
                            player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
    
                            prop_check = (overall_file - prop_file)
    
                            players_only['Mean_Outcome'] = overall_file.mean(axis=1)
                            players_only['10%'] = overall_file.quantile(0.1, axis=1)
                            players_only['90%'] = overall_file.quantile(0.9, axis=1)
                            players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
                            players_only['Imp Over'] = players_only['Player'].map(over_dict)
                            players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
                            players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
                            players_only['Imp Under'] = players_only['Player'].map(under_dict)
                            players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
                            players_only['Prop'] = players_only['Player'].map(prop_dict)
                            players_only['Prop_avg'] = players_only['Prop'].mean() / 100
                            players_only['prop_threshold'] = .10
                            players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
                            players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
                            players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
                            players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
                            players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
                            players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
                            players_only['Edge'] = players_only['Bet_check']
    
                            players_only['Player'] = hold_file[['Player']]
                            players_only['Team'] = players_only['Player'].map(team_dict)
    
                            final_outcomes = players_only[['Player', 'Team', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
                        
                        final_outcomes = final_outcomes[final_outcomes['Prop'] > 0]
                        final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)

                        with df_hold_container:
                            df_hold_container = st.empty()
                            st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
                        with export_container:
                            export_container = st.empty()
                            st.download_button(
                                label="Export Projections",
                                data=convert_df_to_csv(final_outcomes),
                                file_name='NHL_prop_proj.csv',
                                mime='text/csv',
                                key='prop_proj',
                            )