James McCool commited on
Commit
1210272
·
1 Parent(s): 4cd9ca0

Refactor prop data handling to include 'Trending Over' and 'Trending Under' metrics in player prop simulations. Updated DataFrame structures and calculations to incorporate these new columns across various functions, enhancing the analysis of player performance trends.

Browse files
Files changed (1) hide show
  1. app.py +27 -15
app.py CHANGED
@@ -68,7 +68,7 @@ prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '
68
  prop_table_options = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
69
  all_sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
70
  pick6_sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds']
71
- sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
72
 
73
  def calculate_poisson(row):
74
  mean_val = row['Mean_Outcome']
@@ -477,9 +477,9 @@ with tab6:
477
  else:
478
  book_selections = [book_select_var]
479
  if game_select_var == 'Aggregate':
480
- prop_df = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
481
  elif game_select_var == 'Pick6':
482
- prop_df = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
483
  book_selections = ['Pick6']
484
  st.download_button(
485
  label="Download Prop Source",
@@ -500,11 +500,11 @@ with tab6:
500
  with df_hold_container.container():
501
  if prop_type_var == 'All Props':
502
  if game_select_var == 'Aggregate':
503
- prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
504
  sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS',
505
  'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_3_POINTERS_MADE']
506
  elif game_select_var == 'Pick6':
507
- prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
508
  sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds', '3-Pointers Made']
509
 
510
  player_df = player_stats.copy()
@@ -514,7 +514,7 @@ with tab6:
514
  for books in book_selections:
515
  prop_df = prop_df_raw[prop_df_raw['prop_type'] == prop]
516
  prop_df = prop_df[prop_df['book'] == books]
517
- prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
518
  prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
519
  prop_df['Over'] = 1 / prop_df['over_line']
520
  prop_df['Under'] = 1 / prop_df['under_line']
@@ -524,10 +524,14 @@ with tab6:
524
  book_dict = dict(zip(prop_df.Player, prop_df.book))
525
  over_dict = dict(zip(prop_df.Player, prop_df.Over))
526
  under_dict = dict(zip(prop_df.Player, prop_df.Under))
 
 
527
 
528
  player_df['book'] = player_df['Player'].map(book_dict)
529
  player_df['Prop'] = player_df['Player'].map(prop_dict)
530
  player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
 
 
531
 
532
  df = player_df.reset_index(drop=True)
533
 
@@ -586,15 +590,17 @@ with tab6:
586
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
587
  players_only['Book'] = players_only['Player'].map(book_dict)
588
  players_only['Prop'] = players_only['Player'].map(prop_dict)
 
 
589
  players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
590
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
591
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
592
  players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
593
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
594
- players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
595
  players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
596
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
597
- players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
598
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
599
  players_only['prop_threshold'] = .10
600
  players_only = players_only[players_only['Mean_Outcome'] > 0]
@@ -609,7 +615,7 @@ with tab6:
609
  players_only['Player'] = hold_file[['Player']]
610
  players_only['Team'] = players_only['Player'].map(team_dict)
611
 
612
- leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
613
  sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
614
 
615
  final_outcomes = sim_all_hold
@@ -620,9 +626,9 @@ with tab6:
620
  player_df = player_stats.copy()
621
 
622
  if game_select_var == 'Aggregate':
623
- prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
624
  elif game_select_var == 'Pick6':
625
- prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
626
 
627
  for books in book_selections:
628
  prop_df = prop_df_raw[prop_df_raw['book'] == books]
@@ -660,7 +666,7 @@ with tab6:
660
  elif prop_type_var == "Assists + Rebounds":
661
  prop_df = prop_df[prop_df['prop_type'] == 'Assists + Rebounds']
662
 
663
- prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
664
  prop_df = prop_df.rename(columns={"over_prop": "Prop"})
665
  prop_df['Over'] = 1 / prop_df['over_line']
666
  prop_df['Under'] = 1 / prop_df['under_line']
@@ -670,10 +676,14 @@ with tab6:
670
  book_dict = dict(zip(prop_df.Player, prop_df.book))
671
  over_dict = dict(zip(prop_df.Player, prop_df.Over))
672
  under_dict = dict(zip(prop_df.Player, prop_df.Under))
 
 
673
 
674
  player_df['book'] = player_df['Player'].map(book_dict)
675
  player_df['Prop'] = player_df['Player'].map(prop_dict)
676
  player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
 
 
677
 
678
  df = player_df.reset_index(drop=True)
679
 
@@ -732,15 +742,17 @@ with tab6:
732
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
733
  players_only['Book'] = players_only['Player'].map(book_dict)
734
  players_only['Prop'] = players_only['Player'].map(prop_dict)
 
 
735
  players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
736
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
737
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
738
  players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
739
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
740
- players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
741
  players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
742
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
743
- players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
744
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
745
  players_only['prop_threshold'] = .10
746
  players_only = players_only[players_only['Mean_Outcome'] > 0]
@@ -755,7 +767,7 @@ with tab6:
755
  players_only['Player'] = hold_file[['Player']]
756
  players_only['Team'] = players_only['Player'].map(team_dict)
757
 
758
- leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
759
  sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
760
 
761
  final_outcomes = sim_all_hold
 
68
  prop_table_options = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
69
  all_sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
70
  pick6_sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds']
71
+ sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge'])
72
 
73
  def calculate_poisson(row):
74
  mean_val = row['Mean_Outcome']
 
477
  else:
478
  book_selections = [book_select_var]
