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if not name.startswith('_'):
|
6 |
+
del globals()[name]
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
import pandas as pd
|
10 |
+
import streamlit as st
|
11 |
+
import gspread
|
12 |
+
import gc
|
13 |
+
import plotly.express as px
|
14 |
+
import plotly.io as pio
|
15 |
+
import pymongo
|
16 |
+
import certifi
|
17 |
+
ca = certifi.where()
|
18 |
+
|
19 |
+
@st.cache_resource
|
20 |
+
def init_conn():
|
21 |
+
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
22 |
+
|
23 |
+
credentials = {
|
24 |
+
"type": "service_account",
|
25 |
+
"project_id": "model-sheets-connect",
|
26 |
+
"private_key_id": "0e0bc2fdef04e771172fe5807392b9d6639d945e",
|
27 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23nZK3ZVvADYy8u/RUn/EDI82QKxTd/DizRLIV81JiNQxDJXSzgkbwKYEDm\n48E8zGvupU8+Nk76xNPakrQKy2Y8+VJlq5psBtGchJTuUSHcXU5Mg2JhQsB376PJ\nsCw552K6Pw8fpeMDJDZuxpKSkaJR6k9G5Dhf5q8HDXnC5Rh/PRFuKJ2GGRpX7n+2\nhT/sCax0J8jfdTy/MDGiDfJqfQrOPrMKELtsGHR9Iv6F4vKiDqXpKfqH+02E9ptz\nBk+MNcbZ3m90M8ShfRu28ebebsASfarNMzc3dk7tb3utHOGXKCf4tF8yYKo7x8BZ\noO9X4gSfAgMBAAECggEAU8ByyMpSKlTCF32TJhXnVJi/kS+IhC/Qn5JUDMuk4LXr\naAEWsWO6kV/ZRVXArjmuSzuUVrXumISapM9Ps5Ytbl95CJmGDiLDwRL815nvv6k3\nUyAS8EGKjz74RpoIoH6E7EWCAzxlnUgTn+5oP9Flije97epYk3H+e2f1f5e1Nn1d\nYNe8U+1HqJgILcxA1TAUsARBfoD7+K3z/8DVPHI8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protected]",
|
29 |
+
"client_id": "100369174533302798535",
|
30 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
31 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
32 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
33 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
34 |
+
}
|
35 |
+
|
36 |
+
client = pymongo.MongoClient("mongodb+srv://multichem:[email protected]/testing_db")
|
37 |
+
db = client["testing_db"]
|
38 |
+
|
39 |
+
gc_con = gspread.service_account_from_dict(credentials, scope)
|
40 |
+
|
41 |
+
return gc_con, client, db
|
42 |
+
|
43 |
+
gcservice_account, client, db = init_conn()
|
44 |
+
|
45 |
+
NBA_Data = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=1808117109'
|
46 |
+
|
47 |
+
percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
|
48 |
+
|
49 |
+
@st.cache_resource(ttl = 599)
|
50 |
+
def init_baselines():
|
51 |
+
sh = gcservice_account.open_by_url(NBA_Data)
|
52 |
+
collection = db["gamelog"]
|
53 |
+
cursor = collection.find() # Finds all documents in the collection
|
54 |
+
|
55 |
+
raw_display = pd.DataFrame(list(cursor))
|
56 |
+
gamelog_table = raw_display[raw_display['PLAYER_NAME'] != ""]
|
57 |
+
gamelog_table = gamelog_table[['PLAYER_NAME', 'POS', 'GAME_ID', 'TEAM_NAME', 'OPP_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP', 'MIN', 'touches', 'PTS', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A',
|
58 |
+
'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'reboundChancesOffensive', 'OREB', 'reboundChancesDefensive', 'DREB', 'reboundChancesTotal', 'REB',
|
59 |
+
'passes', 'secondaryAssists', 'freeThrowAssists', 'assists', 'STL', 'BLK', 'TOV', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy', 'FPPM']]
|
60 |
+
gamelog_table['assists'].replace("", 0, inplace=True)
|
61 |
+
gamelog_table['reboundChancesTotal'].replace("", 0, inplace=True)
|
62 |
+
gamelog_table['passes'].replace("", 0, inplace=True)
|
63 |
+
gamelog_table['touches'].replace("", 0, inplace=True)
|
64 |
+
gamelog_table['MIN'].replace("", 0, inplace=True)
|
65 |
+
gamelog_table['Fantasy'].replace("", 0, inplace=True)
|
66 |
+
gamelog_table['FD_Fantasy'].replace("", 0, inplace=True)
|
67 |
+
gamelog_table['FPPM'].replace("", 0, inplace=True)
|
68 |
+
gamelog_table['REB'] = gamelog_table['REB'].astype(int)
|
69 |
+
gamelog_table['assists'] = gamelog_table['assists'].astype(int)
|
70 |
+
gamelog_table['reboundChancesTotal'] = gamelog_table['reboundChancesTotal'].astype(int)
|
71 |
+
gamelog_table['passes'] = gamelog_table['passes'].astype(int)
|
72 |
+
gamelog_table['touches'] = gamelog_table['touches'].astype(int)
|
73 |
+
gamelog_table['MIN'] = gamelog_table['MIN'].astype(int)
|
74 |
+
gamelog_table['Fantasy'] = gamelog_table['Fantasy'].astype(float)
|
75 |
+
gamelog_table['FD_Fantasy'] = gamelog_table['FD_Fantasy'].astype(float)
|
76 |
+
gamelog_table['FPPM'] = gamelog_table['FPPM'].astype(float)
|
77 |
+
gamelog_table['rebound%'] = gamelog_table['REB'] / gamelog_table['reboundChancesTotal']
|
78 |
+
gamelog_table['assists_per_pass'] = gamelog_table['assists'] / gamelog_table['passes']
|
79 |
+
gamelog_table['Touch_per_min'] = gamelog_table['touches'] / gamelog_table['MIN']
|
80 |
+
gamelog_table['Fantasy_per_touch'] = gamelog_table['Fantasy'] / gamelog_table['touches']
|
81 |
+
gamelog_table['FD_Fantasy_per_touch'] = gamelog_table['FD_Fantasy'] / gamelog_table['touches']
|
82 |
+
data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'POS', 'TEAM_NAME', 'OPP_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
|
83 |
+
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
84 |
+
gamelog_table['team_score'] = gamelog_table.groupby(['TEAM_NAME', 'GAME_ID'], sort=False)['PTS'].transform('sum')
|
85 |
+
gamelog_table['opp_score'] = gamelog_table.groupby(['GAME_ID'], sort=False)['PTS'].transform('sum') - gamelog_table['team_score']
|
86 |
+
gamelog_table['spread'] = (gamelog_table['opp_score'] - gamelog_table['team_score']).abs()
|
87 |
+
gamelog_table['GAME_DATE'] = pd.to_datetime(gamelog_table['GAME_DATE']).dt.date
|
88 |
+
|
89 |
+
spread_dict = dict(zip(gamelog_table['GAME_ID'], gamelog_table['spread']))
|
90 |
+
|
91 |
+
gamelog_table = gamelog_table.set_axis(['Player', 'Pos', 'game_id', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
92 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
93 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy', 'FPPM',
|
94 |
+
'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch', 'team_score', 'opp_score', 'spread'], axis=1)
|
95 |
+
|
96 |
+
worksheet = sh.worksheet('Rotations')
|
97 |
+
raw_display = pd.DataFrame(worksheet.get_values())
|
98 |
+
raw_display.columns = raw_display.iloc[0]
|
99 |
+
raw_display = raw_display[1:]
|
100 |
+
raw_display = raw_display.reset_index(drop=True)
|
101 |
+
rot_table = raw_display[raw_display['Player'] != ""]
|
102 |
+
rot_table = rot_table[['Player', 'Team', 'PG', 'SG', 'SF', 'PF', 'C', 'Given Pos']]
|
103 |
+
data_cols = ['PG', 'SG', 'SF', 'PF', 'C']
|
104 |
+
rot_table[data_cols] = rot_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
105 |
+
rot_table = rot_table[rot_table['Player'] != 0]
|
106 |
+
|
107 |
+
collection = db["rotations"]
|
108 |
+
cursor = collection.find() # Finds all documents in the collection
|
109 |
+
|
110 |
+
raw_display = pd.DataFrame(list(cursor))
|
111 |
+
game_rot = raw_display[raw_display['PLAYER_NAME'] != ""]
|
112 |
+
data_cols = game_rot.columns.drop(['PLAYER_NAME', 'POS', 'TEAM_ABBREVIATION', 'OPP_ABBREVIATION', 'TEAM_NAME', 'OPP_NAME', 'GAME_DATE',
|
113 |
+
'MATCHUP', 'WL', 'backlog_lookup', 'Task', 'game_players'])
|
114 |
+
game_rot[data_cols] = game_rot[data_cols].apply(pd.to_numeric, errors='coerce')
|
115 |
+
game_rot['spread'] = game_rot['GAME_ID'].map(spread_dict)
|
116 |
+
game_rot['GAME_DATE'] = pd.to_datetime(game_rot['GAME_DATE']).dt.date
|
117 |
+
|
118 |
+
timestamp = gamelog_table['Date'].max()
|
119 |
+
|
120 |
+
return gamelog_table, rot_table, game_rot, timestamp
|
121 |
+
|
122 |
+
@st.cache_data(show_spinner=False)
|
123 |
+
def seasonlong_build(data_sample):
|
124 |
+
season_long_table = data_sample[['Player', 'Pos', 'Team']]
|
125 |
+
season_long_table['Min'] = data_sample.groupby(['Player', 'Season'], sort=False)['Min'].transform('mean').astype(float)
|
126 |
+
season_long_table['Touches'] = data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('mean').astype(float)
|
127 |
+
season_long_table['Touch/Min'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int) /
|
128 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Min'].transform('sum').astype(int))
|
129 |
+
season_long_table['Pts'] = data_sample.groupby(['Player', 'Season'], sort=False)['Pts'].transform('mean').astype(float)
|
130 |
+
season_long_table['FGM'] = data_sample.groupby(['Player', 'Season'], sort=False)['FGM'].transform('mean').astype(float)
|
131 |
+
season_long_table['FGA'] = data_sample.groupby(['Player', 'Season'], sort=False)['FGA'].transform('mean').astype(float)
|
132 |
+
season_long_table['FG%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FGM'].transform('sum').astype(int) /
|
133 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['FGA'].transform('sum').astype(int))
|
134 |
+
season_long_table['FG3M'] = data_sample.groupby(['Player', 'Season'], sort=False)['FG3M'].transform('mean').astype(float)
|
135 |
+
season_long_table['FG3A'] = data_sample.groupby(['Player', 'Season'], sort=False)['FG3A'].transform('mean').astype(float)
|
136 |
+
season_long_table['FG3%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FG3M'].transform('sum').astype(int) /
|
137 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['FG3A'].transform('sum').astype(int))
|
138 |
+
season_long_table['FTM'] = data_sample.groupby(['Player', 'Season'], sort=False)['FTM'].transform('mean').astype(float)
|
139 |
+
season_long_table['FTA'] = data_sample.groupby(['Player', 'Season'], sort=False)['FTA'].transform('mean').astype(float)
|
140 |
+
season_long_table['FT%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FTM'].transform('sum').astype(int) /
|
141 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['FTA'].transform('sum').astype(int))
|
142 |
+
season_long_table['OREB Chance'] = data_sample.groupby(['Player', 'Season'], sort=False)['OREB Chance'].transform('mean').astype(float)
|
143 |
+
season_long_table['OREB'] = data_sample.groupby(['Player', 'Season'], sort=False)['OREB'].transform('mean').astype(float)
|
144 |
+
season_long_table['DREB Chance'] = data_sample.groupby(['Player', 'Season'], sort=False)['DREB Chance'].transform('mean').astype(float)
|
145 |
+
season_long_table['DREB'] = data_sample.groupby(['Player', 'Season'], sort=False)['DREB'].transform('mean').astype(float)
|
146 |
+
season_long_table['REB Chance'] = data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('mean').astype(float)
|
147 |
+
season_long_table['REB'] = data_sample.groupby(['Player', 'Season'], sort=False)['REB'].transform('mean').astype(float)
|
148 |
+
season_long_table['Passes'] = data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('mean').astype(float)
|
149 |
+
season_long_table['Alt Assists'] = data_sample.groupby(['Player', 'Season'], sort=False)['Alt Assists'].transform('mean').astype(float)
|
150 |
+
season_long_table['FT Assists'] = data_sample.groupby(['Player', 'Season'], sort=False)['FT Assists'].transform('mean').astype(float)
|
151 |
+
season_long_table['Assists'] = data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('mean').astype(float)
|
152 |
+
season_long_table['Stl'] = data_sample.groupby(['Player', 'Season'], sort=False)['Stl'].transform('mean').astype(float)
|
153 |
+
season_long_table['Blk'] = data_sample.groupby(['Player', 'Season'], sort=False)['Blk'].transform('mean').astype(float)
|
154 |
+
season_long_table['Tov'] = data_sample.groupby(['Player', 'Season'], sort=False)['Tov'].transform('mean').astype(float)
|
155 |
+
season_long_table['PF'] = data_sample.groupby(['Player', 'Season'], sort=False)['PF'].transform('mean').astype(float)
|
156 |
+
season_long_table['DD'] = data_sample.groupby(['Player', 'Season'], sort=False)['DD'].transform('mean').astype(float)
|
157 |
+
season_long_table['TD'] = data_sample.groupby(['Player', 'Season'], sort=False)['TD'].transform('mean').astype(float)
|
158 |
+
season_long_table['Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('mean').astype(float)
|
159 |
+
season_long_table['FD_Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
|
160 |
+
season_long_table['FPPM'] = data_sample.groupby(['Player', 'Season'], sort=False)['FPPM'].transform('mean').astype(float)
|
161 |
+
season_long_table['Rebound%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['REB'].transform('sum').astype(int) /
|
162 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('sum').astype(int))
|
163 |
+
season_long_table['Assists/Pass'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('sum').astype(int) /
|
164 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('sum').astype(int))
|
165 |
+
season_long_table['Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('sum').astype(int) /
|
166 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
167 |
+
season_long_table['FD Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
|
168 |
+
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
169 |
+
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
170 |
+
|
171 |
+
season_long_table = season_long_table.sort_values(by='Fantasy', ascending=False)
|
172 |
+
|
173 |
+
season_long_table = season_long_table.set_axis(['Player', 'Pos', 'Team', 'Min', 'Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
174 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
175 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
176 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
177 |
+
|
178 |
+
return season_long_table
|
179 |
+
|
180 |
+
@st.cache_data(show_spinner=False)
|
181 |
+
def run_fantasy_corr(data_sample):
|
182 |
+
cor_testing = data_sample
|
183 |
+
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
184 |
+
date_list = cor_testing['Date'].unique().tolist()
|
185 |
+
player_list = cor_testing['Player'].unique().tolist()
|
186 |
+
corr_frame = pd.DataFrame()
|
187 |
+
corr_frame['DATE'] = date_list
|
188 |
+
for player in player_list:
|
189 |
+
player_testing = cor_testing[cor_testing['Player'] == player]
|
190 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['Fantasy']))
|
191 |
+
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
192 |
+
players_fantasy = corr_frame.drop('DATE', axis=1)
|
193 |
+
corrM = players_fantasy.corr()
|
194 |
+
|
195 |
+
return corrM
|
196 |
+
|
197 |
+
@st.cache_data(show_spinner=False)
|
198 |
+
def run_min_corr(data_sample):
|
199 |
+
cor_testing = data_sample
|
200 |
+
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
201 |
+
date_list = cor_testing['Date'].unique().tolist()
|
202 |
+
player_list = cor_testing['Player'].unique().tolist()
|
203 |
+
corr_frame = pd.DataFrame()
|
204 |
+
corr_frame['DATE'] = date_list
|
205 |
+
for player in player_list:
|
206 |
+
player_testing = cor_testing[cor_testing['Player'] == player]
|
207 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['Min']))
|
208 |
+
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
209 |
+
players_fantasy = corr_frame.drop('DATE', axis=1)
|
210 |
+
corrM = players_fantasy.corr()
|
211 |
+
|
212 |
+
return corrM
|
213 |
+
|
214 |
+
@st.cache_data(show_spinner=False)
|
215 |
+
def split_frame(input_df, rows):
|
216 |
+
df = [input_df.loc[i : i + rows - 1, :] for i in range(0, len(input_df), rows)]
|
217 |
+
return df
|
218 |
+
|
219 |
+
def convert_df_to_csv(df):
|
220 |
+
return df.to_csv().encode('utf-8')
|
221 |
+
|
222 |
+
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
223 |
+
t_stamp = f"Updated through: " + str(timestamp) + f" CST"
|
224 |
+
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
225 |
+
basic_season_cols = ['Pos', 'Team', 'Min']
|
226 |
+
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
227 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
228 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
229 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
230 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
231 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
232 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
233 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
234 |
+
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
235 |
+
'Fantasy', 'FD_Fantasy']
|
236 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
237 |
+
total_teams = indv_teams.Team.values.tolist()
|
238 |
+
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
239 |
+
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
240 |
+
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
241 |
+
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
242 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
243 |
+
total_players = indv_players.Player.values.tolist()
|
244 |
+
total_dates = gamelog_table.Date.values.tolist()
|
245 |
+
|
246 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(['Gamelogs', 'Correlation Matrix', 'Position vs. Opp', 'Positional Percentages', 'Game Rotations'])
|
247 |
+
|
248 |
+
with tab1:
|
249 |
+
st.info(t_stamp)
|
250 |
+
col1, col2 = st.columns([1, 9])
|
251 |
+
with col1:
|
252 |
+
if st.button("Reset Data", key='reset1'):
|
253 |
+
st.cache_data.clear()
|
254 |
+
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
255 |
+
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
256 |
+
basic_season_cols = ['Pos', 'Team', 'Min']
|
257 |
+
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
258 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
259 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
260 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
261 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
262 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
263 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
264 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
265 |
+
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
266 |
+
'Fantasy', 'FD_Fantasy']
|
267 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
268 |
+
total_teams = indv_teams.Team.values.tolist()
|
269 |
+
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
270 |
+
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
271 |
+
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
272 |
+
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
273 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
274 |
+
total_players = indv_players.Player.values.tolist()
|
275 |
+
total_dates = gamelog_table.Date.values.tolist()
|
276 |
+
|
277 |
+
split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
|
278 |
+
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
279 |
+
|
280 |
+
if split_var2 == 'Specific Teams':
|
281 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='team_var1')
|
282 |
+
elif split_var2 == 'All':
|
283 |
+
team_var1 = total_teams
|
284 |
+
|
285 |
+
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
286 |
+
|
287 |
+
if split_var3 == 'Specific Dates':
|
288 |
+
low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date')
|
289 |
+
if low_date is not None:
|
290 |
+
low_date = pd.to_datetime(low_date).date()
|
291 |
+
high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date')
|
292 |
+
if high_date is not None:
|
293 |
+
high_date = pd.to_datetime(high_date).date()
|
294 |
+
elif split_var3 == 'All':
|
295 |
+
low_date = gamelog_table['Date'].min()
|
296 |
+
high_date = gamelog_table['Date'].max()
|
297 |
+
|
298 |
+
split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='split_var4')
|
299 |
+
|
300 |
+
if split_var4 == 'Specific Players':
|
301 |
+
player_var1 = st.multiselect('Which players would you like to include in the tables?', options = total_players, key='player_var1')
|
302 |
+
elif split_var4 == 'All':
|
303 |
+
player_var1 = total_players
|
304 |
+
|
305 |
+
spread_var1 = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='spread_var1')
|
306 |
+
|
307 |
+
min_var1 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1')
|
308 |
+
|
309 |
+
with col2:
|
310 |
+
working_data = gamelog_table
|
311 |
+
if split_var1 == 'Season Logs':
|
312 |
+
choose_cols = st.container()
|
313 |
+
with choose_cols:
|
314 |
+
choose_disp = st.multiselect('Which stats would you like to view?', options = season_data_cols, default = season_data_cols, key='col_display')
|
315 |
+
disp_stats = basic_season_cols + choose_disp
|
316 |
+
display = st.container()
|
317 |
+
working_data = working_data[working_data['Date'] >= low_date]
|
318 |
+
working_data = working_data[working_data['Date'] <= high_date]
|
319 |
+
working_data = working_data[working_data['Min'] >= min_var1[0]]
|
320 |
+
working_data = working_data[working_data['Min'] <= min_var1[1]]
|
321 |
+
working_data = working_data[working_data['spread'] >= spread_var1[0]]
|
322 |
+
working_data = working_data[working_data['spread'] <= spread_var1[1]]
|
323 |
+
working_data = working_data[working_data['Team'].isin(team_var1)]
|
324 |
+
working_data = working_data[working_data['Player'].isin(player_var1)]
|
325 |
+
season_long_table = seasonlong_build(working_data)
|
326 |
+
season_long_table = season_long_table.set_index('Player')
|
327 |
+
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
328 |
+
display.dataframe(season_long_table_disp.style.format(precision=2), height=750, use_container_width = True)
|
329 |
+
st.download_button(
|
330 |
+
label="Export seasonlogs Model",
|
331 |
+
data=convert_df_to_csv(season_long_table),
|
332 |
+
file_name='Seasonlogs_NBA_View.csv',
|
333 |
+
mime='text/csv',
|
334 |
+
)
|
335 |
+
|
336 |
+
elif split_var1 == 'Gamelogs':
|
337 |
+
choose_cols = st.container()
|
338 |
+
with choose_cols:
|
339 |
+
choose_disp_gamelog = st.multiselect('Which stats would you like to view?', options = data_cols, default = data_cols, key='choose_disp_gamelog')
|
340 |
+
gamelog_disp_stats = basic_cols + choose_disp_gamelog
|
341 |
+
working_data = working_data[working_data['Date'] >= low_date]
|
342 |
+
working_data = working_data[working_data['Date'] <= high_date]
|
343 |
+
working_data = working_data[working_data['Min'] >= min_var1[0]]
|
344 |
+
working_data = working_data[working_data['Min'] <= min_var1[1]]
|
345 |
+
working_data = working_data[working_data['spread'] >= spread_var1[0]]
|
346 |
+
working_data = working_data[working_data['spread'] <= spread_var1[1]]
|
347 |
+
working_data = working_data[working_data['Team'].isin(team_var1)]
|
348 |
+
working_data = working_data[working_data['Player'].isin(player_var1)]
|
349 |
+
working_data = working_data.reset_index(drop=True)
|
350 |
+
gamelog_data = working_data.reindex(gamelog_disp_stats,axis="columns")
|
351 |
+
display = st.container()
|
352 |
+
|
353 |
+
bottom_menu = st.columns((4, 1, 1))
|
354 |
+
with bottom_menu[2]:
|
355 |
+
batch_size = st.selectbox("Page Size", options=[25, 50, 100])
|
356 |
+
with bottom_menu[1]:
|
357 |
+
total_pages = (
|
358 |
+
int(len(gamelog_data) / batch_size) if int(len(gamelog_data) / batch_size) > 0 else 1
|
359 |
+
)
|
360 |
+
current_page = st.number_input(
|
361 |
+
"Page", min_value=1, max_value=total_pages, step=1
|
362 |
+
)
|
363 |
+
with bottom_menu[0]:
|
364 |
+
st.markdown(f"Page **{current_page}** of **{total_pages}** ")
|
365 |
+
|
366 |
+
|
367 |
+
pages = split_frame(gamelog_data, batch_size)
|
368 |
+
# pages = pages.set_index('Player')
|
369 |
+
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|
370 |
+
st.download_button(
|
371 |
+
label="Export gamelogs Model",
|
372 |
+
data=convert_df_to_csv(gamelog_data),
|
373 |
+
file_name='Gamelogs_NBA_View.csv',
|
374 |
+
mime='text/csv',
|
375 |
+
)
|
376 |
+
|
377 |
+
with tab2:
|
378 |
+
st.info(t_stamp)
|
379 |
+
col1, col2 = st.columns([1, 9])
|
380 |
+
with col1:
|
381 |
+
if st.button("Reset Data", key='reset2'):
|
382 |
+
st.cache_data.clear()
|
383 |
+
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
384 |
+
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
385 |
+
basic_season_cols = ['Pos', 'Team', 'Min']
|
386 |
+
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
387 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
388 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
389 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
390 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
391 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
392 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
393 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
394 |
+
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
395 |
+
'Fantasy', 'FD_Fantasy']
|
396 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
397 |
+
total_teams = indv_teams.Team.values.tolist()
|
398 |
+
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
399 |
+
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
400 |
+
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
401 |
+
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
402 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
403 |
+
total_players = indv_players.Player.values.tolist()
|
404 |
+
total_dates = gamelog_table.Date.values.tolist()
|
405 |
+
|
406 |
+
corr_var = st.radio("Are you correlating fantasy or minutes?", ('Fantasy', 'Minutes'), key='corr_var')
|
407 |
+
|
408 |
+
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
409 |
+
|
410 |
+
if split_var1_t2 == 'Specific Teams':
|
411 |
+
corr_var1_t2 = st.multiselect('Which teams would you like to include in the correlation?', options = total_teams, key='corr_var1_t2')
|
412 |
+
elif split_var1_t2 == 'Specific Players':
|
413 |
+
corr_var1_t2 = st.multiselect('Which players would you like to include in the correlation?', options = total_players, key='corr_var1_t2')
|
414 |
+
|
415 |
+
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
416 |
+
|
417 |
+
if split_var2_t2 == 'Specific Dates':
|
418 |
+
low_date_t2 = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date_t2')
|
419 |
+
if low_date_t2 is not None:
|
420 |
+
low_date_t2 = pd.to_datetime(low_date_t2).date()
|
421 |
+
high_date_t2 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date_t2')
|
422 |
+
if high_date_t2 is not None:
|
423 |
+
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
424 |
+
elif split_var2_t2 == 'All':
|
425 |
+
low_date_t2 = gamelog_table['Date'].min()
|
426 |
+
high_date_t2 = gamelog_table['Date'].max()
|
427 |
+
|
428 |
+
spread_var1_t2 = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='spread_var1_t2')
|
429 |
+
|
430 |
+
min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1_t2')
|
431 |
+
|
432 |
+
with col2:
|
433 |
+
working_data = gamelog_table
|
434 |
+
if split_var1_t2 == 'Specific Teams':
|
435 |
+
display = st.container()
|
436 |
+
working_data = working_data.sort_values(by='Fantasy', ascending=False)
|
437 |
+
working_data = working_data[working_data['Date'] >= low_date_t2]
|
438 |
+
working_data = working_data[working_data['Date'] <= high_date_t2]
|
439 |
+
working_data = working_data[working_data['Min'] >= min_var1_t2[0]]
|
440 |
+
working_data = working_data[working_data['Min'] <= min_var1_t2[1]]
|
441 |
+
working_data = working_data[working_data['spread'] >= spread_var1_t2[0]]
|
442 |
+
working_data = working_data[working_data['spread'] <= spread_var1_t2[1]]
|
443 |
+
working_data = working_data[working_data['Team'].isin(corr_var1_t2)]
|
444 |
+
if corr_var == 'Fantasy':
|
445 |
+
corr_display = run_fantasy_corr(working_data)
|
446 |
+
elif corr_var == 'Minutes':
|
447 |
+
corr_display = run_min_corr(working_data)
|
448 |
+
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
449 |
+
|
450 |
+
elif split_var1_t2 == 'Specific Players':
|
451 |
+
display = st.container()
|
452 |
+
working_data = working_data.sort_values(by='Fantasy', ascending=False)
|
453 |
+
working_data = working_data[working_data['Date'] >= low_date_t2]
|
454 |
+
working_data = working_data[working_data['Date'] <= high_date_t2]
|
455 |
+
working_data = working_data[working_data['Min'] >= min_var1_t2[0]]
|
456 |
+
working_data = working_data[working_data['Min'] <= min_var1_t2[1]]
|
457 |
+
working_data = working_data[working_data['spread'] >= spread_var1_t2[0]]
|
458 |
+
working_data = working_data[working_data['spread'] <= spread_var1_t2[1]]
|
459 |
+
working_data = working_data[working_data['Player'].isin(corr_var1_t2)]
|
460 |
+
if corr_var == 'Fantasy':
|
461 |
+
corr_display = run_fantasy_corr(working_data)
|
462 |
+
elif corr_var == 'Minutes':
|
463 |
+
corr_display = run_min_corr(working_data)
|
464 |
+
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
465 |
+
st.download_button(
|
466 |
+
label="Export Correlations Model",
|
467 |
+
data=convert_df_to_csv(corr_display),
|
468 |
+
file_name='Correlations_NBA_View.csv',
|
469 |
+
mime='text/csv',
|
470 |
+
)
|
471 |
+
|
472 |
+
with tab3:
|
473 |
+
st.info(t_stamp)
|
474 |
+
col1, col2 = st.columns([1, 9])
|
475 |
+
with col1:
|
476 |
+
if st.button("Reset Data", key='reset3'):
|
477 |
+
st.cache_data.clear()
|
478 |
+
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
479 |
+
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
480 |
+
basic_season_cols = ['Pos', 'Team', 'Min']
|
481 |
+
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
482 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
483 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
484 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
485 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
486 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
487 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
488 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
489 |
+
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
490 |
+
'Fantasy', 'FD_Fantasy']
|
491 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
492 |
+
total_teams = indv_teams.Team.values.tolist()
|
493 |
+
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
494 |
+
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
495 |
+
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
496 |
+
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
497 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
498 |
+
total_players = indv_players.Player.values.tolist()
|
499 |
+
total_dates = gamelog_table.Date.values.tolist()
|
500 |
+
|
501 |
+
team_var3 = st.selectbox('Which opponent would you like to view?', options = total_teams, key='team_var3')
|
502 |
+
pos_var3 = st.selectbox('Which position would you like to view?', options = ['PG', 'SG', 'SF', 'PF', 'C'], key='pos_var3')
|
503 |
+
disp_var3 = st.radio('Which view would you like to see?', options = ['Fantasy', 'Stats'], key='disp_var3')
|
504 |
+
date_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='date_var3')
|
505 |
+
|
506 |
+
if date_var3 == 'Specific Dates':
|
507 |
+
low_date3 = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date3')
|
508 |
+
if low_date3 is not None:
|
509 |
+
low_date3 = pd.to_datetime(low_date3).date()
|
510 |
+
high_date3 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date3')
|
511 |
+
if high_date3 is not None:
|
512 |
+
high_date3 = pd.to_datetime(high_date3).date()
|
513 |
+
elif date_var3 == 'All':
|
514 |
+
low_date3 = gamelog_table['Date'].min()
|
515 |
+
high_date3 = gamelog_table['Date'].max()
|
516 |
+
|
517 |
+
spread_var3 = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='spread_var3')
|
518 |
+
|
519 |
+
min_var3 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var3')
|
520 |
+
|
521 |
+
with col2:
|
522 |
+
if disp_var3 == 'Stats':
|
523 |
+
choose_cols = st.container()
|
524 |
+
with choose_cols:
|
525 |
+
choose_disp_matchup = st.multiselect('Which stats would you like to view?', options = data_cols, default = data_cols, key='choose_disp_matchup')
|
526 |
+
matchup_disp_stats = basic_cols + choose_disp_matchup
|
527 |
+
working_data = gamelog_table
|
528 |
+
working_data = working_data[gamelog_table['Date'] >= low_date3]
|
529 |
+
working_data = working_data[gamelog_table['Date'] <= high_date3]
|
530 |
+
season_long_table = seasonlong_build(working_data)
|
531 |
+
fantasy_dict = dict(zip(season_long_table['Player'], season_long_table['Fantasy']))
|
532 |
+
fd_fantasy_dict = dict(zip(season_long_table['Player'], season_long_table['FD_Fantasy']))
|
533 |
+
|
534 |
+
working_data = working_data[working_data['Pos'] == pos_var3]
|
535 |
+
working_data = working_data[working_data['Min'] >= min_var3[0]]
|
536 |
+
working_data = working_data[working_data['Min'] <= min_var3[1]]
|
537 |
+
working_data = working_data[working_data['spread'] >= spread_var3[0]]
|
538 |
+
working_data = working_data[working_data['spread'] <= spread_var3[1]]
|
539 |
+
working_data = working_data[working_data['Opp'] == team_var3]
|
540 |
+
working_data = working_data.reset_index(drop=True)
|
541 |
+
if disp_var3 == 'Fantasy':
|
542 |
+
gamelog_display = working_data[['Player', 'Pos', 'Team', 'Opp', 'Date', 'Min', 'Fantasy', 'FD_Fantasy']]
|
543 |
+
elif disp_var3 == 'Stats':
|
544 |
+
gamelog_data = working_data.reindex(matchup_disp_stats,axis="columns")
|
545 |
+
gamelog_display = gamelog_data
|
546 |
+
gamelog_display['Avg_Fantasy'] = gamelog_display['Player'].map(fantasy_dict)
|
547 |
+
gamelog_display['Avg_FD_Fantasy'] = gamelog_display['Player'].map(fd_fantasy_dict)
|
548 |
+
display = st.container()
|
549 |
+
|
550 |
+
# pages = pages.set_index('Player')
|
551 |
+
display.dataframe(gamelog_display.style.format(precision=2), height=500, use_container_width=True)
|
552 |
+
st.download_button(
|
553 |
+
label="Export Matchups Model",
|
554 |
+
data=convert_df_to_csv(gamelog_display),
|
555 |
+
file_name='Matchups_NBA_View.csv',
|
556 |
+
mime='text/csv',
|
557 |
+
)
|
558 |
+
|
559 |
+
with tab4:
|
560 |
+
st.info(t_stamp)
|
561 |
+
col1, col2 = st.columns([1, 9])
|
562 |
+
with col1:
|
563 |
+
if st.button("Reset Data", key='reset4'):
|
564 |
+
st.cache_data.clear()
|
565 |
+
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
566 |
+
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
567 |
+
basic_season_cols = ['Pos', 'Team', 'Min']
|
568 |
+
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
569 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
570 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
571 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
572 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
573 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
574 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
575 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
576 |
+
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
577 |
+
'Fantasy', 'FD_Fantasy']
|
578 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
579 |
+
total_teams = indv_teams.Team.values.tolist()
|
580 |
+
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
581 |
+
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
582 |
+
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
583 |
+
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
584 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
585 |
+
total_players = indv_players.Player.values.tolist()
|
586 |
+
total_dates = gamelog_table.Date.values.tolist()
|
587 |
+
|
588 |
+
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
589 |
+
|
590 |
+
if split_var5 == 'Specific Teams':
|
591 |
+
team_var4 = st.multiselect('Which teams would you like to view?', options = total_rot_teams, key='team_var4')
|
592 |
+
elif split_var5 == 'All':
|
593 |
+
team_var4 = total_rot_teams
|
594 |
+
|
595 |
+
|
596 |
+
with col2:
|
597 |
+
working_data = rot_table
|
598 |
+
rot_display = working_data[working_data['Team'].isin(team_var4)]
|
599 |
+
display = st.container()
|
600 |
+
|
601 |
+
# rot_display = rot_display.set_index('Player')
|
602 |
+
display.dataframe(rot_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), height=500, use_container_width=True)
|
603 |
+
st.download_button(
|
604 |
+
label="Export Rotations Model",
|
605 |
+
data=convert_df_to_csv(rot_display),
|
606 |
+
file_name='Rotations_NBA_View.csv',
|
607 |
+
mime='text/csv',
|
608 |
+
)
|
609 |
+
|
610 |
+
with tab5:
|
611 |
+
st.info(t_stamp)
|
612 |
+
col1, col2 = st.columns([1, 9])
|
613 |
+
with col1:
|
614 |
+
if st.button("Reset Data", key='reset5'):
|
615 |
+
st.cache_data.clear()
|
616 |
+
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
617 |
+
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
618 |
+
basic_season_cols = ['Pos', 'Team', 'Min']
|
619 |
+
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
620 |
+
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
621 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
622 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
623 |
+
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
624 |
+
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
625 |
+
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
626 |
+
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
627 |
+
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
628 |
+
'Fantasy', 'FD_Fantasy']
|
629 |
+
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
630 |
+
total_teams = indv_teams.Team.values.tolist()
|
631 |
+
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
632 |
+
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
633 |
+
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
634 |
+
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
635 |
+
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
636 |
+
total_players = indv_players.Player.values.tolist()
|
637 |
+
total_dates = gamelog_table.Date.values.tolist()
|
638 |
+
|
639 |
+
game_rot_view = st.radio("What set would you like to view?", ('Team Rotations', 'Player Rotations'), key='game_rot_view')
|
640 |
+
|
641 |
+
if game_rot_view == 'Team Rotations':
|
642 |
+
game_rot_team = st.selectbox("What team would you like to work with?", options = total_game_rot_teams, key='game_rot_team')
|
643 |
+
|
644 |
+
game_rot_spread = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='game_rot_spread')
|
645 |
+
|
646 |
+
game_rot_min = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='game_rot_min')
|
647 |
+
|
648 |
+
game_rot_dates = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='game_rot_dates')
|
649 |
+
|
650 |
+
if game_rot_dates == 'Specific Dates':
|
651 |
+
game_rot_low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='game_rot_low_date')
|
652 |
+
if game_rot_low_date is not None:
|
653 |
+
game_rot_low_date = pd.to_datetime(low_date).date()
|
654 |
+
game_rot_high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='game_rot_high_date')
|
655 |
+
if game_rot_high_date is not None:
|
656 |
+
game_rot_high_date = pd.to_datetime(high_date).date()
|
657 |
+
elif game_rot_dates == 'All':
|
658 |
+
game_rot_low_date = gamelog_table['Date'].min()
|
659 |
+
game_rot_high_date = gamelog_table['Date'].max()
|
660 |
+
elif game_rot_view == 'Player Rotations':
|
661 |
+
game_rot_team = st.multiselect("What players would you like to work with?", options = total_players, key='game_rot_team')
|
662 |
+
|
663 |
+
game_rot_spread = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='game_rot_spread')
|
664 |
+
|
665 |
+
game_rot_min = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='game_rot_min')
|
666 |
+
|
667 |
+
game_rot_dates = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='game_rot_dates')
|
668 |
+
|
669 |
+
if game_rot_dates == 'Specific Dates':
|
670 |
+
game_rot_low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='game_rot_low_date')
|
671 |
+
if game_rot_low_date is not None:
|
672 |
+
game_rot_low_date = pd.to_datetime(low_date).date()
|
673 |
+
game_rot_high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='game_rot_high_date')
|
674 |
+
if game_rot_high_date is not None:
|
675 |
+
game_rot_high_date = pd.to_datetime(high_date).date()
|
676 |
+
elif game_rot_dates == 'All':
|
677 |
+
game_rot_low_date = gamelog_table['Date'].min()
|
678 |
+
game_rot_high_date = gamelog_table['Date'].max()
|
679 |
+
|
680 |
+
|
681 |
+
with col2:
|
682 |
+
if game_rot_view == 'Player Rotations':
|
683 |
+
team_backlog = game_rot[game_rot['PLAYER_NAME'].isin(game_rot_team)]
|
684 |
+
team_backlog = team_backlog[team_backlog['GAME_DATE'] >= game_rot_low_date]
|
685 |
+
team_backlog = team_backlog[team_backlog['GAME_DATE'] <= game_rot_high_date]
|
686 |
+
team_backlog = team_backlog[team_backlog['MIN'] >= game_rot_min[0]]
|
687 |
+
team_backlog = team_backlog[team_backlog['MIN'] <= game_rot_min[1]]
|
688 |
+
team_backlog = team_backlog[team_backlog['spread'] >= game_rot_spread[0]]
|
689 |
+
team_backlog = team_backlog[team_backlog['spread'] <= game_rot_spread[1]]
|
690 |
+
working_data = game_rot
|
691 |
+
display = st.container()
|
692 |
+
stats_disp = st.container()
|
693 |
+
check_rotation = team_backlog.sort_values(by='GAME_DATE', ascending=False)
|
694 |
+
game_rot_stats = check_rotation.reindex(game_rot_cols,axis="columns")
|
695 |
+
game_rot_stats = game_rot_stats.drop_duplicates(subset='backlog_lookup')
|
696 |
+
|
697 |
+
fig = px.timeline(check_rotation, x_start="Start", x_end="Finish", y="Task", range_x=[0,check_rotation["Finish"].max()], text='minutes')
|
698 |
+
fig.update_yaxes(autorange="reversed")
|
699 |
+
|
700 |
+
fig.layout.xaxis.type = 'linear'
|
701 |
+
fig.data[0].x = check_rotation.delta.tolist()
|
702 |
+
fig.add_vline(x=12, line_width=3, line_dash="dash", line_color="green")
|
703 |
+
fig.add_vline(x=24, line_width=3, line_dash="dash", line_color="green")
|
704 |
+
fig.add_vline(x=36, line_width=3, line_dash="dash", line_color="green")
|
705 |
+
# pages = pages.set_index('Player')
|
706 |
+
display.plotly_chart(fig, use_container_width=True)
|
707 |
+
stats_disp.dataframe(game_rot_stats.style.format(precision=2), hide_index=True, use_container_width = True)
|
708 |
+
|
709 |
+
elif game_rot_view == 'Team Rotations':
|
710 |
+
team_backlog = game_rot[game_rot['TEAM_ABBREVIATION'] == game_rot_team]
|
711 |
+
team_backlog = team_backlog[team_backlog['GAME_DATE'] >= game_rot_low_date]
|
712 |
+
team_backlog = team_backlog[team_backlog['GAME_DATE'] <= game_rot_high_date]
|
713 |
+
team_backlog = team_backlog[team_backlog['MIN'] >= game_rot_min[0]]
|
714 |
+
team_backlog = team_backlog[team_backlog['MIN'] <= game_rot_min[1]]
|
715 |
+
team_backlog = team_backlog[team_backlog['spread'] >= game_rot_spread[0]]
|
716 |
+
team_backlog = team_backlog[team_backlog['spread'] <= game_rot_spread[1]]
|
717 |
+
game_id_var = st.selectbox("What game would you like to view?", options = team_backlog['backlog_lookup'].unique(), key='game_id_var')
|
718 |
+
working_data = game_rot
|
719 |
+
display = st.container()
|
720 |
+
stats_disp = st.container()
|
721 |
+
check_rotation = working_data[working_data['backlog_lookup'] == game_id_var]
|
722 |
+
check_rotation = check_rotation.sort_values(by='Start', ascending=True)
|
723 |
+
game_rot_stats = check_rotation.reindex(game_rot_cols,axis="columns")
|
724 |
+
game_rot_stats = game_rot_stats.drop_duplicates(subset='PLAYER_NAME')
|
725 |
+
|
726 |
+
fig = px.timeline(check_rotation, x_start="Start", x_end="Finish", y="Task", range_x=[0,check_rotation["Finish"].max()], text='minutes')
|
727 |
+
fig.update_yaxes(autorange="reversed")
|
728 |
+
|
729 |
+
fig.layout.xaxis.type = 'linear'
|
730 |
+
fig.data[0].x = check_rotation.delta.tolist()
|
731 |
+
fig.add_vline(x=12, line_width=3, line_dash="dash", line_color="green")
|
732 |
+
fig.add_vline(x=24, line_width=3, line_dash="dash", line_color="green")
|
733 |
+
fig.add_vline(x=36, line_width=3, line_dash="dash", line_color="green")
|
734 |
+
# pages = pages.set_index('Player')
|
735 |
+
display.plotly_chart(fig, use_container_width=True)
|
736 |
+
stats_disp.dataframe(game_rot_stats.style.format(precision=2), hide_index=True, use_container_width = True)
|