import pulp import numpy as np import pandas as pd import streamlit as st import gspread scope = ['https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive"] credentials = { "type": "service_account", "project_id": "sheets-api-connect-378620", "private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9", "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5EvqkZvSyMJHV0EEahZStwhjCfnDB/cxyix\nZ+kFhv4y9eK+kFpUAhBy5nX6T0O+2T6WvzAwbmbVsZ+X8kJyPuF9m8ldcPlD0sce\ntj8NwVq1ys52eosqs7zi2vjt+eMcaY393l4ls+vNq8Yf27cfyFw45W45CH/97/Nu\n5AmuzlCOAfFF+z4OC5g4rei4E/Qgpxa7/uom+BVfv9G0DIGW/tU6Sne0+37uoGKt\nW6DzhgtebUtoYkG7ZJ05BTXGp2lwgVcNRoPwnKJDxQKBgQDT5wYPUBDW+FHbvZSp\nd1m1UQuXyerqOTA9smFaM8sr/UraeH85DJPEIEk8qsntMBVMhvD3Pw8uIUeFNMYj\naLmZFObsL+WctepXrVo5NB6RtLB/jZYxiKMatMLUJIYtcKIp+2z/YtKiWcLnwotB\nWdCjVnPTxpkurmF2fWP/eewZ+wKBgQDRMtJg7etjvKyjYNQ5fARnCc+XsI3gkBe1\nX9oeXfhyfZFeBXWnZzN1ITgFHplDznmBdxAyYGiQdbbkdKQSghviUQ0igBvoDMYy\n1rWcy+a17Mj98uyNEfmb3X2cC6WpvOZaGHwg9+GY67BThwI3FqHIbyk6Ko09WlTX\nQpRQjMzU7QKBgAfi1iflu+q0LR+3a3vvFCiaToskmZiD7latd9AKk2ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/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" } gc = gspread.service_account_from_dict(credentials) st.set_page_config(layout="wide") roo_format = {'Win%': '{:.2%}', 'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '60+%': '{:.2%}','5x%': '{:.2%}','6x%': '{:.2%}','7x%': '{:.2%}','Own': '{:.2%}','LevX': '{:.2%}'} stat_format = {'Odds%': '{:.2%}'} table_format = {'Odds': '{:.2%}'} csgo_overall = 'CSGO_Overall_Proj' csgo_rpl = 'CSGO_RPL_Proj' csgo_neutral = 'CSGO_Neutral_Proj' csgo_wins = 'CSGO_Win_Proj' csgo_losses = 'CSGO_Loss_Proj' overall_odds = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' RPL_odds = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' csgo_bo1 = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' two_map = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' csgo_bo3 = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' csgo_bo5 = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' player_baselines = 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013' @st.cache_data def load_roo_model(URL): sh = gc.open(URL) worksheet = sh.get_worksheet(0) raw_display = pd.DataFrame(worksheet.get_all_records()) try: raw_display["Salary"] = raw_display["Salary"].replace("$", "", regex=True).astype(float) except: pass try: raw_display['Win%'] = raw_display['Win%'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['Top_finish'] = raw_display['Top_finish'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['Top_5_finish'] = raw_display['Top_5_finish'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['Top_10_finish'] = raw_display['Top_10_finish'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['60+%'] = raw_display['60+%'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['5x%'] = raw_display['5x%'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['6x%'] = raw_display['6x%'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['7x%'] = raw_display['7x%'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['Own'] = raw_display['Own'].str.replace('%', '').astype(float)/100 except: pass try: raw_display['LevX'] = raw_display['LevX'].str.replace('%', '').astype(float)/100 except: pass return raw_display @st.cache_data def load_overall_odds(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('Overall_Vegas') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display['Odds'] = raw_display['Odds'].str.replace('%', '').astype(float)/100 return raw_display @st.cache_data def load_rpl_odds(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('RPL_Vegas') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display['Odds'] = raw_display['Odds'].str.replace('%', '').astype(float)/100 raw_display['Vegas'] = raw_display['Vegas'].str.replace('%', '').astype(float)/100 raw_display = raw_display[['Team', 'Opponent', 'RPL', 'Opp_RPL', 'RPL_Diff', 'Vegas', 'Odds', 'P Rounds']] return raw_display @st.cache_data def load_bo1_proj_model(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('Overall_BO1_Projections') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display.rename(columns={"Name": "Player"}, inplace = True) raw_display['Odds%'] = raw_display['Odds%'].str.replace('%', '').astype(float)/100 raw_display = raw_display.sort_values(by='Kills', ascending=False) return raw_display @st.cache_data def two_map_load(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('2_map_projections') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display.rename(columns={"Name": "Player"}, inplace = True) raw_display['Odds%'] = raw_display['Odds%'].str.replace('%', '').astype(float)/100 raw_display = raw_display.sort_values(by='Kills', ascending=False) return raw_display @st.cache_data def load_bo3_proj_model(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('Overall_BO3_Projections') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display.rename(columns={"Name": "Player"}, inplace = True) raw_display['Odds%'] = raw_display['Odds%'].str.replace('%', '').astype(float)/100 raw_display = raw_display.sort_values(by='Kills', ascending=False) return raw_display @st.cache_data def load_bo5_proj_model(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('Overall_BO5_Projections') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display.rename(columns={"Name": "Player"}, inplace = True) raw_display['Odds%'] = raw_display['Odds%'].str.replace('%', '').astype(float)/100 raw_display = raw_display.sort_values(by='Kills', ascending=False) return raw_display @st.cache_data def load_slate_baselines(URL): sh = gc.open_by_url(URL) worksheet = sh.worksheet('Player_Data') raw_display = pd.DataFrame(worksheet.get_all_records()) raw_display.rename(columns={"Name": "Player"}, inplace = True) raw_display = raw_display.sort_values(by='Kills/Round', ascending=False) return raw_display hold_display = load_roo_model(csgo_overall) tab1, tab2, tab3, tab4, tab5 = st.tabs(["CSGO Odds Tables", "CSGO Range of Outcomes", "CSGO Player Stat Projections", "CSGO Slate Baselines", '2-map Projections']) def convert_df_to_csv(df): return df.to_csv().encode('utf-8') with tab1: if st.button("Reset Data", key='reset4'): # Clear values from *all* all in-memory and on-disk data caches: # i.e. clear values from both square and cube st.cache_data.clear() odds_choice = st.radio("What table would you like to display?", ('Overall', 'RPL'), key='odds_table') if odds_choice == 'Overall': hold_display = load_overall_odds(overall_odds) elif odds_choice == 'RPL': hold_display = load_rpl_odds(RPL_odds) display = hold_display.set_index('Team') st.dataframe(display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(table_format, precision=2), use_container_width = True) st.download_button( label="Export Tables", data=convert_df_to_csv(display), file_name='CSGO_Odds_Tables_export.csv', mime='text/csv', ) with tab2: if st.button("Reset Data", key='reset1'): # Clear values from *all* all in-memory and on-disk data caches: # i.e. clear values from both square and cube st.cache_data.clear() model_choice = st.radio("What table would you like to display?", ('Overall', 'RPL', 'Neutral', 'Wins', 'Losses'), key='roo_table') team_var1 = st.multiselect('View specific team?', options = hold_display['Team'].unique(), key = 'roo_teamvar') if model_choice == 'Overall': hold_display = load_roo_model(csgo_overall) elif model_choice == 'RPL': hold_display = load_roo_model(csgo_rpl) elif model_choice == 'Neutral': hold_display = load_roo_model(csgo_neutral) elif model_choice == 'Wins': hold_display = load_roo_model(csgo_wins) elif model_choice == 'Losses': hold_display = load_roo_model(csgo_losses) hold_display['Own'] = hold_display['Own'] / 100 display = hold_display.set_index('Player') export_display = display export_display['Own'] = export_display['Own'] *100 export_display['Position'] = "FLEX" if team_var1: display = display[display['Team'].isin(team_var1)] st.dataframe(display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(roo_format, precision=2), use_container_width = True) st.download_button( label="Export Range of Outcomes", data=convert_df_to_csv(export_display), file_name='CSGO_ROO_export.csv', mime='text/csv', ) with tab3: if st.button("Reset Data", key='reset2'): # Clear values from *all* all in-memory and on-disk data caches: # i.e. clear values from both square and cube st.cache_data.clear() gametype_choice = st.radio("What format are the games being played?", ('Best of 1', 'Best of 3', 'Best of 5'), key='player_stats') team_var2 = st.multiselect('View specific team?', options = hold_display['Team'].unique(), key = 'stat_teamvar') if gametype_choice == 'Best of 1': hold_display = load_bo1_proj_model(csgo_bo1) elif gametype_choice == 'Best of 3': hold_display = load_bo3_proj_model(csgo_bo3) elif gametype_choice == 'Best of 5': hold_display = load_bo5_proj_model(csgo_bo5) display = hold_display.set_index('Player') if team_var2: display = display[display['Team'].isin(team_var2)] st.dataframe(display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(stat_format, precision=2), use_container_width = True) st.download_button( label="Export Projections", data=convert_df_to_csv(display), file_name='CSGO_Projections_export.csv', mime='text/csv', ) with tab4: if st.button("Reset Data", key='reset3'): # Clear values from *all* all in-memory and on-disk data caches: # i.e. clear values from both square and cube st.cache_data.clear() hold_display = load_slate_baselines(player_baselines) display = hold_display.set_index('Player') st.dataframe(display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True) st.download_button( label="Export Baselines", data=convert_df_to_csv(display), file_name='CSGO_Baselines_export.csv', mime='text/csv', ) with tab5: if st.button("Reset Data", key='reset5'): # Clear values from *all* all in-memory and on-disk data caches: # i.e. clear values from both square and cube st.cache_data.clear() hold_display = two_map_load(two_map) display = hold_display.set_index('Player') st.dataframe(display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True) st.download_button( label="Export Baselines", data=convert_df_to_csv(display), file_name='CSGO_2_map_export.csv', mime='text/csv', )