Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,16 +29,16 @@ def init_conn():
|
|
29 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
30 |
}
|
31 |
|
32 |
-
|
33 |
-
return
|
34 |
|
35 |
-
|
36 |
|
37 |
freq_format = {'Proj Own': '{:.2%}', 'Exposure': '{:.2%}', 'Edge': '{:.2%}'}
|
38 |
|
39 |
@st.cache_resource(ttl = 300)
|
40 |
def load_dk_player_projections():
|
41 |
-
sh =
|
42 |
worksheet = sh.worksheet('DK_ROO')
|
43 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
44 |
load_display.replace('', np.nan, inplace=True)
|
@@ -48,7 +48,7 @@ def load_dk_player_projections():
|
|
48 |
|
49 |
@st.cache_resource(ttl = 300)
|
50 |
def load_fd_player_projections():
|
51 |
-
sh =
|
52 |
worksheet = sh.worksheet('FD_ROO')
|
53 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
54 |
load_display.replace('', np.nan, inplace=True)
|
@@ -58,7 +58,7 @@ def load_fd_player_projections():
|
|
58 |
|
59 |
@st.cache_resource(ttl = 300)
|
60 |
def set_export_ids():
|
61 |
-
sh =
|
62 |
worksheet = sh.worksheet('DK_ROO')
|
63 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
64 |
load_display.replace('', np.nan, inplace=True)
|
@@ -1042,7 +1042,7 @@ with tab2:
|
|
1042 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
1043 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
1044 |
nerf_frame = Overall_Proj
|
1045 |
-
|
1046 |
ref_dict = {
|
1047 |
'pos':['RB', 'WR', 'TE', 'FLEX'],
|
1048 |
'pos_dfs':['RB_Table', 'WR_Table', 'TE_Table', 'FLEX_Table'],
|
@@ -1076,24 +1076,6 @@ with tab2:
|
|
1076 |
st.write('Seed frame creation')
|
1077 |
FinalPortfolio, maps_dict = run_seed_frame(10, Strength_var, strength_grow, Teams_used, 1000000)
|
1078 |
|
1079 |
-
Sim_size = 2500
|
1080 |
-
SimVar = 1
|
1081 |
-
Sim_Winners = []
|
1082 |
-
fp_array = FinalPortfolio.values
|
1083 |
-
|
1084 |
-
if insert_port == 1:
|
1085 |
-
up_array = CleanPortfolio.values
|
1086 |
-
|
1087 |
-
# Pre-vectorize functions
|
1088 |
-
vec_projection_map = np.vectorize(maps_dict['Projection_map'].__getitem__)
|
1089 |
-
vec_stdev_map = np.vectorize(maps_dict['STDev_map'].__getitem__)
|
1090 |
-
|
1091 |
-
if insert_port == 1:
|
1092 |
-
vec_up_projection_map = np.vectorize(up_dict['Projection_map'].__getitem__)
|
1093 |
-
vec_up_stdev_map = np.vectorize(up_dict['STDev_map'].__getitem__)
|
1094 |
-
|
1095 |
-
st.write('Simulating contest on frames')
|
1096 |
-
|
1097 |
Sim_Winners = sim_contest(2500, FinalPortfolio, CleanPortfolio, maps_dict, up_dict, insert_port)
|
1098 |
|
1099 |
st.write('Contest simulation complete')
|
@@ -1128,7 +1110,7 @@ with tab2:
|
|
1128 |
player_freq['Position'] = player_freq['Player'].map(maps_dict['Pos_map'])
|
1129 |
player_freq['Salary'] = player_freq['Player'].map(maps_dict['Salary_map'])
|
1130 |
player_freq['Proj Own'] = player_freq['Player'].map(maps_dict['Own_map']) / 100
|
1131 |
-
player_freq['Exposure'] = player_freq['Freq']/(
|
1132 |
player_freq['Edge'] = player_freq['Exposure'] - player_freq['Proj Own']
|
1133 |
player_freq['Team'] = player_freq['Player'].map(maps_dict['Team_map'])
|
1134 |
for checkVar in range(len(team_list)):
|
@@ -1142,7 +1124,7 @@ with tab2:
|
|
1142 |
qb_freq['Position'] = qb_freq['Player'].map(maps_dict['Pos_map'])
|
1143 |
qb_freq['Salary'] = qb_freq['Player'].map(maps_dict['Salary_map'])
|
1144 |
qb_freq['Proj Own'] = qb_freq['Player'].map(maps_dict['Own_map']) / 100
|
1145 |
-
qb_freq['Exposure'] = qb_freq['Freq']/(
|
1146 |
qb_freq['Edge'] = qb_freq['Exposure'] - qb_freq['Proj Own']
|
1147 |
qb_freq['Team'] = qb_freq['Player'].map(maps_dict['Team_map'])
|
1148 |
for checkVar in range(len(team_list)):
|
@@ -1156,7 +1138,7 @@ with tab2:
|
|
1156 |
rb_freq['Position'] = rb_freq['Player'].map(maps_dict['Pos_map'])
|
1157 |
rb_freq['Salary'] = rb_freq['Player'].map(maps_dict['Salary_map'])
|
1158 |
rb_freq['Proj Own'] = rb_freq['Player'].map(maps_dict['Own_map']) / 100
|
1159 |
-
rb_freq['Exposure'] = rb_freq['Freq']/
|
1160 |
rb_freq['Edge'] = rb_freq['Exposure'] - rb_freq['Proj Own']
|
1161 |
rb_freq['Team'] = rb_freq['Player'].map(maps_dict['Team_map'])
|
1162 |
for checkVar in range(len(team_list)):
|
@@ -1170,7 +1152,7 @@ with tab2:
|
|
1170 |
wr_freq['Position'] = wr_freq['Player'].map(maps_dict['Pos_map'])
|
1171 |
wr_freq['Salary'] = wr_freq['Player'].map(maps_dict['Salary_map'])
|
1172 |
wr_freq['Proj Own'] = wr_freq['Player'].map(maps_dict['Own_map']) / 100
|
1173 |
-
wr_freq['Exposure'] = wr_freq['Freq']/
|
1174 |
wr_freq['Edge'] = wr_freq['Exposure'] - wr_freq['Proj Own']
|
1175 |
wr_freq['Team'] = wr_freq['Player'].map(maps_dict['Team_map'])
|
1176 |
for checkVar in range(len(team_list)):
|
@@ -1184,7 +1166,7 @@ with tab2:
|
|
1184 |
te_freq['Position'] = te_freq['Player'].map(maps_dict['Pos_map'])
|
1185 |
te_freq['Salary'] = te_freq['Player'].map(maps_dict['Salary_map'])
|
1186 |
te_freq['Proj Own'] = te_freq['Player'].map(maps_dict['Own_map']) / 100
|
1187 |
-
te_freq['Exposure'] = te_freq['Freq']/
|
1188 |
te_freq['Edge'] = te_freq['Exposure'] - te_freq['Proj Own']
|
1189 |
te_freq['Team'] = te_freq['Player'].map(maps_dict['Team_map'])
|
1190 |
for checkVar in range(len(team_list)):
|
@@ -1198,7 +1180,7 @@ with tab2:
|
|
1198 |
flex_freq['Position'] = flex_freq['Player'].map(maps_dict['Pos_map'])
|
1199 |
flex_freq['Salary'] = flex_freq['Player'].map(maps_dict['Salary_map'])
|
1200 |
flex_freq['Proj Own'] = flex_freq['Player'].map(maps_dict['Own_map']) / 100
|
1201 |
-
flex_freq['Exposure'] = flex_freq['Freq']/
|
1202 |
flex_freq['Edge'] = flex_freq['Exposure'] - flex_freq['Proj Own']
|
1203 |
flex_freq['Team'] = flex_freq['Player'].map(maps_dict['Team_map'])
|
1204 |
for checkVar in range(len(team_list)):
|
@@ -1212,7 +1194,7 @@ with tab2:
|
|
1212 |
dst_freq['Position'] = dst_freq['Player'].map(maps_dict['Pos_map'])
|
1213 |
dst_freq['Salary'] = dst_freq['Player'].map(maps_dict['Salary_map'])
|
1214 |
dst_freq['Proj Own'] = dst_freq['Player'].map(maps_dict['Own_map']) / 100
|
1215 |
-
dst_freq['Exposure'] = dst_freq['Freq']/
|
1216 |
dst_freq['Edge'] = dst_freq['Exposure'] - dst_freq['Proj Own']
|
1217 |
dst_freq['Team'] = dst_freq['Player'].map(maps_dict['Team_map'])
|
1218 |
for checkVar in range(len(team_list)):
|
@@ -1310,7 +1292,10 @@ with tab2:
|
|
1310 |
mime='text/csv',
|
1311 |
)
|
1312 |
|
1313 |
-
del
|
1314 |
del dk_roo_raw, fd_roo_raw
|
1315 |
del t_stamp
|
1316 |
-
del dkid_dict, fdid_dict
|
|
|
|
|
|
|
|
29 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
30 |
}
|
31 |
|
32 |
+
gc_con = gspread.service_account_from_dict(credentials)
|
33 |
+
return gc_con
|
34 |
|
35 |
+
gcservice_account = init_conn()
|
36 |
|
37 |
freq_format = {'Proj Own': '{:.2%}', 'Exposure': '{:.2%}', 'Edge': '{:.2%}'}
|
38 |
|
39 |
@st.cache_resource(ttl = 300)
|
40 |
def load_dk_player_projections():
|
41 |
+
sh = gcservice_account.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
42 |
worksheet = sh.worksheet('DK_ROO')
|
43 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
44 |
load_display.replace('', np.nan, inplace=True)
|
|
|
48 |
|
49 |
@st.cache_resource(ttl = 300)
|
50 |
def load_fd_player_projections():
|
51 |
+
sh = gcservice_account.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
52 |
worksheet = sh.worksheet('FD_ROO')
|
53 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
54 |
load_display.replace('', np.nan, inplace=True)
|
|
|
58 |
|
59 |
@st.cache_resource(ttl = 300)
|
60 |
def set_export_ids():
|
61 |
+
sh = gcservice_account.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
62 |
worksheet = sh.worksheet('DK_ROO')
|
63 |
load_display = pd.DataFrame(worksheet.get_all_records())
|
64 |
load_display.replace('', np.nan, inplace=True)
|
|
|
1042 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
1043 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
1044 |
nerf_frame = Overall_Proj
|
1045 |
+
|
1046 |
ref_dict = {
|
1047 |
'pos':['RB', 'WR', 'TE', 'FLEX'],
|
1048 |
'pos_dfs':['RB_Table', 'WR_Table', 'TE_Table', 'FLEX_Table'],
|
|
|
1076 |
st.write('Seed frame creation')
|
1077 |
FinalPortfolio, maps_dict = run_seed_frame(10, Strength_var, strength_grow, Teams_used, 1000000)
|
1078 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1079 |
Sim_Winners = sim_contest(2500, FinalPortfolio, CleanPortfolio, maps_dict, up_dict, insert_port)
|
1080 |
|
1081 |
st.write('Contest simulation complete')
|
|
|
1110 |
player_freq['Position'] = player_freq['Player'].map(maps_dict['Pos_map'])
|
1111 |
player_freq['Salary'] = player_freq['Player'].map(maps_dict['Salary_map'])
|
1112 |
player_freq['Proj Own'] = player_freq['Player'].map(maps_dict['Own_map']) / 100
|
1113 |
+
player_freq['Exposure'] = player_freq['Freq']/(2500)
|
1114 |
player_freq['Edge'] = player_freq['Exposure'] - player_freq['Proj Own']
|
1115 |
player_freq['Team'] = player_freq['Player'].map(maps_dict['Team_map'])
|
1116 |
for checkVar in range(len(team_list)):
|
|
|
1124 |
qb_freq['Position'] = qb_freq['Player'].map(maps_dict['Pos_map'])
|
1125 |
qb_freq['Salary'] = qb_freq['Player'].map(maps_dict['Salary_map'])
|
1126 |
qb_freq['Proj Own'] = qb_freq['Player'].map(maps_dict['Own_map']) / 100
|
1127 |
+
qb_freq['Exposure'] = qb_freq['Freq']/(2500)
|
1128 |
qb_freq['Edge'] = qb_freq['Exposure'] - qb_freq['Proj Own']
|
1129 |
qb_freq['Team'] = qb_freq['Player'].map(maps_dict['Team_map'])
|
1130 |
for checkVar in range(len(team_list)):
|
|
|
1138 |
rb_freq['Position'] = rb_freq['Player'].map(maps_dict['Pos_map'])
|
1139 |
rb_freq['Salary'] = rb_freq['Player'].map(maps_dict['Salary_map'])
|
1140 |
rb_freq['Proj Own'] = rb_freq['Player'].map(maps_dict['Own_map']) / 100
|
1141 |
+
rb_freq['Exposure'] = rb_freq['Freq']/2500
|
1142 |
rb_freq['Edge'] = rb_freq['Exposure'] - rb_freq['Proj Own']
|
1143 |
rb_freq['Team'] = rb_freq['Player'].map(maps_dict['Team_map'])
|
1144 |
for checkVar in range(len(team_list)):
|
|
|
1152 |
wr_freq['Position'] = wr_freq['Player'].map(maps_dict['Pos_map'])
|
1153 |
wr_freq['Salary'] = wr_freq['Player'].map(maps_dict['Salary_map'])
|
1154 |
wr_freq['Proj Own'] = wr_freq['Player'].map(maps_dict['Own_map']) / 100
|
1155 |
+
wr_freq['Exposure'] = wr_freq['Freq']/2500
|
1156 |
wr_freq['Edge'] = wr_freq['Exposure'] - wr_freq['Proj Own']
|
1157 |
wr_freq['Team'] = wr_freq['Player'].map(maps_dict['Team_map'])
|
1158 |
for checkVar in range(len(team_list)):
|
|
|
1166 |
te_freq['Position'] = te_freq['Player'].map(maps_dict['Pos_map'])
|
1167 |
te_freq['Salary'] = te_freq['Player'].map(maps_dict['Salary_map'])
|
1168 |
te_freq['Proj Own'] = te_freq['Player'].map(maps_dict['Own_map']) / 100
|
1169 |
+
te_freq['Exposure'] = te_freq['Freq']/2500
|
1170 |
te_freq['Edge'] = te_freq['Exposure'] - te_freq['Proj Own']
|
1171 |
te_freq['Team'] = te_freq['Player'].map(maps_dict['Team_map'])
|
1172 |
for checkVar in range(len(team_list)):
|
|
|
1180 |
flex_freq['Position'] = flex_freq['Player'].map(maps_dict['Pos_map'])
|
1181 |
flex_freq['Salary'] = flex_freq['Player'].map(maps_dict['Salary_map'])
|
1182 |
flex_freq['Proj Own'] = flex_freq['Player'].map(maps_dict['Own_map']) / 100
|
1183 |
+
flex_freq['Exposure'] = flex_freq['Freq']/2500
|
1184 |
flex_freq['Edge'] = flex_freq['Exposure'] - flex_freq['Proj Own']
|
1185 |
flex_freq['Team'] = flex_freq['Player'].map(maps_dict['Team_map'])
|
1186 |
for checkVar in range(len(team_list)):
|
|
|
1194 |
dst_freq['Position'] = dst_freq['Player'].map(maps_dict['Pos_map'])
|
1195 |
dst_freq['Salary'] = dst_freq['Player'].map(maps_dict['Salary_map'])
|
1196 |
dst_freq['Proj Own'] = dst_freq['Player'].map(maps_dict['Own_map']) / 100
|
1197 |
+
dst_freq['Exposure'] = dst_freq['Freq']/2500
|
1198 |
dst_freq['Edge'] = dst_freq['Exposure'] - dst_freq['Proj Own']
|
1199 |
dst_freq['Team'] = dst_freq['Player'].map(maps_dict['Team_map'])
|
1200 |
for checkVar in range(len(team_list)):
|
|
|
1292 |
mime='text/csv',
|
1293 |
)
|
1294 |
|
1295 |
+
del gcservice_account
|
1296 |
del dk_roo_raw, fd_roo_raw
|
1297 |
del t_stamp
|
1298 |
+
del dkid_dict, fdid_dict
|
1299 |
+
del static_exposure, overall_exposure
|
1300 |
+
del insert_port1, Contest_Size, sharp_split, Strength_var, scaling_var
|
1301 |
+
del raw_baselines
|