Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,6 +50,17 @@ def init_baselines():
|
|
| 50 |
'Shots', 'SH%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
| 51 |
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 52 |
'Faceoffs Lost', 'Faceoffs %']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
gamelog_table['dk_shots_bonus'] = np.where((gamelog_table['Shots'] >= 5), 1, 0)
|
| 54 |
gamelog_table['dk_blocks_bonus'] = np.where((gamelog_table['Shots Blocked'] >= 3), 1, 0)
|
| 55 |
gamelog_table['dk_goals_bonus'] = np.where((gamelog_table['Goals'] >= 3), 1, 0)
|
|
@@ -59,20 +70,20 @@ def init_baselines():
|
|
| 59 |
(gamelog_table['dk_goals_bonus'] * 3), (gamelog_table['dk_points_bonus'] * 3)]).astype(float).round(2)
|
| 60 |
gamelog_table['fd_fantasy'] = sum([(gamelog_table['Goals'] * 12), (gamelog_table['Total Assists'] * 8), (gamelog_table['Shots'] * 1.6),
|
| 61 |
(gamelog_table['Shots Blocked'] * 1.6)]).astype(float).round(2)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
gamelog_table['Date'] = pd.to_datetime(gamelog_table['Date']).dt.date
|
| 65 |
|
| 66 |
gamelog_table = gamelog_table.set_axis(['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points', 'IPP',
|
| 67 |
'Shots', 'Shots%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
| 68 |
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 69 |
-
'Faceoffs Lost', 'Faceoffs%'
|
|
|
|
| 70 |
|
| 71 |
return gamelog_table
|
| 72 |
|
| 73 |
@st.cache_data(show_spinner=False)
|
| 74 |
def seasonlong_build(data_sample):
|
| 75 |
-
season_long_table = data_sample[['Player', 'Team']]
|
| 76 |
season_long_table['TOI'] = data_sample.groupby(['Player', 'Team'], sort=False)['TOI'].transform('mean').astype(float)
|
| 77 |
season_long_table['Goals'] = data_sample.groupby(['Player', 'Team'], sort=False)['Goals'].transform('mean').astype(float)
|
| 78 |
season_long_table['Total Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Assists'].transform('mean').astype(float)
|
|
@@ -100,12 +111,20 @@ def seasonlong_build(data_sample):
|
|
| 100 |
season_long_table['Shots Blocked'] = data_sample.groupby(['Player', 'Team'], sort=False)['Shots Blocked'].transform('mean').astype(float)
|
| 101 |
season_long_table['Faceoffs Won'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Won'].transform('mean').astype(float)
|
| 102 |
season_long_table['Faceoffs Lost'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Lost'].transform('mean').astype(float)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
| 104 |
|
| 105 |
-
|
|
|
|
| 106 |
'IPP', 'Shots', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties',
|
| 107 |
'Minor', 'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 108 |
-
'Faceoffs Lost'
|
|
|
|
| 109 |
|
| 110 |
return season_long_table
|
| 111 |
|
|
|
|
| 50 |
'Shots', 'SH%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
| 51 |
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 52 |
'Faceoffs Lost', 'Faceoffs %']]
|
| 53 |
+
data_cols = gamelog_table.columns.drop(['Player', 'Team', 'Position', 'Date'])
|
| 54 |
+
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
| 55 |
+
gamelog_table['Date'] = pd.to_datetime(gamelog_table['Date']).dt.date
|
| 56 |
+
# gamelog_table['Shots'].replace("", 0, inplace=True)
|
| 57 |
+
# gamelog_table['Shots Blocked'].replace("", 0, inplace=True)
|
| 58 |
+
# gamelog_table['Goals'].replace("", 0, inplace=True)
|
| 59 |
+
# gamelog_table['Total Points'].replace("", 0, inplace=True)
|
| 60 |
+
# gamelog_table['Shots'] = gamelog_table['Shots'].astype(int)
|
| 61 |
+
# gamelog_table['Shots Blocked'] = gamelog_table['Shots Blocked'].astype(int)
|
| 62 |
+
# gamelog_table['Goals'] = gamelog_table['Goals'].astype(int)
|
| 63 |
+
# gamelog_table['Total Points'] = gamelog_table['Total Points'].astype(int)
|
| 64 |
gamelog_table['dk_shots_bonus'] = np.where((gamelog_table['Shots'] >= 5), 1, 0)
|
| 65 |
gamelog_table['dk_blocks_bonus'] = np.where((gamelog_table['Shots Blocked'] >= 3), 1, 0)
|
| 66 |
gamelog_table['dk_goals_bonus'] = np.where((gamelog_table['Goals'] >= 3), 1, 0)
|
|
|
|
| 70 |
(gamelog_table['dk_goals_bonus'] * 3), (gamelog_table['dk_points_bonus'] * 3)]).astype(float).round(2)
|
| 71 |
gamelog_table['fd_fantasy'] = sum([(gamelog_table['Goals'] * 12), (gamelog_table['Total Assists'] * 8), (gamelog_table['Shots'] * 1.6),
|
| 72 |
(gamelog_table['Shots Blocked'] * 1.6)]).astype(float).round(2)
|
| 73 |
+
|
| 74 |
+
|
|
|
|
| 75 |
|
| 76 |
gamelog_table = gamelog_table.set_axis(['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points', 'IPP',
|
| 77 |
'Shots', 'Shots%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
| 78 |
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 79 |
+
'Faceoffs Lost', 'Faceoffs%', 'dk_shots_bonus', 'dk_blocks_bonus', 'dk_goals_bonus', 'dk_points_bonus',
|
| 80 |
+
'dk_fantasy', 'fd_fantasy'], axis=1)
|
| 81 |
|
| 82 |
return gamelog_table
|
| 83 |
|
| 84 |
@st.cache_data(show_spinner=False)
|
| 85 |
def seasonlong_build(data_sample):
|
| 86 |
+
season_long_table = data_sample[['Player', 'Team', 'Position']]
|
| 87 |
season_long_table['TOI'] = data_sample.groupby(['Player', 'Team'], sort=False)['TOI'].transform('mean').astype(float)
|
| 88 |
season_long_table['Goals'] = data_sample.groupby(['Player', 'Team'], sort=False)['Goals'].transform('mean').astype(float)
|
| 89 |
season_long_table['Total Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Assists'].transform('mean').astype(float)
|
|
|
|
| 111 |
season_long_table['Shots Blocked'] = data_sample.groupby(['Player', 'Team'], sort=False)['Shots Blocked'].transform('mean').astype(float)
|
| 112 |
season_long_table['Faceoffs Won'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Won'].transform('mean').astype(float)
|
| 113 |
season_long_table['Faceoffs Lost'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Lost'].transform('mean').astype(float)
|
| 114 |
+
season_long_table['dk_shots_bonus'] = data_sample.groupby(['Player', 'Team'], sort=False)['dk_shots_bonus'].transform('mean').astype(float)
|
| 115 |
+
season_long_table['dk_blocks_bonus'] = data_sample.groupby(['Player', 'Team'], sort=False)['dk_blocks_bonus'].transform('mean').astype(float)
|
| 116 |
+
season_long_table['dk_goals_bonus'] = data_sample.groupby(['Player', 'Team'], sort=False)['dk_goals_bonus'].transform('mean').astype(float)
|
| 117 |
+
season_long_table['dk_points_bonus'] = data_sample.groupby(['Player', 'Team'], sort=False)['dk_points_bonus'].transform('mean').astype(float)
|
| 118 |
+
season_long_table['dk_fantasy'] = data_sample.groupby(['Player', 'Team'], sort=False)['dk_fantasy'].transform('mean').astype(float)
|
| 119 |
+
season_long_table['fd_fantasy'] = data_sample.groupby(['Player', 'Team'], sort=False)['fd_fantasy'].transform('mean').astype(float)
|
| 120 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
| 121 |
|
| 122 |
+
|
| 123 |
+
season_long_table = season_long_table.set_axis(['Player', 'Team', 'Position', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points',
|
| 124 |
'IPP', 'Shots', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties',
|
| 125 |
'Minor', 'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 126 |
+
'Faceoffs Lost', 'dk_shots_bonus', 'dk_blocks_bonus', 'dk_goals_bonus', 'dk_points_bonus',
|
| 127 |
+
'dk_fantasy', 'fd_fantasy'], axis=1)
|
| 128 |
|
| 129 |
return season_long_table
|
| 130 |
|