Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -77,6 +77,57 @@ def set_export_ids():
|
|
77 |
def convert_df_to_csv(df):
|
78 |
return df.to_csv().encode('utf-8')
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_Runs):
|
81 |
RunsVar = 1
|
82 |
seed_depth_def = seed_depth1
|
@@ -770,7 +821,6 @@ with tab2:
|
|
770 |
Contest_Size = 5000
|
771 |
elif contest_var1 == 'Large':
|
772 |
Contest_Size = 10000
|
773 |
-
linenum_var1 = 2500
|
774 |
strength_var1 = st.selectbox("How sharp is the field in the contest?", ('Not Very', 'Average', 'Very'))
|
775 |
if strength_var1 == 'Not Very':
|
776 |
sharp_split = .33
|
@@ -792,8 +842,6 @@ with tab2:
|
|
792 |
st.write('Contest Simulation Starting')
|
793 |
for key in st.session_state.keys():
|
794 |
del st.session_state[key]
|
795 |
-
seed_depth1 = 10
|
796 |
-
Total_Runs = 1000000
|
797 |
if Contest_Size <= 1000:
|
798 |
strength_grow = .01
|
799 |
elif Contest_Size > 1000 and Contest_Size <= 2500:
|
@@ -1026,9 +1074,9 @@ with tab2:
|
|
1026 |
}
|
1027 |
|
1028 |
st.write('Seed frame creation')
|
1029 |
-
FinalPortfolio, maps_dict = run_seed_frame(
|
1030 |
|
1031 |
-
Sim_size =
|
1032 |
SimVar = 1
|
1033 |
Sim_Winners = []
|
1034 |
fp_array = FinalPortfolio.values
|
@@ -1046,36 +1094,7 @@ with tab2:
|
|
1046 |
|
1047 |
st.write('Simulating contest on frames')
|
1048 |
|
1049 |
-
|
1050 |
-
if insert_port == 1:
|
1051 |
-
fp_random = fp_array[np.random.choice(fp_array.shape[0], Contest_Size-len(CleanPortfolio))]
|
1052 |
-
elif insert_port == 0:
|
1053 |
-
fp_random = fp_array[np.random.choice(fp_array.shape[0], Contest_Size)]
|
1054 |
-
|
1055 |
-
sample_arrays1 = np.c_[
|
1056 |
-
fp_random,
|
1057 |
-
np.sum(np.random.normal(
|
1058 |
-
loc=vec_projection_map(fp_random[:, :-5]),
|
1059 |
-
scale=vec_stdev_map(fp_random[:, :-5])),
|
1060 |
-
axis=1)
|
1061 |
-
]
|
1062 |
-
|
1063 |
-
if insert_port == 1:
|
1064 |
-
sample_arrays2 = np.c_[
|
1065 |
-
up_array,
|
1066 |
-
np.sum(np.random.normal(
|
1067 |
-
loc=vec_up_projection_map(up_array[:, :-5]),
|
1068 |
-
scale=vec_up_stdev_map(up_array[:, :-5])),
|
1069 |
-
axis=1)
|
1070 |
-
]
|
1071 |
-
sample_arrays = np.vstack((sample_arrays1, sample_arrays2))
|
1072 |
-
else:
|
1073 |
-
sample_arrays = sample_arrays1
|
1074 |
-
|
1075 |
-
final_array = sample_arrays[sample_arrays[:, 10].argsort()[::-1]]
|
1076 |
-
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
1077 |
-
Sim_Winners.append(best_lineup)
|
1078 |
-
SimVar += 1
|
1079 |
|
1080 |
st.write('Contest simulation complete')
|
1081 |
# Initial setup
|
@@ -1294,6 +1313,4 @@ with tab2:
|
|
1294 |
del gc
|
1295 |
del dk_roo_raw, fd_roo_raw
|
1296 |
del t_stamp
|
1297 |
-
del dkid_dict, fdid_dict
|
1298 |
-
for key in st.session_state.keys():
|
1299 |
-
del st.session_state[key]
|
|
|
77 |
def convert_df_to_csv(df):
|
78 |
return df.to_csv().encode('utf-8')
|
79 |
|
80 |
+
def sim_contest(Sim_size, FinalPortfolio, CleanPortfolio, maps_dict, up_dict, insert_port):
|
81 |
+
SimVar = 1
|
82 |
+
Sim_Winners = []
|
83 |
+
fp_array = FinalPortfolio.values
|
84 |
+
|
85 |
+
if insert_port == 1:
|
86 |
+
up_array = CleanPortfolio.values
|
87 |
+
|
88 |
+
# Pre-vectorize functions
|
89 |
+
vec_projection_map = np.vectorize(maps_dict['Projection_map'].__getitem__)
|
90 |
+
vec_stdev_map = np.vectorize(maps_dict['STDev_map'].__getitem__)
|
91 |
+
|
92 |
+
if insert_port == 1:
|
93 |
+
vec_up_projection_map = np.vectorize(up_dict['Projection_map'].__getitem__)
|
94 |
+
vec_up_stdev_map = np.vectorize(up_dict['STDev_map'].__getitem__)
|
95 |
+
|
96 |
+
st.write('Simulating contest on frames')
|
97 |
+
|
98 |
+
while SimVar <= Sim_size:
|
99 |
+
if insert_port == 1:
|
100 |
+
fp_random = fp_array[np.random.choice(fp_array.shape[0], Contest_Size-len(CleanPortfolio))]
|
101 |
+
elif insert_port == 0:
|
102 |
+
fp_random = fp_array[np.random.choice(fp_array.shape[0], Contest_Size)]
|
103 |
+
|
104 |
+
sample_arrays1 = np.c_[
|
105 |
+
fp_random,
|
106 |
+
np.sum(np.random.normal(
|
107 |
+
loc=vec_projection_map(fp_random[:, :-5]),
|
108 |
+
scale=vec_stdev_map(fp_random[:, :-5])),
|
109 |
+
axis=1)
|
110 |
+
]
|
111 |
+
|
112 |
+
if insert_port == 1:
|
113 |
+
sample_arrays2 = np.c_[
|
114 |
+
up_array,
|
115 |
+
np.sum(np.random.normal(
|
116 |
+
loc=vec_up_projection_map(up_array[:, :-5]),
|
117 |
+
scale=vec_up_stdev_map(up_array[:, :-5])),
|
118 |
+
axis=1)
|
119 |
+
]
|
120 |
+
sample_arrays = np.vstack((sample_arrays1, sample_arrays2))
|
121 |
+
else:
|
122 |
+
sample_arrays = sample_arrays1
|
123 |
+
|
124 |
+
final_array = sample_arrays[sample_arrays[:, 10].argsort()[::-1]]
|
125 |
+
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
126 |
+
Sim_Winners.append(best_lineup)
|
127 |
+
SimVar += 1
|
128 |
+
|
129 |
+
return Sim_Winners
|
130 |
+
|
131 |
def run_seed_frame(seed_depth1, Strength_var, strength_grow, Teams_used, Total_Runs):
|
132 |
RunsVar = 1
|
133 |
seed_depth_def = seed_depth1
|
|
|
821 |
Contest_Size = 5000
|
822 |
elif contest_var1 == 'Large':
|
823 |
Contest_Size = 10000
|
|
|
824 |
strength_var1 = st.selectbox("How sharp is the field in the contest?", ('Not Very', 'Average', 'Very'))
|
825 |
if strength_var1 == 'Not Very':
|
826 |
sharp_split = .33
|
|
|
842 |
st.write('Contest Simulation Starting')
|
843 |
for key in st.session_state.keys():
|
844 |
del st.session_state[key]
|
|
|
|
|
845 |
if Contest_Size <= 1000:
|
846 |
strength_grow = .01
|
847 |
elif Contest_Size > 1000 and Contest_Size <= 2500:
|
|
|
1074 |
}
|
1075 |
|
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
|
|
|
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')
|
1100 |
# Initial setup
|
|
|
1313 |
del gc
|
1314 |
del dk_roo_raw, fd_roo_raw
|
1315 |
del t_stamp
|
1316 |
+
del dkid_dict, fdid_dict
|
|
|
|