Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,14 +30,14 @@ def init_conn():
|
|
| 30 |
cursor = collection.find()
|
| 31 |
|
| 32 |
raw_display = pd.DataFrame(list(cursor))
|
| 33 |
-
raw_display = raw_display[['
|
| 34 |
DK_seed = raw_display.to_numpy()
|
| 35 |
|
| 36 |
collection = db["FD_MLB_seed_frame"]
|
| 37 |
cursor = collection.find()
|
| 38 |
|
| 39 |
raw_display = pd.DataFrame(list(cursor))
|
| 40 |
-
raw_display = raw_display[['
|
| 41 |
FD_seed = raw_display.to_numpy()
|
| 42 |
|
| 43 |
MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
|
|
@@ -51,8 +51,8 @@ def init_conn():
|
|
| 51 |
gcservice_account, client, db, DK_seed, FD_seed, MLB_Data = init_conn()
|
| 52 |
|
| 53 |
percentages_format = {'Exposure': '{:.2%}'}
|
| 54 |
-
dk_columns = [
|
| 55 |
-
fd_columns = [
|
| 56 |
|
| 57 |
@st.cache_data(ttl = 60)
|
| 58 |
def init_baselines():
|
|
@@ -78,12 +78,19 @@ def convert_df(array):
|
|
| 78 |
return array.to_csv().encode('utf-8')
|
| 79 |
|
| 80 |
@st.cache_data
|
| 81 |
-
def
|
| 82 |
-
unique, counts = np.unique(np_array, return_counts=True)
|
| 83 |
frequencies = counts / len(np_array) # Normalize by the number of rows
|
| 84 |
combined_array = np.column_stack((unique, frequencies))
|
| 85 |
return combined_array
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
dk_raw, fd_raw = init_baselines()
|
| 88 |
|
| 89 |
tab1, tab2 = st.tabs(['Data Export', 'Contest Sims'])
|
|
@@ -134,20 +141,20 @@ with tab1:
|
|
| 134 |
if site_var1 == 'Draftkings':
|
| 135 |
|
| 136 |
st.session_state.working_seed = DK_seed.copy()
|
| 137 |
-
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:,
|
| 138 |
-
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:,
|
| 139 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 140 |
|
| 141 |
-
|
| 142 |
|
| 143 |
elif site_var1 == 'Fanduel':
|
| 144 |
|
| 145 |
st.session_state.working_seed = FD_seed.copy()
|
| 146 |
-
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:,
|
| 147 |
-
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:,
|
| 148 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 149 |
|
| 150 |
-
|
| 151 |
|
| 152 |
with st.container():
|
| 153 |
if 'data_export_display' in st.session_state:
|
|
@@ -157,14 +164,13 @@ with tab1:
|
|
| 157 |
st.dataframe(st.session_state.data_export_freq.style.format(percentages_format, precision=2), height=500, use_container_width=True)
|
| 158 |
|
| 159 |
if st.button("Prepare data export", key='data_export'):
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
)
|
| 168 |
|
| 169 |
with tab2:
|
| 170 |
col1, col2 = st.columns([1, 7])
|
|
|
|
| 30 |
cursor = collection.find()
|
| 31 |
|
| 32 |
raw_display = pd.DataFrame(list(cursor))
|
| 33 |
+
raw_display = raw_display[['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']]
|
| 34 |
DK_seed = raw_display.to_numpy()
|
| 35 |
|
| 36 |
collection = db["FD_MLB_seed_frame"]
|
| 37 |
cursor = collection.find()
|
| 38 |
|
| 39 |
raw_display = pd.DataFrame(list(cursor))
|
| 40 |
+
raw_display = raw_display[['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']]
|
| 41 |
FD_seed = raw_display.to_numpy()
|
| 42 |
|
| 43 |
MLB_Data = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
|
|
|
|
| 51 |
gcservice_account, client, db, DK_seed, FD_seed, MLB_Data = init_conn()
|
| 52 |
|
| 53 |
percentages_format = {'Exposure': '{:.2%}'}
|
| 54 |
+
dk_columns = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']
|
| 55 |
+
fd_columns = ['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count']
|
| 56 |
|
| 57 |
@st.cache_data(ttl = 60)
|
| 58 |
def init_baselines():
|
|
|
|
| 78 |
return array.to_csv().encode('utf-8')
|
| 79 |
|
| 80 |
@st.cache_data
|
| 81 |
+
def calculate_DK_value_frequencies(np_array):
|
| 82 |
+
unique, counts = np.unique(np_array[:9], return_counts=True)
|
| 83 |
frequencies = counts / len(np_array) # Normalize by the number of rows
|
| 84 |
combined_array = np.column_stack((unique, frequencies))
|
| 85 |
return combined_array
|
| 86 |
|
| 87 |
+
@st.cache_data
|
| 88 |
+
def calculate_FD_value_frequencies(np_array):
|
| 89 |
+
unique, counts = np.unique(np_array[:8], return_counts=True)
|
| 90 |
+
frequencies = counts / len(np_array) # Normalize by the number of rows
|
| 91 |
+
combined_array = np.column_stack((unique, frequencies))
|
| 92 |
+
return combined_array
|
| 93 |
+
|
| 94 |
dk_raw, fd_raw = init_baselines()
|
| 95 |
|
| 96 |
tab1, tab2 = st.tabs(['Data Export', 'Contest Sims'])
|
|
|
|
| 141 |
if site_var1 == 'Draftkings':
|
| 142 |
|
| 143 |
st.session_state.working_seed = DK_seed.copy()
|
| 144 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 12], team_var2)]
|
| 145 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 13], stack_var2)]
|
| 146 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 147 |
|
| 148 |
+
st.session_state.data_export_freq = calculate_DK_value_frequencies(st.session_state.working_seed)
|
| 149 |
|
| 150 |
elif site_var1 == 'Fanduel':
|
| 151 |
|
| 152 |
st.session_state.working_seed = FD_seed.copy()
|
| 153 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 11], team_var2)]
|
| 154 |
+
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 12], stack_var2)]
|
| 155 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 156 |
|
| 157 |
+
st.session_state.data_export_freq = calculate_FD_value_frequencies(st.session_state.working_seed)
|
| 158 |
|
| 159 |
with st.container():
|
| 160 |
if 'data_export_display' in st.session_state:
|
|
|
|
| 164 |
st.dataframe(st.session_state.data_export_freq.style.format(percentages_format, precision=2), height=500, use_container_width=True)
|
| 165 |
|
| 166 |
if st.button("Prepare data export", key='data_export'):
|
| 167 |
+
data_export = st.session_state.working_seed.copy()
|
| 168 |
+
st.download_button(
|
| 169 |
+
label="Export optimals set",
|
| 170 |
+
data=convert_df(st.session_state.data_export),
|
| 171 |
+
file_name='MLB_optimals_export.csv',
|
| 172 |
+
mime='text/csv',
|
| 173 |
+
)
|
|
|
|
| 174 |
|
| 175 |
with tab2:
|
| 176 |
col1, col2 = st.columns([1, 7])
|