File size: 6,063 Bytes
ab2c04b
5847715
 
ab2c04b
d5d4d17
 
 
ab2c04b
 
 
 
 
d5d4d17
ab2c04b
d5d4d17
ab2c04b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d5d4d17
ab2c04b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
import pandas as pd
import pymongo

st.set_page_config(layout="wide")

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

        return db
    
db = init_conn()

st.markdown("""
<style>
    /* Tab styling */
    .stTabs [data-baseweb="tab-list"] {
        gap: 8px;
        padding: 4px;
    }
    .stTabs [data-baseweb="tab"] {
        height: 50px;
        white-space: pre-wrap;
        background-color: #DAA520;
        color: white;
        border-radius: 10px;
        gap: 1px;
        padding: 10px 20px;
        font-weight: bold;
        transition: all 0.3s ease;
    }
    .stTabs [aria-selected="true"] {
        background-color: #DAA520;
        border: 3px solid #FFD700;
        color: white;
    }
    .stTabs [data-baseweb="tab"]:hover {
        background-color: #FFD700;
        cursor: pointer;
    }
    div[data-baseweb="select"] > div {
        background-color: #DAA520;
        color: white;
    }
    div{
        box-sizing: content-box !important;
    }
</style>""", unsafe_allow_html=True)

@st.cache_resource(ttl = 61)
def init_baselines():

    db_pulls = ['Bullpen_Data', 'Hitter_Agg_Merge', 'Hitter_Long_Merge', 'Hitter_Short_Merge', 'Pitcher_Agg_Merge', 'Pitcher_Long_Merge', 'Pitcher_Short_Merge',
                'Slate_Hitters_Merge', 'Slate_Team_Merge', 'Starting_Pitchers', 'True_AVG_Split', 'Pitcher_Info', 'Hitter_Info']

    for table in db_pulls:
        collection = db[table] 
        cursor = collection.find()
        df = pd.DataFrame(cursor)

        if table == 'Bullpen_Data':
            bp_data = df
        elif table == 'Hitter_Agg_Merge':
            hitter_agg = df
        elif table == 'Hitter_Long_Merge':
            hitter_long = df
        elif table == 'Hitter_Short_Merge':
            hitter_short = df
        elif table == 'Pitcher_Agg_Merge':
            pitcher_agg = df
        elif table == 'Pitcher_Long_Merge':
            pitcher_long = df
        elif table == 'Pitcher_Short_Merge':
            pitcher_short = df
        elif table == 'Slate_Hitters_Merge':
            slate_hitters = df
        elif table == 'Slate_Team_Merge':
            slate_team = df
        elif table == 'Starting_Pitchers':  
            starting_pitchers = df
        elif table == 'True_AVG_Split':
            true_avg_split = df
        elif table == 'Pitcher_Info':
            pitcher_info = df
        elif table == 'Hitter_Info':    
            hitter_info = df

    return bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitcher_short, slate_hitters, slate_team, starting_pitchers, true_avg_split, pitcher_info, hitter_info

bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitcher_short, slate_hitters, slate_team, starting_pitchers, true_avg_split, pitcher_info, hitter_info = init_baselines()

pitcher_tab, hitter_tab, team_tab = st.tabs(['Pitchers', 'Hitters', 'Team'])

with pitcher_tab:
    with st.expander('Info and Display Options'):
        st.info('Note: Splits options are available for all baseline tables, they do not apply to True AVG, HWSr, or the Overview tables')
        col1, col2, col3 = st.columns(3)
        with col1:
            site_var_sp = st.selectbox('Site', ['DraftKings', 'FanDuel'], key = 'site_var_sp')
        with col2:
            table_var_sp = st.selectbox('Table', ['True AVG Splits', 'HWSr Splits', 'Current Slate Overview', 'Active Baselines', 'League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines'], key = 'table_var_sp')
        with col3:
            splits_var_sp = st.selectbox('Splits', ['Overall', 'RHH', 'LHH'], key = 'splits_var_sp')
    
    if table_var_sp == 'True AVG Splits':
        st.dataframe(true_avg_split)
    elif table_var_sp == 'HWSr Splits':
        st.dataframe(true_avg_split)
    elif table_var_sp == 'Current Slate Overview':
        st.dataframe(starting_pitchers)
    elif table_var_sp == 'Active Baselines':
        st.dataframe(pitcher_info)
    elif table_var_sp == 'League Aggregate Baselines':
        st.dataframe(pitcher_agg)
    elif table_var_sp == 'League Short Term Baselines':
        st.dataframe(pitcher_short)
    elif table_var_sp == 'League Long Term Baselines':
        st.dataframe(pitcher_long)

with hitter_tab:
    with st.expander('Info and Display Options'):
        st.info('Note: Splits options are available for all baseline tables')
        col1, col2, col3 = st.columns(3)
        with col1:
            site_var_hitter = st.selectbox('Site', ['DraftKings', 'FanDuel'], key = 'site_var_hitter')
        with col2:
            table_var_hitter = st.selectbox('Table', ['Active Baselines', 'League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines'], key = 'table_var_hitter')
        with col3:
            splits_var_hitter = st.selectbox('Splits', ['Overall', 'RHP', 'LHP'], key = 'splits_var_hitter')

    if table_var_hitter == 'Current Slate Overview':
        st.dataframe(starting_pitchers)
    elif table_var_hitter == 'Active Baselines':
        st.dataframe(hitter_info)
    elif table_var_hitter == 'League Aggregate Baselines':
        st.dataframe(hitter_agg)
    elif table_var_hitter == 'League Short Term Baselines':
        st.dataframe(hitter_short)
    elif table_var_hitter == 'League Long Term Baselines':
        st.dataframe(hitter_long)

with team_tab:
    with st.expander('Info and Display Options'):
        col1, col2, col3 = st.columns(3)
        with col1:
            site_var_team= st.selectbox('Site', ['DraftKings', 'FanDuel'], key = 'site_var_team')
        with col2:
            table_var_team = st.selectbox('Table', ['Team Baselines', 'Bullpen Baselines'], key = 'table_var_team')
    
    if table_var_team == 'Team Baselines':
        st.dataframe(slate_team)
    elif table_var_team == 'Bullpen Baselines':
        st.dataframe(bp_data)