File size: 1,723 Bytes
e23665a
 
 
b92949e
12ff34e
e23665a
b92949e
 
 
 
12ff34e
b92949e
 
 
 
 
 
 
6c12e73
b92949e
6c12e73
 
 
 
 
b92949e
6c12e73
b92949e
 
 
 
7fe9caa
 
 
7a1b6ea
7fe9caa
350005a
6c12e73
7fe9caa
 
 
350005a
 
553595b
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
import numpy as np
import pandas as pd
import streamlit as st
import pymongo
import os

st.set_page_config(layout="wide")

@st.cache_resource
def init_conn():
    uri = os.getenv('mongo_uri')
    client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
    db = client["MLB_Database"]

    return db

db = init_conn()

@st.cache_resource(ttl = 60)
def init_baselines():
    collection = db["HR_Table"] 
    cursor = collection.find()
    raw_display = pd.DataFrame(cursor)
    raw_display.rename(columns={"Names": "Player"}, inplace = True)
    raw_frame = raw_display.drop(columns=['_id']).drop_duplicates(subset='Player')

    return raw_frame

hr_frame = init_baselines()
st.title("HR Finder Table")

disp_options = st.radio("Display options:", options = ['Basics', 'Exclude DFS Info', 'Include DFS Info'], key='display_options')
if disp_options == 'Basics':
    st.session_state['disp_frame'] = hr_frame[['Player', 'xHR/PA', 'Opp_xHR/PA', 'BP_Binom_xHR', 'Binom_xHR']]
    st.session_state['disp_frame'] = st.session_state['disp_frame'].rename(columns={'xHR/PA': 'Hitter', 'Opp_xHR/PA': 'SP', 'BP_Binom_xHR': 'BP', 'Binom_xHR': 'xHRs'})
elif disp_options == 'Exclude DFS Info':
    st.session_state['disp_frame'] = hr_frame.drop(columns=['Salary', 'Position', 'FD_Position', 'Order'])
else:
    st.session_state['disp_frame'] = hr_frame.copy()

st.session_state['disp_frame'] = st.session_state['disp_frame'].sort_values(by='Binom_xHR', ascending=False)

if 'disp_frame' in st.session_state:
    st.dataframe(st.session_state['disp_frame'].style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').format(precision=2), height=1200, use_container_width = True, hide_index = True)