File size: 47,002 Bytes
2c0c3ee
 
 
 
 
 
 
1329302
 
 
 
4713c08
2c0c3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15d8a95
e799097
 
0f6b2d0
e745b1f
b8fd314
15d8a95
cc23ed9
 
1ac5e91
7044d1d
 
 
 
 
 
 
 
 
 
 
 
f1a67c9
cc23ed9
4208f4a
7044d1d
 
8bf2b61
f720f63
2c0c3ee
3677719
2c0c3ee
1329302
75af7be
717529b
75af7be
1329302
2c0c3ee
1329302
4713c08
bcdcf6e
eae0f4b
 
 
 
 
 
 
 
 
be87652
cc34b57
 
 
2c0c3ee
 
 
1329302
2c0c3ee
1329302
4713c08
3813258
22439ab
 
 
 
 
1329302
cc34b57
 
 
 
 
 
eae0f4b
 
1329302
2c0c3ee
 
 
eae0f4b
4713c08
1329302
eae0f4b
1329302
 
4713c08
 
1329302
eae0f4b
2c0c3ee
4713c08
 
 
2c0c3ee
15d8a95
 
4713c08
2c0c3ee
15d8a95
4713c08
 
1329302
4713c08
 
2c0c3ee
4713c08
 
1329302
 
 
4713c08
 
1329302
eae0f4b
2c0c3ee
4713c08
 
2c0c3ee
4713c08
2c0c3ee
 
fcbf3e4
 
 
1329302
4713c08
2c0c3ee
 
4713c08
1329302
2c0c3ee
1329302
dab3604
2bbbebc
dab3604
eae0f4b
dab3604
 
 
 
 
 
2bbbebc
e3f7150
 
 
dab3604
 
 
 
 
 
 
 
 
 
4713c08
2bbbebc
4713c08
eae0f4b
2c0c3ee
4713c08
 
 
 
 
 
 
 
2c0c3ee
2df260c
2c0c3ee
4713c08
 
2c0c3ee
 
2df260c
 
2c0c3ee
 
 
 
 
4713c08
2c0c3ee
4713c08
2c0c3ee
 
 
 
 
 
 
 
 
4713c08
 
 
 
 
 
 
2c0c3ee
4713c08
 
 
 
 
 
 
 
2c0c3ee
 
2df260c
7508147
2c0c3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4713c08
 
2c0c3ee
 
 
4713c08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dab3604
4713c08
97af186
4713c08
1329302
eae0f4b
2c0c3ee
1329302
 
 
 
 
 
 
 
 
e43db7d
 
 
 
 
 
 
 
 
 
 
8990830
e43db7d
34b0b01
b1505ef
 
 
1329302
 
 
 
b1505ef
a31528c
 
e43db7d
22439ab
9e8aff0
bec6bfd
 
a31528c
 
 
 
 
 
 
 
 
 
 
 
 
b1505ef
a31528c
 
 
 
 
 
 
 
 
34b0b01
 
a31528c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8fd314
a31528c
 
 
b8fd314
a31528c
496250b
 
 
a31528c
b1505ef
e43db7d
97bfc45
9e8aff0
97bfc45
 
a31528c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34b0b01
 
 
 
 
 
 
 
 
a31528c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34b0b01
 
a31528c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1329302
b1505ef
1329302
 
 
 
 
 
 
 
 
 
2c0c3ee
1329302
 
eae0f4b
 
 
 
 
 
 
 
 
 
 
 
47ed0c2
85ba362
8bf2b61
 
 
 
85ba362
8bf2b61
85ba362
4208f4a
eae0f4b
 
 
 
 
 
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
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
import plotly.express as px
import random
import gc

@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": "model-sheets-connect",
          "private_key_id": "0e0bc2fdef04e771172fe5807392b9d6639d945e",
          "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",
          "client_email": "gspread-connection@model-sheets-connect.iam.gserviceaccount.com",
          "client_id": "100369174533302798535",
          "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%40model-sheets-connect.iam.gserviceaccount.com"
        }

        gc_con = gspread.service_account_from_dict(credentials)
      
        return gc_con

gcservice_account = init_conn()

master_hold = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=853878325'

