James McCool commited on
Commit
0cd4d7f
·
1 Parent(s): 8c22e49

Add sport selection and dynamic template for NBA, NFL, and MLB projections

Browse files
Files changed (3) hide show
  1. app.py +13 -4
  2. function_hold/NBA_functions.py +399 -0
  3. requirements.txt +1 -1
app.py CHANGED
@@ -28,9 +28,14 @@ tab1, tab2 = st.tabs(["Data Load", "Manage Portfolio"])
28
  with tab1:
29
  if st.button('Clear data', key='reset1'):
30
  st.session_state.clear()
31
-
32
  st.subheader("Projections File")
33
- st.info("upload a projections file that has Data oriented in the following format:")
 
 
 
 
 
34
 
35
  # Create two columns for the uploader and template button
36
  upload_col, template_col = st.columns([3, 1])
@@ -39,8 +44,12 @@ with tab1:
39
  projections_file = st.file_uploader("Upload Projections File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
40
 
41
  with template_col:
42
- # Create empty DataFrame with required columns
43
- template_df = pd.DataFrame(columns=['player_names', 'position', 'team', 'salary', 'median', 'ownership', 'captain ownership'])
 
 
 
 
44
  # Add download button for template
45
  st.download_button(
46
  label="Template",
 
28
  with tab1:
29
  if st.button('Clear data', key='reset1'):
30
  st.session_state.clear()
31
+ sport_var = st.selectbox("Select Sport", ["NBA", "NFL", "MLB"])
32
  st.subheader("Projections File")
33
+ if sport_var == "NBA":
34
+ st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
35
+ elif sport_var == "NFL":
36
+ st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
37
+ elif sport_var == "MLB":
38
+ st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
39
 
40
  # Create two columns for the uploader and template button
41
  upload_col, template_col = st.columns([3, 1])
 
44
  projections_file = st.file_uploader("Upload Projections File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
45
 
46
  with template_col:
47
+ if sport_var == "NBA":
48
+ template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
49
+ elif sport_var == "NFL":
50
+ template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
51
+ elif sport_var == "MLB":
52
+ template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
53
  # Add download button for template
54
  st.download_button(
55
  label="Template",
function_hold/NBA_functions.py ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def DK_NBA_ROO_Build(projections_file):
2
+ total_sims = 1000
3
+
4
+ projects_raw = projections_file.copy()
5
+ projects_raw = projects_raw.replace("", np_nan)
6
+ dk_df = projects_raw.sort_values(by='Median', ascending=False)
7
+
8
+ basic_own_df = dk_df.copy()
9
+ basic_own_df['name_team'] = basic_own_df['Player'] + basic_own_df['Position']
10
+
11
+ def calculate_ownership(df):
12
+ # Filter the dataframe based on the position
13
+ frame = df.copy()
14
+
15
+ # Calculate Small Field Own%
16
+ frame['Base Own%'] = np_where(
17
+ (frame['Own'] - frame['Own'].mean() >= 0),
18
+ frame['Own'] * (5 * (frame['Own'] - (frame['Own'].mean() / 1.5)) / 100) + frame['Own'].mean(),
19
+ frame['Own']
20
+ )
21
+ frame['Base Own%'] = np_where(
22
+ frame['Base Own%'] > 85,
23
+ 85,
24
+ frame['Base Own%']
25
+ )
26
+
27
+ # Calculate Small Field Own%
28
+ frame['Small Field Own%'] = np_where(
29
+ (frame['Own'] - frame['Own'].mean() >= 0),
30
+ frame['Own'] * (6 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
31
+ frame['Own']
32
+ )
33
+ frame['Small Field Own%'] = np_where(
34
+ frame['Small Field Own%'] > 85,
35
+ 85,
36
+ frame['Small Field Own%']
37
+ )
38
+
39
+ # Calculate Large Field Own%
40
+ frame['Large Field Own%'] = np_where(
41
+ (frame['Own'] - frame['Own'].mean() >= 0),
42
+ frame['Own'] * (2.5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
43
+ frame['Own']
44
+ )
45
+ frame['Large Field Own%'] = np_where(
46
+ frame['Large Field Own%'] > 85,
47
+ 85,
48
+ frame['Large Field Own%']
49
+ )
50
+
51
+ # Calculate Cash Own%
52
+ frame['Cash Own%'] = np_where(
53
+ (frame['Own'] - frame['Own'].mean() >= 0),
54
+ frame['Own'] * (8 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
55
+ frame['Own']
56
+ )
57
+ frame['Cash Own%'] = np_where(
58
+ frame['Cash Own%'] > 85,
59
+ 85,
60
+ frame['Cash Own%']
61
+ )
62
+
63
+ return frame
64
+
65
+ # Apply the function to each dataframe
66
+ basic_own_df = calculate_ownership(basic_own_df)
67
+
68
+ own_norm_var_reg = 800 / basic_own_df['Own'].sum()
69
+ own_norm_var_small = 800 / basic_own_df['Small Field Own%'].sum()
70
+ own_norm_var_large = 800 / basic_own_df['Large Field Own%'].sum()
71
+ own_norm_var_cash = 800 / basic_own_df['Cash Own%'].sum()
72
+ basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
73
+ basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
74
+ basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
75
+ basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
76
+
77
+ basic_own_df['Own'] = np_where(basic_own_df['Own'] > 90, 90, basic_own_df['Own'])
78
+
79
+ # Apply the function to each dataframe
80
+ basic_own_df = calculate_ownership(basic_own_df)
81
+
82
+ own_norm_var_reg = 800 / basic_own_df['Own'].sum()
83
+ own_norm_var_small = 800 / basic_own_df['Small Field Own%'].sum()
84
+ own_norm_var_large = 800 / basic_own_df['Large Field Own%'].sum()
85
+ own_norm_var_cash = 800 / basic_own_df['Cash Own%'].sum()
86
+ basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
87
+ basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
88
+ basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
89
+ basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
90
+
91
+ own_dict = dict(zip(basic_own_df.Player, basic_own_df.Own))
92
+ small_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Small Field Own%']))
93
+ large_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Large Field Own%']))
94
+ cash_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Cash Own%']))
95
+ team_dict = dict(zip(basic_own_df.name_team, basic_own_df.Team))
96
+ opp_dict = dict(zip(basic_own_df.Player, basic_own_df.Opp))
97
+ min_dict = dict(zip(basic_own_df.Player, basic_own_df.Minutes))
98
+
99
+ flex_file = basic_own_df[['Player', 'Position', 'Salary', 'Median', 'Minutes']]
100
+ flex_file = flex_file.rename(columns={"Agg": "Median"})
101
+ flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
102
+ flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
103
+ flex_file['STD'] = (flex_file['Median']/4)
104
+ flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
105
+ flex_file = flex_file.reset_index(drop=True)
106
+ hold_file = flex_file.copy()
107
+ overall_file = flex_file.copy()
108
+ salary_file = flex_file.copy()
109
+
110
+ try:
111
+ overall_median_gpu = np_array(overall_file['Median'])
112
+ overall_std_gpu = np_array(overall_file['STD'])
113
+ overall_salary_gpu = np_array(overall_file['Salary'])
114
+
115
+ data_shape = (len(overall_file['Player']), total_sims) # Example: 1000 rows
116
+ salary_array = np_zeros(data_shape)
117
+ sim_array = np_zeros(data_shape)
118
+
119
+ for x in range(0, total_sims):
120
+ result_gpu = overall_salary_gpu
121
+ salary_array[:, x] = result_gpu
122
+ cupy_array = salary_array
123
+
124
+ salary_file = salary_file.reset_index(drop=True)
125
+ salary_cupy = DataFrame(cupy_array, columns=list(range(0, total_sims)))
126
+ salary_check_file = pd_concat([salary_file, salary_cupy], axis=1)
127
+ except:
128
+ for x in range(0,total_sims):
129
+ salary_file[x] = salary_file['Salary']
130
+ salary_check_file = salary_file.copy()
131
+
132
+ salary_file=salary_check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
133
+
134
+ salary_file = salary_file.div(1000)
135
+
136
+ try:
137
+ for x in range(0, total_sims):
138
+ result_gpu = np_random.normal(overall_median_gpu, overall_std_gpu)
139
+ sim_array[:, x] = result_gpu
140
+ add_array = sim_array
141
+
142
+ overall_file = overall_file.reset_index(drop=True)
143
+ df2 = DataFrame(add_array, columns=list(range(0, total_sims)))
144
+ check_file = pd_concat([overall_file, df2], axis=1)
145
+ except:
146
+ for x in range(0,total_sims):
147
+ overall_file[x] = np_random.normal(overall_file['Median'],overall_file['STD'])
148
+ check_file = overall_file.copy()
149
+
150
+ overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
151
+
152
+ players_only = hold_file[['Player']]
153
+ raw_lineups_file = players_only
154
+
155
+ for x in range(0,total_sims):
156
+ maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))}
157
+ raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
158
+ players_only[x] = raw_lineups_file[x].rank(ascending=False)
159
+
160
+ players_only=players_only.drop(['Player'], axis=1)
161
+
162
+ salary_4x_check = (overall_file - (salary_file*4))
163
+ salary_5x_check = (overall_file - (salary_file*5))
164
+ salary_6x_check = (overall_file - (salary_file*6))
165
+ gpp_check = (overall_file - ((salary_file*5)+10))
166
+
167
+ players_only['Average_Rank'] = players_only.mean(axis=1)
168
+ players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
169
+ players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
170
+ players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
171
+ players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
172
+ players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
173
+ players_only['5x%'] = salary_5x_check[salary_5x_check >= 1].count(axis=1)/float(total_sims)
174
+ players_only['6x%'] = salary_6x_check[salary_6x_check >= 1].count(axis=1)/float(total_sims)
175
+ players_only['GPP%'] = gpp_check[gpp_check >= 1].count(axis=1)/float(total_sims)
176
+
177
+ players_only['Player'] = hold_file[['Player']]
178
+
179
+ final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%']]
180
+
181
+ final_Proj = pd_merge(hold_file, final_outcomes, on="Player")
182
+ final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%']]
183
+
184
+ final_Proj['name_team'] = final_Proj['Player'] + final_Proj['Position']
185
+ final_Proj['Own'] = final_Proj['Player'].map(own_dict)
186
+ final_Proj['Small_Own'] = final_Proj['Player'].map(small_own_dict)
187
+ final_Proj['Large_Own'] = final_Proj['Player'].map(large_own_dict)
188
+ final_Proj['Cash_Own'] = final_Proj['Player'].map(cash_own_dict)
189
+ final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
190
+ final_Proj['Team'] = final_Proj['name_team'].map(team_dict)
191
+ final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
192
+ final_Proj['CPT_Own'] = final_Proj['Own'] / 6
193
+ final_Proj['LevX'] = ((final_Proj[['Top_finish', '6x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
194
+ final_Proj['ValX'] = ((final_Proj[['5x%', '6x%']].mean(axis=1))*100) + final_Proj['LevX']
195
+
196
+ final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%', 'Own', 'Small_Own', 'Large_Own', 'Cash_Own', 'CPT_Own', 'LevX', 'ValX']]
197
+ final_Proj = final_Proj.sort_values(by='Median', ascending=False)
198
+
199
+ return final_Proj.copy()
200
+
201
+ def FD_NBA_ROO_Build(projections_file):
202
+ total_sims = 1000
203
+
204
+ projects_raw = projections_file.copy()
205
+ fd_df = projects_raw.sort_values(by='Median', ascending=False)
206
+
207
+ basic_own_df = fd_df.copy()
208
+ basic_own_df['name_team'] = basic_own_df['Player'] + basic_own_df['Position']
209
+
210
+ def calculate_ownership(df):
211
+ # Filter the dataframe based on the position
212
+ frame = df.copy()
213
+
214
+ # Calculate Small Field Own%
215
+ frame['Base Own%'] = np_where(
216
+ (frame['Own'] - frame['Own'].mean() >= 0),
217
+ frame['Own'] * (5 * (frame['Own'] - (frame['Own'].mean() / 1.5)) / 100) + frame['Own'].mean(),
218
+ frame['Own']
219
+ )
220
+ frame['Base Own%'] = np_where(
221
+ frame['Base Own%'] > 85,
222
+ 85,
223
+ frame['Base Own%']
224
+ )
225
+
226
+ # Calculate Small Field Own%
227
+ frame['Small Field Own%'] = np_where(
228
+ (frame['Own'] - frame['Own'].mean() >= 0),
229
+ frame['Own'] * (6 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
230
+ frame['Own']
231
+ )
232
+ frame['Small Field Own%'] = np_where(
233
+ frame['Small Field Own%'] > 85,
234
+ 85,
235
+ frame['Small Field Own%']
236
+ )
237
+
238
+ # Calculate Large Field Own%
239
+ frame['Large Field Own%'] = np_where(
240
+ (frame['Own'] - frame['Own'].mean() >= 0),
241
+ frame['Own'] * (2.5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
242
+ frame['Own']
243
+ )
244
+ frame['Large Field Own%'] = np_where(
245
+ frame['Large Field Own%'] > 85,
246
+ 85,
247
+ frame['Large Field Own%']
248
+ )
249
+
250
+ # Calculate Cash Own%
251
+ frame['Cash Own%'] = np_where(
252
+ (frame['Own'] - frame['Own'].mean() >= 0),
253
+ frame['Own'] * (8 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
254
+ frame['Own']
255
+ )
256
+ frame['Cash Own%'] = np_where(
257
+ frame['Cash Own%'] > 85,
258
+ 85,
259
+ frame['Cash Own%']
260
+ )
261
+
262
+ return frame
263
+
264
+ # Apply the function to each dataframe
265
+ basic_own_df = calculate_ownership(basic_own_df)
266
+
267
+ own_norm_var_reg = 900 / basic_own_df['Own'].sum()
268
+ own_norm_var_small = 900 / basic_own_df['Small Field Own%'].sum()
269
+ own_norm_var_large = 900 / basic_own_df['Large Field Own%'].sum()
270
+ own_norm_var_cash = 900 / basic_own_df['Cash Own%'].sum()
271
+ basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
272
+ basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
273
+ basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
274
+ basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
275
+
276
+ basic_own_df['Own'] = np_where(basic_own_df['Own'] > 90, 90, basic_own_df['Own'])
277
+
278
+ # Apply the function to each dataframe
279
+ basic_own_df = calculate_ownership(basic_own_df)
280
+
281
+ own_norm_var_reg = 900 / basic_own_df['Own'].sum()
282
+ own_norm_var_small = 900 / basic_own_df['Small Field Own%'].sum()
283
+ own_norm_var_large = 900 / basic_own_df['Large Field Own%'].sum()
284
+ own_norm_var_cash = 900 / basic_own_df['Cash Own%'].sum()
285
+ basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
286
+ basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
287
+ basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
288
+ basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
289
+
290
+ own_dict = dict(zip(basic_own_df.Player, basic_own_df.Own))
291
+ small_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Small Field Own%']))
292
+ large_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Large Field Own%']))
293
+ cash_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Cash Own%']))
294
+ team_dict = dict(zip(basic_own_df.name_team, basic_own_df.Team))
295
+ opp_dict = dict(zip(basic_own_df.Player, basic_own_df.Opp))
296
+ min_dict = dict(zip(basic_own_df.Player, basic_own_df.Minutes))
297
+
298
+ flex_file = basic_own_df[['Player', 'Position', 'Salary', 'Median', 'Minutes']]
299
+ flex_file = flex_file.rename(columns={"Agg": "Median"})
300
+ flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
301
+ flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
302
+ flex_file['STD'] = (flex_file['Median']/4)
303
+ flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
304
+ flex_file = flex_file.reset_index(drop=True)
305
+ hold_file = flex_file.copy()
306
+ overall_file = flex_file.copy()
307
+ salary_file = flex_file.copy()
308
+
309
+ try:
310
+ overall_median_gpu = np_array(overall_file['Median'])
311
+ overall_std_gpu = np_array(overall_file['STD'])
312
+ overall_salary_gpu = np_array(overall_file['Salary'])
313
+
314
+ data_shape = (len(overall_file['Player']), total_sims) # Example: 1000 rows
315
+ salary_array = np_zeros(data_shape)
316
+ sim_array = np_zeros(data_shape)
317
+
318
+ for x in range(0, total_sims):
319
+ result_gpu = overall_salary_gpu
320
+ salary_array[:, x] = result_gpu
321
+ cupy_array = salary_array
322
+
323
+ salary_file = salary_file.reset_index(drop=True)
324
+ salary_cupy = DataFrame(cupy_array, columns=list(range(0, total_sims)))
325
+ salary_check_file = pd_concat([salary_file, salary_cupy], axis=1)
326
+ except:
327
+ for x in range(0,total_sims):
328
+ salary_file[x] = salary_file['Salary']
329
+ salary_check_file = salary_file.copy()
330
+
331
+ salary_file=salary_check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
332
+
333
+ salary_file = salary_file.div(1000)
334
+
335
+ try:
336
+ for x in range(0, total_sims):
337
+ result_gpu = np_random.normal(overall_median_gpu, overall_std_gpu)
338
+ sim_array[:, x] = result_gpu
339
+ add_array = sim_array
340
+
341
+ overall_file = overall_file.reset_index(drop=True)
342
+ df2 = DataFrame(add_array, columns=list(range(0, total_sims)))
343
+ check_file = pd_concat([overall_file, df2], axis=1)
344
+ except:
345
+ for x in range(0,total_sims):
346
+ overall_file[x] = np_random.normal(overall_file['Median'],overall_file['STD'])
347
+ check_file = overall_file.copy()
348
+
349
+ overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
350
+
351
+ players_only = hold_file[['Player']]
352
+ raw_lineups_file = players_only
353
+
354
+ for x in range(0,total_sims):
355
+ maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))}
356
+ raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
357
+ players_only[x] = raw_lineups_file[x].rank(ascending=False)
358
+
359
+ players_only=players_only.drop(['Player'], axis=1)
360
+
361
+ salary_4x_check = (overall_file - (salary_file*4))
362
+ salary_5x_check = (overall_file - (salary_file*5))
363
+ salary_6x_check = (overall_file - (salary_file*6))
364
+ gpp_check = (overall_file - ((salary_file*5)+10))
365
+
366
+ players_only['Average_Rank'] = players_only.mean(axis=1)
367
+ players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
368
+ players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
369
+ players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
370
+ players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
371
+ players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
372
+ players_only['5x%'] = salary_5x_check[salary_5x_check >= 1].count(axis=1)/float(total_sims)
373
+ players_only['6x%'] = salary_6x_check[salary_6x_check >= 1].count(axis=1)/float(total_sims)
374
+ players_only['GPP%'] = gpp_check[gpp_check >= 1].count(axis=1)/float(total_sims)
375
+
376
+ players_only['Player'] = hold_file[['Player']]
377
+
378
+ final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%']]
379
+
380
+ final_Proj = pd_merge(hold_file, final_outcomes, on="Player")
381
+ final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%']]
382
+
383
+ final_Proj['name_team'] = final_Proj['Player'] + final_Proj['Position']
384
+ final_Proj['Own'] = final_Proj['Player'].map(own_dict)
385
+ final_Proj['Small_Own'] = final_Proj['Player'].map(small_own_dict)
386
+ final_Proj['Large_Own'] = final_Proj['Player'].map(large_own_dict)
387
+ final_Proj['Cash_Own'] = final_Proj['Player'].map(cash_own_dict)
388
+ final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
389
+ final_Proj['Team'] = final_Proj['name_team'].map(team_dict)
390
+ final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
391
+ final_Proj['CPT_Own'] = final_Proj['Own'] / 6
392
+ final_Proj['LevX'] = ((final_Proj[['Top_finish', '6x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
393
+ final_Proj['ValX'] = ((final_Proj[['5x%', '6x%']].mean(axis=1))*100) + final_Proj['LevX']
394
+
395
+ final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%', 'Own', 'Small_Own', 'Large_Own', 'Cash_Own', 'CPT_Own', 'LevX', 'ValX']]
396
+ final_Proj['Salary'] = final_Proj['Salary'].astype(int)
397
+ final_Proj = final_Proj.sort_values(by='Median', ascending=False)
398
+
399
+ return final_Proj.copy()
requirements.txt CHANGED
@@ -2,7 +2,7 @@ streamlit
2
  gspread
3
  openpyxl
4
  matplotlib
5
- streamlit-aggrid
6
  pulp
7
  docker
8
  plotly
 
2
  gspread
3
  openpyxl
4
  matplotlib
5
+ fuzzywuzzy
6
  pulp
7
  docker
8
  plotly