File size: 12,871 Bytes
69b5aee
 
 
 
 
 
 
ee74e6c
69b5aee
 
 
67fdcc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69b5aee
 
 
 
 
 
 
 
 
 
 
 
 
 
50ac5b0
 
 
 
67fdcc7
 
 
e17e663
4789d7b
 
31420bc
67fdcc7
69b5aee
 
 
31420bc
 
 
69b5aee
 
 
 
31420bc
 
 
69b5aee
 
 
 
31420bc
 
 
69b5aee
 
 
 
31420bc
 
 
69b5aee
67fdcc7
69b5aee
67fdcc7
69b5aee
 
 
 
 
fccc635
 
 
 
 
 
 
 
 
 
 
 
 
2e4a5ae
fccc635
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69b5aee
fccc635
 
 
 
67fdcc7
fccc635
 
 
 
2e4a5ae
 
 
 
 
 
 
fccc635
 
 
 
 
 
 
 
 
 
 
 
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
import pulp
import numpy as np
import pandas as pd
import streamlit as st
import gspread
from itertools import combinations
import time
st.set_page_config(layout="wide")

@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": st.secrets['model_sheets_connect_pk'],
          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elwOLdV\nXRLrLWJfX8+O1z/UE15l2q3SUEnQ4esPHbQnZowHLm0mdL14qSVMl1mu1XfsoZ3z\nJZTQb48CIwKBgEWbzQRtKD8lKDupJEYqSrseRbK/ax43DDITS77/DWwHl33D3FYC\nMblUm8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
          "client_email": "[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"
        }
        
        credentials2 = {
          "type": "service_account",
          "project_id": "sheets-api-connect-378620",
          "private_key_id": st.secrets['sheets_api_connect_pk'],
          "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na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K0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
          "client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
          "client_id": "106625872877651920064",
          "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%40sheets-api-connect-378620.iam.gserviceaccount.com"
        }
     
        NBA_Data = st.secrets['NBA_Data']

        gc = gspread.service_account_from_dict(credentials)
        gc2 = gspread.service_account_from_dict(credentials2)

        return gc, gc2, NBA_Data
    
gcservice_account, gcservice_account2, NBA_Data = init_conn()

game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
              'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}

team_roo_format = {'Top Score%': '{:.2%}','0 Runs': '{:.2%}', '1 Run': '{:.2%}', '2 Runs': '{:.2%}', '3 Runs': '{:.2%}', '4 Runs': '{:.2%}',
                   '5 Runs': '{:.2%}','6 Runs': '{:.2%}', '7 Runs': '{:.2%}', '8 Runs': '{:.2%}', '9 Runs': '{:.2%}', '10 Runs': '{:.2%}'}

player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
                   '4x%': '{:.2%}','GPP%': '{:.2%}'}

expose_format = {'Proj Own': '{:.2%}','Exposure': '{:.2%}'}

