File size: 16,219 Bytes
3096df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98c4e33
9287978
1e2cd0a
5c6dd71
3096df7
 
017bb46
 
5310763
e84bf1e
 
3096df7
9287978
3096df7
9287978
3096df7
9287978
3096df7
9287978
1e2cd0a
9287978
1e2cd0a
9287978
3096df7
 
 
 
 
1e2cd0a
3096df7
 
 
 
1e2cd0a
3096df7
 
 
 
 
 
1e2cd0a
3096df7
 
9287978
 
3096df7
 
 
1e2cd0a
3096df7
 
9287978
 
3096df7
 
 
1e2cd0a
3096df7
9287978
 
7444a76
9287978
 
 
c04d9d1
 
3096df7
 
 
 
 
 
 
 
 
 
 
47079ea
3096df7
79a3609
3096df7
 
 
 
98c4e33
3096df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e2cd0a
 
 
 
3096df7
1e2cd0a
 
 
 
 
5ec49bd
3096df7
 
 
 
 
 
 
 
 
 
47079ea
3096df7
79a3609
3096df7
 
 
 
 
 
 
 
30e1855
3096df7
 
5cc891a
3096df7
 
 
 
 
 
 
 
 
 
5cc891a
3096df7
 
 
 
 
 
 
 
 
 
5cc891a
3096df7
 
 
1e2cd0a
 
 
 
 
 
 
 
 
 
 
3096df7
 
 
 
aee2f0e
3096df7
 
 
30e1855
3096df7
 
5cc891a
3096df7
 
 
3ddd1d0
3096df7
 
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
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 gc

