Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,8 @@ gcservice_account, client, db = init_conn()
|
|
40 |
MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
|
41 |
|
42 |
percentages_format = {'Exposure': '{:.2%}'}
|
|
|
|
|
43 |
|
44 |
@st.cache_data(ttl = 600)
|
45 |
def init_baselines():
|
@@ -64,8 +66,7 @@ def init_DK_seed_frame():
|
|
64 |
collection = db["DK_MLB_seed_frame"]
|
65 |
cursor = collection.find()
|
66 |
|
67 |
-
|
68 |
-
DK_seed = raw_display[['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'salary', 'proj']]
|
69 |
|
70 |
return DK_seed
|
71 |
|
@@ -74,16 +75,23 @@ def init_FD_seed_frame():
|
|
74 |
collection = db["FD_MLB_seed_frame"]
|
75 |
cursor = collection.find()
|
76 |
|
77 |
-
|
78 |
-
FD_seed = raw_display[['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'salary', 'proj']]
|
79 |
|
80 |
return FD_seed
|
81 |
|
82 |
@st.cache_data
|
83 |
-
def convert_df(
|
84 |
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
|
|
85 |
return df.to_csv().encode('utf-8')
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
dk_raw, fd_raw = init_baselines()
|
88 |
|
89 |
tab1, tab2 = st.tabs(['Data Export', 'Contest Sims'])
|
@@ -100,6 +108,7 @@ with tab1:
|
|
100 |
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'))
|
101 |
if site_var1 == 'Draftkings':
|
102 |
raw_baselines = dk_raw
|
|
|
103 |
|
104 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
105 |
if team_var1 == 'Specific Teams':
|
@@ -115,6 +124,7 @@ with tab1:
|
|
115 |
|
116 |
elif site_var1 == 'Fanduel':
|
117 |
raw_baselines = fd_raw
|
|
|
118 |
|
119 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
120 |
if team_var1 == 'Specific Teams':
|
@@ -132,16 +142,13 @@ with tab1:
|
|
132 |
if st.button("Load Seed Frame", key='seed_frame_load'):
|
133 |
if site_var1 == 'Draftkings':
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
data_export_display =
|
139 |
st.session_state.data_export_display = data_export_display.copy()
|
140 |
-
st.session_state.data_export =
|
141 |
-
st.session_state.data_export_freq =
|
142 |
-
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
143 |
-
st.session_state.data_export_freq['Freq'] = st.session_state.data_export_freq['Freq'].astype(int)
|
144 |
-
st.session_state.data_export_freq['Exposure'] = st.session_state.data_export_freq['Freq']/(len(st.session_state.data_export_expo['Team']))
|
145 |
|
146 |
if 'data_export' in st.session_state:
|
147 |
st.download_button(
|
@@ -158,16 +165,14 @@ with tab1:
|
|
158 |
st.dataframe(st.session_state.data_export_freq.style.format(percentages_format, precision=2), height=500, use_container_width=True)
|
159 |
|
160 |
elif site_var1 == 'Fanduel':
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
165 |
st.session_state.data_export_display = data_export_display.copy()
|
166 |
-
st.session_state.data_export =
|
167 |
-
st.session_state.data_export_freq =
|
168 |
-
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
169 |
-
st.session_state.data_export_freq['Freq'] = st.session_state.data_export_freq['Freq'].astype(int)
|
170 |
-
st.session_state.data_export_freq['Exposure'] = st.session_state.data_export_freq['Freq']/(len(st.session_state.data_export_expo['Team']))
|
171 |
|
172 |
if 'data_export' in st.session_state:
|
173 |
st.download_button(
|
|
|
40 |
MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
|
41 |
|
42 |
percentages_format = {'Exposure': '{:.2%}'}
|
43 |
+
dk_columns = [['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
|
44 |
+
fd_columns = [['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL']]
|
45 |
|
46 |
@st.cache_data(ttl = 600)
|
47 |
def init_baselines():
|
|
|
66 |
collection = db["DK_MLB_seed_frame"]
|
67 |
cursor = collection.find()
|
68 |
|
69 |
+
DK_seed = np.array(list(cursor))
|
|
|
70 |
|
71 |
return DK_seed
|
72 |
|
|
|
75 |
collection = db["FD_MLB_seed_frame"]
|
76 |
cursor = collection.find()
|
77 |
|
78 |
+
FD_seed = np.array(list(cursor))
|
|
|
79 |
|
80 |
return FD_seed
|
81 |
|
82 |
@st.cache_data
|
83 |
+
def convert_df(array):
|
84 |
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
85 |
+
array = pd.DataFrame(array, columns=column_names)
|
86 |
return df.to_csv().encode('utf-8')
|
87 |
|
88 |
+
@st.cache_data
|
89 |
+
def calculate_value_frequencies(np_array):
|
90 |
+
unique, counts = np.unique(np_array, return_counts=True)
|
91 |
+
frequencies = counts / len(np_array) # Normalize by the number of rows
|
92 |
+
combined_array = np.column_stack((unique, frequencies))
|
93 |
+
return combined_array
|
94 |
+
|
95 |
dk_raw, fd_raw = init_baselines()
|
96 |
|
97 |
tab1, tab2 = st.tabs(['Data Export', 'Contest Sims'])
|
|
|
108 |
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'))
|
109 |
if site_var1 == 'Draftkings':
|
110 |
raw_baselines = dk_raw
|
111 |
+
column_names = dk_columns
|
112 |
|
113 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
114 |
if team_var1 == 'Specific Teams':
|
|
|
124 |
|
125 |
elif site_var1 == 'Fanduel':
|
126 |
raw_baselines = fd_raw
|
127 |
+
column_names = fd_columns
|
128 |
|
129 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
130 |
if team_var1 == 'Specific Teams':
|
|
|
142 |
if st.button("Load Seed Frame", key='seed_frame_load'):
|
143 |
if site_var1 == 'Draftkings':
|
144 |
|
145 |
+
working_seed = init_DK_seed_frame()
|
146 |
+
working_seed_parse = working_seed[np.isin(working_seed[:, 2], team_var2)]
|
147 |
+
working_seed_parse = working_seed[np.isin(working_seed[:, 3], stack_var2)]
|
148 |
+
data_export_display = working_seed_parse[0:1000]
|
149 |
st.session_state.data_export_display = data_export_display.copy()
|
150 |
+
st.session_state.data_export = working_seed.copy()
|
151 |
+
st.session_state.data_export_freq = calculate_value_frequencies(my_array)
|
|
|
|
|
|
|
152 |
|
153 |
if 'data_export' in st.session_state:
|
154 |
st.download_button(
|
|
|
165 |
st.dataframe(st.session_state.data_export_freq.style.format(percentages_format, precision=2), height=500, use_container_width=True)
|
166 |
|
167 |
elif site_var1 == 'Fanduel':
|
168 |
+
|
169 |
+
working_seed = init_FD_seed_frame()
|
170 |
+
working_seed_parse = working_seed[np.isin(working_seed[:, 2], team_var2)]
|
171 |
+
working_seed_parse = working_seed[np.isin(working_seed[:, 3], stack_var2)]
|
172 |
+
data_export_display = working_seed_parse[0:1000]
|
173 |
st.session_state.data_export_display = data_export_display.copy()
|
174 |
+
st.session_state.data_export = working_seed.copy()
|
175 |
+
st.session_state.data_export_freq = calculate_value_frequencies(my_array)
|
|
|
|
|
|
|
176 |
|
177 |
if 'data_export' in st.session_state:
|
178 |
st.download_button(
|