game_format = {'Win%': '{:.2%}'}
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%}'}
prop_table_options = ['points', 'threes', 'rebounds', 'assists', 'blocks', 'steals', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
all_sim_vars = ['points', 'rebounds', 'assists', 'threes', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
sim_all_hold = pd.DataFrame(columns=['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])

def add_column(df):
    return_df = df
    return_df['2P'] = return_df["Minutes"] * return_df["FG2M"]
    return_df['3P'] = return_df["Minutes"] * return_df["Threes"]
    return_df['FT'] = return_df["Minutes"] * return_df["FTM"]
    return_df['Points'] = (return_df["2P"] * 2) + (return_df["3P"] * 3) + return_df['FT']
    return_df['Rebounds'] = return_df["Minutes"] * return_df["TRB"]
    return_df['Assists'] = return_df["Minutes"] * return_df["AST"]
    return_df['PRA'] = return_df['Points'] + return_df['Rebounds'] + return_df['Assists']
    return_df['PR'] = return_df['Points'] + return_df['Rebounds']
    return_df['PA'] = return_df['Points'] + return_df['Assists']
    return_df['RA'] = return_df['Rebounds'] + return_df['Assists']
    return_df['Steals'] = return_df["Minutes"] * return_df["STL"]
    return_df['Blocks'] = return_df["Minutes"] * return_df["BLK"]
    return_df['Turnovers'] = return_df["Minutes"] * return_df["TOV"]
    return_df['Fantasy'] = (return_df["2P"] * 3) + (return_df["3P"] * 3.5) + return_df['FT'] + (return_df["Rebounds"] * 1.25) + (return_df["Assists"] * 1.5) + (return_df["Steals"] * 2) + (return_df["Blocks"] * 2) + (return_df["Turnovers"] * -.5)
    
    export_df = return_df[['Player', 'Position', 'Team', 'Opp', 'Minutes', '2P', '3P', 'FT', 'Points', 'Rebounds', 'Assists', 'PRA', 'PR', 'PA', 'RA', 'Steals', 'Blocks', 'Turnovers', 'Fantasy']]
    
    return export_df

@st.cache_resource(ttl = 299)
def init_baselines():
    sh = gcservice_account.open_by_url(master_hold)
    worksheet = sh.worksheet('Betting Model Clean')
    raw_display = pd.DataFrame(worksheet.get_all_records())
    raw_display.replace('#DIV/0!', np.nan, inplace=True)
    raw_display['Win%'] = raw_display['Win%'].replace({'%': ''}, regex=True).astype(float) / 100
    game_model = raw_display.dropna()

    worksheet = sh.worksheet('DK_Build_Up')
    raw_display = pd.DataFrame(worksheet.get_all_records())
    raw_display.replace('', np.nan, inplace=True)
    raw_display.rename(columns={"Name": "Player"}, inplace = True)
    
    raw_baselines = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', 'FGM', 'FGA', 'FG2M', 'FG2A', 'Threes', 'FG3A', 'FTM', 'FTA', 'TRB', 'AST', 'STL', 'BLK', 'TOV']]
    raw_baselines = raw_baselines[raw_baselines['Minutes'] > 0]
    raw_baselines['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
                                 ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
                                  'Trey Murphy III', 'Cam Thomas'], inplace=True)
    
    player_stats = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', '3P', 'Points', 'Rebounds', 'Assists', 'Steals', 'Blocks', 'Turnovers', 'Fantasy']]
    player_stats = player_stats[player_stats['Minutes'] > 0]

    player_stats['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
                                 ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
                                  'Trey Murphy III', 'Cam Thomas'], inplace=True)
    
    worksheet = sh.worksheet('Timestamp')
    timestamp = worksheet.acell('A1').value

    worksheet = sh.worksheet('Prop_Frame')
    raw_display = pd.DataFrame(worksheet.get_all_records())
    raw_display.replace('', np.nan, inplace=True)
    prop_frame = raw_display.dropna(subset='Player')
    
    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')

    prop_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
                                 ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
                                  'Trey Murphy III', 'Cam Thomas'], inplace=True)
    pick_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
                                 ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
                                  'Trey Murphy III', 'Cam Thomas'], inplace=True)
    
    return game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp

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

game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
t_stamp = f"Last Update: " + str(timestamp) + f" CST"

tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Game Betting Model", "Player Projections", "Prop Trend Table", "Player Prop Simulations", "Stat Specific Simulations", "Testing"])

with tab1:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset1'):
              st.cache_data.clear()
              game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
              t_stamp = f"Last Update: " + str(timestamp) + f" CST"
    line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
    team_frame = game_model
    if line_var1 == 'Percentage':
        team_frame = team_frame[['Team', 'Opp', 'Team Points', 'Opp Points', 'Proj Total', 'Proj Spread', 'Proj Winner', 'Win%']]
        team_frame = team_frame.set_index('Team')
        st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
    if line_var1 == 'American':
        team_frame = team_frame[['Team', 'Opp', 'Team Points', 'Opp Points', 'Proj Total', 'Proj Spread', 'Proj Winner', 'Odds Line']]
        team_frame = team_frame.set_index('Team')
        st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
    
    st.download_button(
        label="Export Team Model",
        data=convert_df_to_csv(team_frame),
        file_name='NBA_team_betting_export.csv',
        mime='text/csv',
        key='team_export',
    )

