JBOTTUM_models / app.py
Multichem's picture
Update app.py
ae52f5a verified
import pulp
import numpy as np
import pandas as pd
import streamlit as st
import gspread
from itertools import combinations
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")
american_format = {'ML': '{:.2%}'}
mma_format = {'ML_perc': '{:.2%}', 'Min_%': '{:.2%}', 'Med_%': '{:.2%}', }
@st.cache_resource(ttl = 600)
def init_baselines():
sh = gc.open_by_url("https://docs.google.com/spreadsheets/d/1T4n3-KC141n2XwhRCqLssuk1nVdHjsBPSdb8Q6LopuY/edit?gid=0#gid=0")
worksheet = sh.worksheet('JBOTTUM_Tennis')
frame_hold = pd.DataFrame(worksheet.get_all_records())
tennis_model = frame_hold.drop_duplicates(subset='Player')
tennis_model = tennis_model.set_index('Player')
tennis_model = tennis_model.sort_values(by='Median', ascending=False)
sh = gc.open_by_url("https://docs.google.com/spreadsheets/d/1T4n3-KC141n2XwhRCqLssuk1nVdHjsBPSdb8Q6LopuY/edit?gid=0#gid=0")
worksheet = sh.worksheet('JBOTTUM_MMA')
frame_hold = pd.DataFrame(worksheet.get_all_records())
mma_model = frame_hold[['Player', 'Opponent', 'Salary', 'Floor_Adj', 'Median_Adj', 'Ceiling_Adj', 'ML_perc', 'Min_Win', 'Min_%', 'Median_Win', 'Med_%', 'Max_Win']]
mma_model = mma_model.drop_duplicates(subset='Player')
mma_model = mma_model.sort_values(by='Median_Adj', ascending=False)
mma_model = mma_model.set_index('Player')
return tennis_model, mma_model
@st.cache_resource()
def convert_df_to_csv(df):
return df.to_csv().encode('utf-8')
tennis_base, mma_base = init_baselines()
tab1, tab2 = st.tabs(['Tennis Models', 'MMA Models'])
with tab1:
with st.container():
st.dataframe(tennis_base.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
st.download_button(
label="Export Tables",
data=convert_df_to_csv(tennis_base),
file_name='tennis_model_export.csv',
mime='text/csv',
)
with tab2:
with st.container():
st.dataframe(mma_base.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(mma_format, precision=2), height = 1000, use_container_width = True)
st.download_button(
label="Export Tables",
data=convert_df_to_csv(mma_base),
file_name='mma_model_export.csv',
mime='text/csv',
)