479
  if game_select_var == 'Aggregate':
480
+ prop_df = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
481
  elif game_select_var == 'Pick6':
482
+ prop_df = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
483
  book_selections = ['Pick6']
484
  st.download_button(
485
  label="Download Prop Source",
 
500
  with df_hold_container.container():
501
  if prop_type_var == 'All Props':
502
  if game_select_var == 'Aggregate':
503
+ prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
504
  sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS',
505
  'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_3_POINTERS_MADE']
506
  elif game_select_var == 'Pick6':
507
+ prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
508
  sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds', '3-Pointers Made']
509
 
510
  player_df = player_stats.copy()
 
514
  for books in book_selections:
515
  prop_df = prop_df_raw[prop_df_raw['prop_type'] == prop]
516
  prop_df = prop_df[prop_df['book'] == books]
517
+ prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
518
  prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
519
  prop_df['Over'] = 1 / prop_df['over_line']
520
  prop_df['Under'] = 1 / prop_df['under_line']
 
524
  book_dict = dict(zip(prop_df.Player, prop_df.book))
525
  over_dict = dict(zip(prop_df.Player, prop_df.Over))
526
  under_dict = dict(zip(prop_df.Player, prop_df.Under))
527
+ trending_over_dict = dict(zip(prop_df.Player, prop_df['Trending Over']))
528
+ trending_under_dict = dict(zip(prop_df.Player, prop_df['Trending Under']))
529
 
530
  player_df['book'] = player_df['Player'].map(book_dict)
531
  player_df['Prop'] = player_df['Player'].map(prop_dict)
532
  player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
533
+ player_df['Trending Over'] = player_df['Player'].map(trending_over_dict)
534
+ player_df['Trending Under'] = player_df['Player'].map(trending_under_dict)
535
 
536
  df = player_df.reset_index(drop=True)
537
 
 
590
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
591
  players_only['Book'] = players_only['Player'].map(book_dict)
592
  players_only['Prop'] = players_only['Player'].map(prop_dict)
593
+ players_only['Trending Over'] = players_only['Player'].map(trending_over_dict)
594
+ players_only['Trending Under'] = players_only['Player'].map(trending_under_dict)
595
  players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
596
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
597
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
598
  players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
599
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
600
+ players_only['Over%'] = players_only[["Over", "Imp Over", "Trending Over"]].mean(axis=1)
601
  players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
602
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
603
+ players_only['Under%'] = players_only[["Under", "Imp Under", "Trending Under"]].mean(axis=1)
604
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
605
  players_only['prop_threshold'] = .10
606
  players_only = players_only[players_only['Mean_Outcome'] > 0]
 
615
  players_only['Player'] = hold_file[['Player']]
616
  players_only['Team'] = players_only['Player'].map(team_dict)
617
 
618
+ leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge']]
619
  sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
620
 
621
  final_outcomes = sim_all_hold
 
626
  player_df = player_stats.copy()
627
 
628
  if game_select_var == 'Aggregate':
629
+ prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
630
  elif game_select_var == 'Pick6':
631
+ prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
632
 
633
  for books in book_selections:
634
  prop_df = prop_df_raw[prop_df_raw['book'] == books]
 
666
  elif prop_type_var == "Assists + Rebounds":
667
  prop_df = prop_df[prop_df['prop_type'] == 'Assists + Rebounds']
668
 
669
+ prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
670
  prop_df = prop_df.rename(columns={"over_prop": "Prop"})
671
  prop_df['Over'] = 1 / prop_df['over_line']
672
  prop_df['Under'] = 1 / prop_df['under_line']
 
676
  book_dict = dict(zip(prop_df.Player, prop_df.book))
677
  over_dict = dict(zip(prop_df.Player, prop_df.Over))
678
  under_dict = dict(zip(prop_df.Player, prop_df.Under))
679
+ trending_over_dict = dict(zip(prop_df.Player, prop_df['Trending Over']))
680
+ trending_under_dict = dict(zip(prop_df.Player, prop_df['Trending Under']))
681
 
682
  player_df['book'] = player_df['Player'].map(book_dict)
683
  player_df['Prop'] = player_df['Player'].map(prop_dict)
684
  player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
685
+ player_df['Trending Over'] = player_df['Player'].map(trending_over_dict)
686
+ player_df['Trending Under'] = player_df['Player'].map(trending_under_dict)
687
 
688
  df = player_df.reset_index(drop=True)
689
 
 
742
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
743
  players_only['Book'] = players_only['Player'].map(book_dict)
744
  players_only['Prop'] = players_only['Player'].map(prop_dict)
745
+ players_only['Trending Over'] = players_only['Player'].map(trending_over_dict)
746
+ players_only['Trending Under'] = players_only['Player'].map(trending_under_dict)
747
  players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
748
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
749
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
750
  players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
751
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
752
+ players_only['Over%'] = players_only[["Over", "Imp Over", "Trending Over"]].mean(axis=1)
753
  players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
754
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
755
+ players_only['Under%'] = players_only[["Under", "Imp Under", "Trending Under"]].mean(axis=1)
756
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
757
  players_only['prop_threshold'] = .10
758
  players_only = players_only[players_only['Mean_Outcome'] > 0]
 
767
  players_only['Player'] = hold_file[['Player']]
768
  players_only['Team'] = players_only['Player'].map(team_dict)
769
 
770
+ leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge']]
771
  sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
772
 
773
  final_outcomes = sim_all_hold