@st.cache_resource(ttl=30)
def init_load():
    try:
        sh = gcservice_account.open_by_url(NBA_Data)
    except:
        sh = gcservice_account2.open_by_url(NBA_Data)
    worksheet = sh.worksheet('Player_Level_SD_ROO')
    load_display = pd.DataFrame(worksheet.get_all_records())
    load_display.replace('', np.nan, inplace=True)
    load_display.rename(columns={"Name": "Player", "Fantasy": "Median", "Minutes Proj": "Minutes"}, inplace = True)

    timestamp = load_display['timestamp'].values[0]
    roo_raw = load_display.loc[load_display['Median'] > 0]

    worksheet = sh.worksheet('DK_SD_Build')
    load_display = pd.DataFrame(worksheet.get_all_records())
    load_display.replace('', np.nan, inplace=True)
    load_display.rename(columns={"Name": "Player", "Fantasy": "Median"}, inplace = True)
    load_display = load_display[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Minutes', 'Median', 'Own']]
    dk_roo_raw = load_display.loc[load_display['Median'] > 0]

    worksheet = sh.worksheet('FD_SD_Build')
    load_display = pd.DataFrame(worksheet.get_all_records())
    load_display.replace('', np.nan, inplace=True)
    load_display.rename(columns={"Name": "Player", "Fantasy": "Median"}, inplace = True)
    load_display = load_display[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Minutes', 'Median', 'Own']]
    fd_roo_raw = load_display.loc[load_display['Median'] > 0]

    worksheet = sh.worksheet('DK_SD2_Build')
    load_display = pd.DataFrame(worksheet.get_all_records())
    load_display.replace('', np.nan, inplace=True)
    load_display.rename(columns={"Name": "Player", "Fantasy": "Median"}, inplace = True)
    load_display = load_display[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Minutes', 'Median', 'Own']]
    dk_roo_raw_2 = load_display.loc[load_display['Median'] > 0]

    worksheet = sh.worksheet('FD_SD2_Build')
    load_display = pd.DataFrame(worksheet.get_all_records())
    load_display.replace('', np.nan, inplace=True)
    load_display.rename(columns={"Name": "Player", "Fantasy": "Median"}, inplace = True)
    load_display = load_display[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', 'Own', 'Minutes']]
    fd_roo_raw_2 = load_display.loc[load_display['Median'] > 0]

    return roo_raw, dk_roo_raw, dk_roo_raw_2, fd_roo_raw, fd_roo_raw_2, timestamp

roo_raw, dk_roo_raw, dk_roo_raw_2, fd_roo_raw, fd_roo_raw_2, t_stamp = init_load()

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

tab1, tab2 = st.tabs(['Range of Outcomes', 'Uploads and Info'])

with tab1:
    col1, col2 = st.columns([1, 9])

    with col1:
        st.info(t_stamp)
        if st.button("Load/Reset Data", key='reset1'):
            st.cache_data.clear()
            dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = init_load()
            t_stamp = f"Last Update: " + str(timestamp) + f" CST"
            for key in st.session_state.keys():
                del st.session_state[key]
        table_view2 = st.radio("What view would you like to display?", ('Simple', 'Advanced'), key='table_view2')
        site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
        if site_var2 == 'Draftkings':
            site_baselines = roo_raw[roo_raw['site'] == 'Draftkings']
        elif site_var2 == 'Fanduel':
            site_baselines = roo_raw[roo_raw['site'] == 'Fanduel']
        slate_split = st.radio("Are you viewing the main slate or the secondary slate?", ('Showdown #1', 'Showdown #2'), key='slate_split')
        if slate_split == 'Showdown #1':
            raw_baselines = site_baselines[site_baselines['slate'] == 'Showdown #1']
        elif slate_split == 'Showdown #2':
            raw_baselines = site_baselines[site_baselines['slate'] == 'Showdown #2']
        split_var2 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var2')
        if split_var2 == 'Specific Games':
            team_var2 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var2')
        elif split_var2 == 'Full Slate Run':
            team_var2 = raw_baselines.Team.values.tolist()
        pos_var2 = st.selectbox('View specific position?', options = ['All', 'PG', 'SG', 'SF', 'PF', 'C'], key='pos_var2')

    with col2:
        display_container_1 = st.empty()
        display_dl_container_1 = st.empty()
        display_proj = raw_baselines[raw_baselines['Team'].isin(team_var2)]
        display_proj = display_proj.drop(columns=['site', 'version', 'slate', 'timestamp'])
        
        st.session_state.display_proj = display_proj
            
        with display_container_1:
            display_container = st.empty()
            if 'display_proj' in st.session_state:
                if pos_var2 == 'All':
                    st.session_state.display_proj = st.session_state.display_proj
                elif pos_var2 != 'All':
                    st.session_state.display_proj = st.session_state.display_proj[st.session_state.display_proj['Position'].str.contains(pos_var2)]
                if table_view2 == 'Simple':
                    st.session_state.display_proj = st.session_state.display_proj[['Player', 'Team', 'Position', 'Median', 'GPP%', 'Own']]
                    st.dataframe(st.session_state.display_proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
                elif table_view2 == 'Advanced':
                    st.session_state.display_proj = st.session_state.display_proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%',
                    'Own', 'Small_Own', 'Large_Own', 'Cash_Own', 'CPT_Own']]
                    st.dataframe(st.session_state.display_proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
        
        with display_dl_container_1:
                display_dl_container = st.empty()
                if 'display_proj' in st.session_state:
                    st.download_button(
                                label="Export Tables",
                                data=convert_df_to_csv(st.session_state.display_proj),
                                file_name='NBA_SD_ROO_export.csv',
                                mime='text/csv',
                    )
with tab2:
    st.write("Yeah man idk that's crazy")