Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,4 +17,134 @@ credentials = {
|
|
| 17 |
"token_uri": "https://oauth2.googleapis.com/token",
|
| 18 |
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 19 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 20 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"token_uri": "https://oauth2.googleapis.com/token",
|
| 18 |
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 19 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Set up gspread service account
|
| 23 |
+
gc = gspread.service_account_from_dict(credentials)
|
| 24 |
+
|
| 25 |
+
# Set Streamlit page config
|
| 26 |
+
st.set_page_config(layout="wide")
|
| 27 |
+
|
| 28 |
+
# Define formats for dataframes
|
| 29 |
+
roo_format = {'Win%': '{:.2%}', 'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}',
|
| 30 |
+
'60+%': '{:.2%}', '5x%': '{:.2%}', '6x%': '{:.2%}', '7x%': '{:.2%}', 'Own': '{:.2%}', 'LevX': '{:.2%}'}
|
| 31 |
+
stat_format = {'Odds%': '{:.2%}'}
|
| 32 |
+
table_format = {'Odds': '{:.2%}'}
|
| 33 |
+
|
| 34 |
+
# Define sheet URLs
|
| 35 |
+
sheet_urls = {
|
| 36 |
+
'csgo_overall': 'CSGO_Overall_Proj',
|
| 37 |
+
'csgo_rpl': 'CSGO_RPL_Proj',
|
| 38 |
+
'csgo_neutral': 'CSGO_Neutral_Proj',
|
| 39 |
+
'csgo_wins': 'CSGO_Win_Proj',
|
| 40 |
+
'csgo_losses': 'CSGO_Loss_Proj',
|
| 41 |
+
'overall_odds': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013',
|
| 42 |
+
'RPL_odds': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013',
|
| 43 |
+
'csgo_bo1': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013',
|
| 44 |
+
'two_map': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013',
|
| 45 |
+
'csgo_bo3': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013',
|
| 46 |
+
'csgo_bo5': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013',
|
| 47 |
+
'player_baselines': 'https://docs.google.com/spreadsheets/d/1aLVN4izjSuqZGRyz73Kip6U1q3rubh6v9GrckgEqbfs/edit?pli=1#gid=1545712013'
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
# Define function to load data from Google Sheets
|
| 51 |
+
@st.cache_data
|
| 52 |
+
def load_data(sheet_name, worksheet_name=None):
|
| 53 |
+
try:
|
| 54 |
+
sh = gc.open_by_url(sheet_name)
|
| 55 |
+
worksheet = sh.get_worksheet(0) if not worksheet_name else sh.worksheet(worksheet_name)
|
| 56 |
+
df = pd.DataFrame(worksheet.get_all_records())
|
| 57 |
+
return df
|
| 58 |
+
except Exception as e:
|
| 59 |
+
st.error(f"Error loading data: {e}")
|
| 60 |
+
return pd.DataFrame()
|
| 61 |
+
|
| 62 |
+
# Define function to convert dataframe to CSV
|
| 63 |
+
def convert_df_to_csv(df):
|
| 64 |
+
return df.to_csv().encode('utf-8')
|
| 65 |
+
|
| 66 |
+
# Load initial data
|
| 67 |
+
hold_display = load_data(sheet_urls['csgo_overall'])
|
| 68 |
+
|
| 69 |
+
# Define tabs for the app
|
| 70 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(["CSGO Odds Tables", "CSGO Range of Outcomes", "CSGO Player Stat Projections", "CSGO Slate Baselines", '2-map Projections'])
|
| 71 |
+
|
| 72 |
+
with tab1:
|
| 73 |
+
if st.button("Reset Data", key='reset4'):
|
| 74 |
+
st.cache_data.clear()
|
| 75 |
+
|
| 76 |
+
odds_choice = st.radio("What table would you like to display?", ('Overall', 'RPL'), key='odds_table')
|
| 77 |
+
if odds_choice == 'Overall':
|
| 78 |
+
hold_display = load_data(sheet_urls['overall_odds'], 'Overall_Vegas')
|
| 79 |
+
elif odds_choice == 'RPL':
|
| 80 |
+
hold_display = load_data(sheet_urls['RPL_odds'], 'RPL_Vegas')
|
| 81 |
+
|
| 82 |
+
hold_display['Odds'] = hold_display['Odds'].str.replace('%', '').astype(float)/100
|
| 83 |
+
display = hold_display.set_index('Team')
|
| 84 |
+
st.dataframe(display.style.background_gradient(cmap='RdYlGn').format(table_format, precision=2), use_container_width=True)
|
| 85 |
+
st.download_button(label="Export Tables", data=convert_df_to_csv(display), file_name='CSGO_Odds_Tables_export.csv', mime='text/csv')
|
| 86 |
+
|
| 87 |
+
with tab2:
|
| 88 |
+
if st.button("Reset Data", key='reset1'):
|
| 89 |
+
st.cache_data.clear()
|
| 90 |
+
|
| 91 |
+
model_choice = st.radio("What table would you like to display?", ('Overall', 'RPL', 'Neutral', 'Wins', 'Losses'), key='roo_table')
|
| 92 |
+
team_var1 = st.multiselect('View specific team?', options=hold_display['Team'].unique(), key='roo_teamvar')
|
| 93 |
+
|
| 94 |
+
if model_choice == 'Overall':
|
| 95 |
+
hold_display = load_data(sheet_urls['csgo_overall'])
|
| 96 |
+
elif model_choice == 'RPL':
|
| 97 |
+
hold_display = load_data(sheet_urls['csgo_rpl'])
|
| 98 |
+
elif model_choice == 'Neutral':
|
| 99 |
+
hold_display = load_data(sheet_urls['csgo_neutral'])
|
| 100 |
+
elif model_choice == 'Wins':
|
| 101 |
+
hold_display = load_data(sheet_urls['csgo_wins'])
|
| 102 |
+
elif model_choice == 'Losses':
|
| 103 |
+
hold_display = load_data(sheet_urls['csgo_losses'])
|
| 104 |
+
|
| 105 |
+
hold_display['Own'] = hold_display['Own'] / 100
|
| 106 |
+
display = hold_display.set_index('Player')
|
| 107 |
+
export_display = display.copy()
|
| 108 |
+
export_display['Own'] = export_display['Own'] * 100
|
| 109 |
+
export_display['Position'] = "FLEX"
|
| 110 |
+
|
| 111 |
+
if team_var1:
|
| 112 |
+
display = display[display['Team'].isin(team_var1)]
|
| 113 |
+
|
| 114 |
+
st.dataframe(display.style.background_gradient(cmap='RdYlGn').format(roo_format, precision=2), use_container_width=True)
|
| 115 |
+
st.download_button(label="Export Range of Outcomes", data=convert_df_to_csv(export_display), file_name='CSGO_ROO_export.csv', mime='text/csv')
|
| 116 |
+
|
| 117 |
+
with tab3:
|
| 118 |
+
if st.button("Reset Data", key='reset2'):
|
| 119 |
+
st.cache_data.clear()
|
| 120 |
+
|
| 121 |
+
gametype_choice = st.radio("What format are the games being played?", ('Best of 1', 'Best of 3', 'Best of 5'), key='player_stats')
|
| 122 |
+
team_var2 = st.multiselect('View specific team?', options=hold_display['Team'].unique(), key='stat_teamvar')
|
| 123 |
+
|
| 124 |
+
if gametype_choice == 'Best of 1':
|
| 125 |
+
hold_display = load_data(sheet_urls['csgo_bo1'], 'Overall_BO1_Projections')
|
| 126 |
+
elif gametype_choice == 'Best of 3':
|
| 127 |
+
hold_display = load_data(sheet_urls['csgo_bo3'], 'Overall_BO3_Projections')
|
| 128 |
+
elif gametype_choice == 'Best of 5':
|
| 129 |
+
hold_display = load_data(sheet_urls['csgo_bo5'], 'Overall_BO5_Projections')
|
| 130 |
+
|
| 131 |
+
display = hold_display.set_index('Player')
|
| 132 |
+
|
| 133 |
+
if team_var2:
|
| 134 |
+
display = display[display['Team'].isin(team_var2)]
|
| 135 |
+
|
| 136 |
+
st.dataframe(display.style.background_gradient(cmap='RdYlGn').format(stat_format, precision=2), use_container_width=True)
|
| 137 |
+
st.download_button(label="Export Projections", data=convert_df_to_csv(display), file_name='CSGO_Projections_export.csv', mime='text/csv')
|
| 138 |
+
|
| 139 |
+
with tab4:
|
| 140 |
+
if st.button("Reset Data", key='reset3'):
|
| 141 |
+
st.cache_data.clear()
|
| 142 |
+
|
| 143 |
+
hold_display = load_data(sheet_urls['player_baselines'], 'Player_Data')
|
| 144 |
+
display = hold_display.set_index('Player')
|
| 145 |
+
st.dataframe(display.style.background_gradient(cmap='RdYlGn').format(precision=2), use_container_width=True)
|
| 146 |
+
st.download_button(label="Export Baselines", data=convert_df_to_csv(display), file_name='CSGO_Baselines_export.csv', mime='text/csv')
|
| 147 |
+
|
| 148 |
+
with tab5:
|
| 149 |
+
if st.button("Reset Data", key='reset5'):
|
| 150 |
+
st.cache_data.clear()
|