with tab2:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset2'):
              st.cache_data.clear()
              game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
              t_stamp = f"Last Update: " + str(timestamp) + f" CST"
    split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
    if split_var1 == 'Specific Teams':
        team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var1')
    elif split_var1 == 'All':
        team_var1 = player_stats.Team.values.tolist()
    player_stats = player_stats[player_stats['Team'].isin(team_var1)]
    player_stats_disp = player_stats.set_index('Player')
    player_stats_disp = player_stats_disp.sort_values(by='Fantasy', ascending=False)
    st.dataframe(player_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
    st.download_button(
        label="Export Prop Model",
        data=convert_df_to_csv(player_stats),
        file_name='NBA_stats_export.csv',
        mime='text/csv',
    )
    
with tab3:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset3'):
              st.cache_data.clear()
              game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_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 = player_stats['Team'].unique(), key='team_var5')
    elif split_var5 == 'All':
        team_var5 = player_stats.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_frame[prop_frame['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),
        file_name='NBA_prop_trends_export.csv',
        mime='text/csv',
    )
    
with tab4:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset4'):
              st.cache_data.clear()
              game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_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()
    
    with col1:
        player_check = st.selectbox('Select player to simulate props', options = player_stats['Player'].unique())
        prop_type_var = st.selectbox('Select type of prop to simulate', options = ['points', 'threes', 'rebounds', 'assists', 'blocks', 'steals',
                                                                                   'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists'])

        ou_var = st.selectbox('Select wether it is an over or under', options = ['Over', 'Under'])
        if prop_type_var == 'points':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 15.5, step = .5)
        elif prop_type_var == 'threes':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
        elif prop_type_var == 'rebounds':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 25.5, value = 5.5, step = .5)
        elif prop_type_var == 'assists':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 25.5, value = 5.5, step = .5)
        elif prop_type_var == 'blocks':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
        elif prop_type_var == 'steals':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
        elif prop_type_var == 'PRA':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 65.5, value = 20.5, step = .5)
        elif prop_type_var == 'points+rebounds':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
        elif prop_type_var == 'points+assists':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
        elif prop_type_var == 'rebounds+assists':
            prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
        line_var = st.number_input('Type in the line on the prop (i.e. -120)', min_value = -1500, max_value = 1500, value = -150, step = 1)
        line_var = line_var + 1

        if st.button('Simulate Prop'):
            with col2:
                   
                    with df_hold_container.container():

                        df = player_stats

                        total_sims = 5000

                        df.replace("", 0, inplace=True)

                        player_var = df.loc[df['Player'] == player_check]
                        player_var = player_var.reset_index()

                        if prop_type_var == 'points':
                            df['Median'] = df['Points']
                        elif prop_type_var == 'threes':
                            df['Median'] = df['3P']
                        elif prop_type_var == 'rebounds':
                            df['Median'] = df['Rebounds']
                        elif prop_type_var == 'assists':
                            df['Median'] = df['Assists']
                        elif prop_type_var == 'blocks':
                            df['Median'] = df['Blocks']
                        elif prop_type_var == 'steals':
                            df['Median'] = df['Steals']
                        elif prop_type_var == 'PRA':
                            df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
                        elif prop_type_var == 'points+rebounds':
                            df['Median'] = df['Points'] + df['Rebounds']
                        elif prop_type_var == 'points+assists':
                            df['Median'] = df['Points'] + df['Assists']
                        elif prop_type_var == 'rebounds+assists':
                            df['Median'] = df['Assists'] + df['Rebounds']

                        flex_file = df
                        flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
                        flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
                        flex_file['STD'] = (flex_file['Median']/4)
                        flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]

                        hold_file = flex_file
                        overall_file = flex_file
                        salary_file = flex_file

                        overall_players = overall_file[['Player']]

                        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', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
                        overall_file.astype('int').dtypes

                        players_only = hold_file[['Player']]

                        player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)

                        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)
                        if ou_var == 'Over':
                            players_only['beat_prop'] = overall_file[overall_file > prop_var].count(axis=1)/float(total_sims)
                        elif ou_var == 'Under':
                            players_only['beat_prop'] = (overall_file[overall_file < prop_var].count(axis=1)/float(total_sims))

                        players_only['implied_odds'] = np.where(line_var <= 0, (-(line_var)/((-(line_var))+100)), 100/(line_var+100))

                        players_only['Player'] = hold_file[['Player']]

                        final_outcomes = players_only[['Player', '10%', 'Mean_Outcome', '90%', 'implied_odds', 'beat_prop']]
                        final_outcomes['Bet?'] = np.where(final_outcomes['beat_prop'] - final_outcomes['implied_odds'] >= .10, "Bet", "No Bet")
                        final_outcomes = final_outcomes.loc[final_outcomes['Player'] == player_check]
                        player_outcomes = player_outcomes.loc[player_outcomes['Player'] == player_check]
                        player_outcomes = player_outcomes.drop(columns=['Player']).transpose()
                        player_outcomes = player_outcomes.reset_index()
                        player_outcomes.columns = ['Instance', 'Outcome']

                        x1 = player_outcomes.Outcome.to_numpy()

                        print(x1)

                        hist_data = [x1]

                        group_labels = ['player outcomes']

                        fig = px.histogram(
                                player_outcomes, x='Outcome')
                        fig.add_vline(x=prop_var, line_dash="dash", line_color="green")

                        with df_hold_container:
                            df_hold_container = st.empty()
                            format_dict = {'10%': '{:.2f}', 'Mean_Outcome': '{:.2f}','90%': '{:.2f}', 'beat_prop': '{:.2%}','implied_odds': '{:.2%}'}
                            st.dataframe(final_outcomes.style.format(format_dict), use_container_width = True)

                        with info_hold_container:
                            st.info('The Y-axis is the percent of times in simulations that the player reaches certain thresholds, while the X-axis is the threshold to be met. The Green dotted line is the prop you entered. You can hover over any spot and see the percent to reach that mark.')

                        with plot_hold_container:
                            st.dataframe(player_outcomes, use_container_width = True)
                            plot_hold_container = st.empty()
                            st.plotly_chart(fig, use_container_width=True)