@st.cache_resource
def init_conn():
        scope = ['https://spreadsheets.google.com/feeds', '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+1HqJg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ATE KEY-----\n",
          "client_email": "[email protected]",
          "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, scope)
      
        return gc_con

gcservice_account = init_conn()

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

@st.cache_resource(ttl = 600)
def init_baselines():
    sh = gcservice_account.open_by_url(NBA_Data)
    
    worksheet = sh.worksheet('Trending')
    raw_display = pd.DataFrame(worksheet.get_values())
    raw_display.columns = raw_display.iloc[0]
    raw_display = raw_display[1:]
    raw_display = raw_display.reset_index(drop=True)
    trend_table = raw_display[raw_display['PLAYER_NAME'] != ""]
    trend_table.replace('', np.nan, inplace=True)
    trend_table = trend_table[['PLAYER_NAME', 'Team', 'Position', 'FD_Position', 'Season MIN', 'Season Fantasy', 'Season FPPM', 'Season Ceiling', 'Season FD_Fantasy', 'Season FD_Ceiling', 'L10 MIN', 'L10 Fantasy', 'L10 FPPM', 'L10 Ceiling', 'L10 FD_Fantasy',
                               'L10 FD_Ceiling', 'L5 MIN', 'L5 Fantasy', 'L5 FPPM', 'L5 Ceiling', 'L5 FD_Fantasy', 'L5 FD_Ceiling', 'L3 MIN', 'L3 Fantasy',
                               'L3 FPPM', 'L3 Ceiling', 'L3 FD_Fantasy', 'L3 FD_Ceiling', 'Trend Min', 'Trend Median', 'Trend FPPM', 'DK_Proj', 'Adj Median', 'Adj Ceiling',
                               'Trend FD_Median', 'FD_Proj', 'Adj FD_Median', 'Adj FD_Ceiling', 'DK_Salary', 'DK_Avg_Val', 'DK_Ceiling_Value',
                               'FD_Salary', 'FD_Avg_Val', 'FD_Ceiling_Value']]
    trend_table['DK_Salary'] = trend_table['DK_Salary'].str.replace(',', '').astype(float)
    trend_table['FD_Salary'] = trend_table['FD_Salary'].str.replace(',', '').astype(float)
    trend_table = trend_table.dropna(subset=['Position'])
    data_cols = trend_table.columns.drop(['PLAYER_NAME', 'Team', 'Position', 'FD_Position'])
    trend_table[data_cols] = trend_table[data_cols].apply(pd.to_numeric, errors='coerce')
    
    dk_minutes_table = trend_table[['PLAYER_NAME', 'Team', 'Season MIN', 'L10 MIN', 'L5 MIN', 'L3 MIN', 'Trend Min']]
    
    fd_minutes_table = trend_table[['PLAYER_NAME', 'Team', 'Season MIN', 'L10 MIN', 'L5 MIN', 'L3 MIN', 'Trend Min']]
    
    dk_medians_table = trend_table[['PLAYER_NAME', 'Team', 'Season Fantasy', 'L10 Fantasy', 'L5 Fantasy', 'L3 Fantasy', 'Trend Median']]
    
    fd_medians_table = trend_table[['PLAYER_NAME', 'Team', 'Season FD_Fantasy', 'L10 FD_Fantasy', 'L5 FD_Fantasy', 'L3 FD_Fantasy', 'Trend FD_Median']]

    dk_fppm_table = trend_table[['PLAYER_NAME', 'Team', 'Season FPPM', 'L10 FPPM', 'L5 FPPM', 'L3 FPPM', 'Trend FPPM']]
    
    fd_fppm_table = trend_table[['PLAYER_NAME', 'Team', 'Season FPPM', 'L10 FPPM', 'L5 FPPM', 'L3 FPPM', 'Trend FPPM']]
    
    dk_proj_medians_table = trend_table[['PLAYER_NAME', 'Team', 'Position', 'DK_Salary', 'DK_Proj', 'Adj Median', 'DK_Avg_Val', 'Adj Ceiling', 'DK_Ceiling_Value']]
    
    fd_proj_medians_table = trend_table[['PLAYER_NAME', 'Team', 'FD_Position', 'FD_Salary', 'FD_Proj', 'Adj FD_Median', 'FD_Avg_Val', 'Adj FD_Ceiling', 'FD_Ceiling_Value']]

    return trend_table, dk_minutes_table, fd_minutes_table, dk_medians_table, fd_medians_table, dk_fppm_table, fd_fppm_table, dk_proj_medians_table, fd_proj_medians_table

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

trend_table, dk_minutes_table, fd_minutes_table, dk_medians_table, fd_medians_table, dk_fppm_table, fd_fppm_table, dk_proj_medians_table, fd_proj_medians_table = init_baselines()

col1, col2 = st.columns([1, 9])
with col1:
    if st.button("Reset Data", key='reset1'):
              st.cache_data.clear()
              trend_table, dk_minutes_table, fd_minutes_table, dk_medians_table, fd_medians_table, dk_proj_medians_table, fd_proj_medians_table = init_baselines()
    split_var1 = st.radio("What table would you like to view?", ('Minutes Trends', 'Fantasy Trends', 'FPPM Trends', 'Slate specific', 'Overall'), key='split_var1')
    site_var1 = st.radio("What site would you like to view?", ('Draftkings', 'Fanduel'), key='site_var1')
    if site_var1 == 'Draftkings':
        trend_table = trend_table[['PLAYER_NAME', 'Team', 'Position', 'Season MIN', 'L10 MIN', 'L5 MIN', 'L3 MIN', 'Trend Min', 'Season Fantasy', 'L10 Fantasy', 'L5 Fantasy', 'L3 Fantasy',
                                   'Trend Median', 'Season FPPM', 'L10 FPPM', 'L5 FPPM', 'L3 FPPM', 'Trend FPPM', 'DK_Proj', 'Adj Median', 'Adj Ceiling',
                                   'DK_Salary', 'DK_Avg_Val', 'DK_Ceiling_Value']]
        minutes_table = dk_minutes_table
        medians_table = dk_medians_table
        fppm_table = dk_fppm_table
        proj_medians_table = dk_proj_medians_table
    elif site_var1 == 'Fanduel':
        trend_table = trend_table[['PLAYER_NAME', 'Team', 'FD_Position', 'Season MIN', 'L10 MIN', 'L5 MIN', 'L3 MIN', 'Trend Min', 'Season FD_Fantasy', 'L10 FD_Fantasy', 'L5 FD_Fantasy', 'L3 FD_Fantasy',
                                   'Trend FD_Median', 'Season FPPM', 'L10 FPPM', 'L5 FPPM', 'L3 FPPM', 'Trend FPPM', 'FD_Proj', 'Adj FD_Median', 'Adj FD_Ceiling',
                                   'FD_Salary', 'FD_Avg_Val', 'FD_Ceiling_Value']]
        minutes_table = fd_minutes_table
        medians_table = fd_medians_table
        fppm_table = fd_fppm_table
        proj_medians_table = fd_proj_medians_table
    trend_table = trend_table.set_axis(['PLAYER_NAME', 'Team', 'Position', 'Season MIN', 'L10 MIN', 'L5 MIN', 'L3 MIN', 'Trend Min', 'Season Fantasy', 'L10 Fantasy', 'L5 Fantasy', 'L3 Fantasy',
                                        'Trend Median', 'Season FPPM', 'L10 FPPM', 'L5 FPPM', 'L3 FPPM', 'Trend FPPM', 'DK_Proj', 'Adj Median', 'Adj Ceiling',
                                        'Salary', 'Avg_Val', 'Ceiling_Value'], axis=1)
    minutes_table = minutes_table.set_axis(['PLAYER_NAME', 'Team', 'Season MIN', 'L10 MIN', 'L5 MIN', 'L3 MIN', 'Trend Min'], axis=1)
    medians_table = medians_table.set_axis(['PLAYER_NAME', 'Team', 'Season Fantasy', 'L10 Fantasy', 'L5 Fantasy', 'L3 Fantasy', 'Trend Median'], axis=1)
    fppm_table = fppm_table.set_axis(['PLAYER_NAME', 'Team', 'Season FPPM', 'L10 FPPM', 'L5 FPPM', 'L3 FPPM', 'Trend FPPM'], axis=1)
    proj_medians_table = proj_medians_table.set_axis(['PLAYER_NAME', 'Team', 'Position', 'Salary', 'Proj',
                                                      'Adj Median', 'Avg_Val', 'Adj Ceiling', 'Ceiling_Value'], axis=1)
    if split_var1 == 'Overall':
        view_var1 = trend_table.Team.values.tolist()
        split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
        
        if split_var2 == 'Specific Teams':
            team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = view_var1, key='team_var1')
        elif split_var2 == 'All':
            team_var1 = view_var1
        
        split_var3 = st.radio("Would you like to view all positions or specific ones?", ('All', 'Specific Positions'), key='split_var3')
        if split_var3 == 'Specific Positions':
            pos_var1 = st.multiselect('Which positions would you like to include in the tables?', options = ['PG', 'SG', 'SF', 'PF', 'C'], key='pos_var1')
        elif split_var3 == 'All':
            pos_var1 = ['PG', 'SG', 'SF', 'PF', 'C']
        
        proj_var1 = st.slider("Is there a certain projection range you want to view?", 0, 100, (10, 100), key='proj_var1')
            
    elif split_var1 == 'Minutes Trends':
        view_var1 = trend_table.Team.values.tolist()
        split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
        
        if split_var2 == 'Specific Teams':
            team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = view_var1, key='team_var1')
        elif split_var2 == 'All':
            team_var1 = view_var1
        
    elif split_var1 == 'Fantasy Trends':
        view_var1 = trend_table.Team.values.tolist()
        split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
        
        if split_var2 == 'Specific Teams':
            team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = view_var1, key='team_var1')
        elif split_var2 == 'All':
            team_var1 = view_var1
            
    elif split_var1 == 'FPPM Trends':
        view_var1 = trend_table.Team.values.tolist()
        split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
        
        if split_var2 == 'Specific Teams':
            team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = view_var1, key='team_var1')
        elif split_var2 == 'All':
            team_var1 = view_var1
            
    elif split_var1 == 'Slate specific':
        view_var1 = trend_table.Team.values.tolist()
        split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
        
        if split_var2 == 'Specific Teams':
            team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = view_var1, key='team_var1')
        elif split_var2 == 'All':
            team_var1 = view_var1
        
        split_var3 = st.radio("Would you like to view all positions or specific ones?", ('All', 'Specific Positions'), key='split_var3')
        if split_var3 == 'Specific Positions':
            pos_var1 = st.multiselect('Which positions would you like to include in the tables?', options = ['PG', 'SG', 'SF', 'PF', 'C'], key='pos_var1')
        elif split_var3 == 'All':
            pos_var1 = ['PG', 'SG', 'SF', 'PF', 'C']
        
        proj_var1 = st.slider("Is there a certain projection range you want to view?", 0, 100, (10, 100), key='proj_var1')