with tab5:
    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()
              game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_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_frame[['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', 'points', 'rebounds', 'assists', 'threes', 'PRA', 'points+rebounds',
                                                                        'points+assists', 'rebounds+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_frame[['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(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                                
                                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['Points']
                                elif prop == 'rebounds':
                                    df['Median'] = df['Rebounds']
                                elif prop == 'assists':
                                    df['Median'] = df['Assists']
                                elif prop == 'threes':
                                    df['Median'] = df['3P']
                                elif prop == 'PRA':
                                    df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
                                elif prop == 'points+rebounds':
                                    df['Median'] = df['Points'] + df['Rebounds']
                                elif prop == 'points+assists':
                                    df['Median'] = df['Points'] + df['Assists']
                                elif prop == 'rebounds+assists':
                                    df['Median'] = df['Assists'] + df['Rebounds']
        
                                flex_file = df
                                flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
                                flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
                                flex_file['STD'] = (flex_file['Median']/4)
                                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']]
        
                                leg_outcomes = players_only[['Player', '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_frame[['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 == "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))
                                df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "rebounds":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds']
                                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(player_stats, 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))
                                df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "threes":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'threes']
                                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(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "PRA":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'PRA']
                                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(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "points+rebounds":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'points+rebounds']
                                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(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "points+assists":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'points+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))
                                df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            elif prop_type_var == "rebounds+assists":
                                prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds+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))
                                df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
                            
                            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_type_var == 'points':
                                df['Median'] = df['Points']
                            elif prop_type_var == 'rebounds':
                                df['Median'] = df['Rebounds']
                            elif prop_type_var == 'assists':
                                df['Median'] = df['Assists']
                            elif prop_type_var == 'threes':
                                df['Median'] = df['3P']
                            elif prop_type_var == 'PRA':
                                df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
                            elif prop_type_var == 'points+rebounds':
                                df['Median'] = df['Points'] + df['Rebounds']
                            elif prop_type_var == 'points+assists':
                                df['Median'] = df['Points'] + df['Assists']
                            elif prop_type_var == 'rebounds+assists':
                                df['Median'] = df['Assists'] + df['Rebounds']
    
                            flex_file = df
                            flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
                            flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
                            flex_file['STD'] = (flex_file['Median']/4)
                            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']]
    
                            final_outcomes = players_only[['Player', '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='Nba_prop_proj.csv',
                                mime='text/csv',
                                key='prop_proj',
                            )
with tab6:
    st.info(t_stamp)
    if st.button("Reset Data", key='reset6'):
              st.cache_data.clear()
              game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
              t_stamp = f"Last Update: " + str(timestamp) + f" CST"
    split_var6 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var6')
    if split_var6 == 'Specific Teams':
        team_var6 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var6')
    elif split_var6 == 'All':
        team_var6 = player_stats.Team.values.tolist()
    raw_stats_disp = raw_baselines[raw_baselines['Team'].isin(team_var6)]
    st.header("Baselines to adjust")
    editable_df = st.data_editor(
        raw_stats_disp,
        key="data",
        hide_index=True,
        use_container_width = True
    )
    st.header("Customized Projections")
    st.dataframe(add_column(editable_df).style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
    st.download_button(
        label="Export Customizable Model",
        data=convert_df_to_csv(player_stats),
        file_name='NBA_stats_export.csv',
        mime='text/csv',
    )