with col2:
    if split_var1 == 'Overall':
        table_display = trend_table[trend_table['Proj'] >= proj_var1[0]]
        table_display = table_display[table_display['Proj'] <= proj_var1[1]]
        table_display = table_display[table_display['Team'].isin(team_var1)]
        table_display = table_display[table_display['Position'].str.contains('|'.join(pos_var1))]
        table_display = table_display.sort_values(by='Adj Ceiling', ascending=False)
        table_display = table_display.set_index('PLAYER_NAME')
        st.dataframe(table_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
        st.download_button(
            label="Export Trending Numbers",
            data=convert_df_to_csv(table_display),
            file_name='Trending_export.csv',
            mime='text/csv',
        )
            
    elif split_var1 == 'Minutes Trends':
        table_display = minutes_table[minutes_table['Team'].isin(team_var1)]
        table_display = table_display.set_index('PLAYER_NAME')
        st.dataframe(table_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
        st.download_button(
            label="Export Trending Numbers",
            data=convert_df_to_csv(table_display),
            file_name='Trending_export.csv',
            mime='text/csv',
        )
        
    elif split_var1 == 'Fantasy Trends':
        table_display = medians_table[medians_table['Team'].isin(team_var1)]
        table_display = table_display.set_index('PLAYER_NAME')
        st.dataframe(table_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
        st.download_button(
            label="Export Trending Numbers",
            data=convert_df_to_csv(table_display),
            file_name='Trending_export.csv',
            mime='text/csv',
        )
        
    elif split_var1 == 'FPPM Trends':
        table_display = fppm_table[fppm_table['Team'].isin(team_var1)]
        table_display = table_display.set_index('PLAYER_NAME')
        st.dataframe(table_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
        st.download_button(
            label="Export Trending Numbers",
            data=convert_df_to_csv(table_display),
            file_name='Trending_export.csv',
            mime='text/csv',
        )
        
    elif split_var1 == 'Slate specific':
        table_display = proj_medians_table[proj_medians_table['Proj'] >= proj_var1[0]]
        table_display = table_display[table_display['Proj'] <= proj_var1[1]]
        table_display = table_display[table_display['Team'].isin(team_var1)]
        table_display = table_display[table_display['Position'].str.contains('|'.join(pos_var1))]
        table_display = table_display.sort_values(by='Adj Ceiling', ascending=False)
        table_display = table_display.set_index('PLAYER_NAME')
        st.dataframe(table_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
        st.download_button(
            label="Export Trending Numbers",
            data=convert_df_to_csv(table_display),
            file_name='NBA_Trending_export.csv',
            mime='text/csv',
        )