Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
691ab8e
1
Parent(s):
f978d14
Enhance contest file loading and player data calculations
Browse files- Updated the load_contest_file function to return an additional dictionary for actual points, improving data accuracy.
- Modified app.py to incorporate actual points in player calculations, enhancing the analysis of player performance.
- Introduced new sets to track player usage based on actual points, improving data insights for user interaction.
- app.py +11 -2
- global_func/load_contest_file.py +2 -1
app.py
CHANGED
@@ -33,7 +33,7 @@ with tab1:
|
|
33 |
del st.session_state['Contest']
|
34 |
|
35 |
if Contest_file:
|
36 |
-
st.session_state['Contest'], st.session_state['ownership_dict'], st.session_state['entry_list'] = load_contest_file(Contest_file, sport_select)
|
37 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
38 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
39 |
if st.session_state['Contest'] is not None:
|
@@ -132,6 +132,7 @@ with tab2:
|
|
132 |
)
|
133 |
working_df['salary'] = working_df.apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
134 |
working_df['median'] = working_df.apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
|
|
135 |
working_df['Own'] = working_df.apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
136 |
working_df['sorted'] = working_df[player_columns].apply(
|
137 |
lambda row: ','.join(sorted(row.values)),
|
@@ -178,10 +179,18 @@ with tab2:
|
|
178 |
|
179 |
|
180 |
contest_players = set()
|
|
|
|
|
|
|
|
|
181 |
for col in player_columns:
|
182 |
contest_players.update(working_df[col].unique())
|
|
|
|
|
|
|
|
|
183 |
with st.container():
|
184 |
-
tab1, tab2 = st.tabs(['Player Used Info', 'Stack Used Info'
|
185 |
with tab1:
|
186 |
player_counts = contest_players.value_counts()
|
187 |
player_frame = player_counts.to_frame().reset_index().rename(columns={'index': 'Player', 0: 'Count'})
|
|
|
33 |
del st.session_state['Contest']
|
34 |
|
35 |
if Contest_file:
|
36 |
+
st.session_state['Contest'], st.session_state['ownership_dict'], st.session_state['actual_dict'], st.session_state['entry_list'] = load_contest_file(Contest_file, sport_select)
|
37 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
38 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
39 |
if st.session_state['Contest'] is not None:
|
|
|
132 |
)
|
133 |
working_df['salary'] = working_df.apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
134 |
working_df['median'] = working_df.apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
135 |
+
working_df['actual'] = working_df.apply(lambda row: sum(st.session_state['actual_dict'].get(player, 0) for player in row), axis=1)
|
136 |
working_df['Own'] = working_df.apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
137 |
working_df['sorted'] = working_df[player_columns].apply(
|
138 |
lambda row: ','.join(sorted(row.values)),
|
|
|
179 |
|
180 |
|
181 |
contest_players = set()
|
182 |
+
players_1per = set()
|
183 |
+
players_5per = set()
|
184 |
+
players_10per = set()
|
185 |
+
players_20per = set()
|
186 |
for col in player_columns:
|
187 |
contest_players.update(working_df[col].unique())
|
188 |
+
players_1per.update(working_df.nlargest(n=int(len(working_df) * 0.01), columns='actual')[col].unique())
|
189 |
+
players_5per.update(working_df.nlargest(n=int(len(working_df) * 0.05), columns='actual')[col].unique())
|
190 |
+
players_10per.update(working_df.nlargest(n=int(len(working_df) * 0.10), columns='actual')[col].unique())
|
191 |
+
players_20per.update(working_df.nlargest(n=int(len(working_df) * 0.20), columns='actual')[col].unique())
|
192 |
with st.container():
|
193 |
+
tab1, tab2 = st.tabs(['Player Used Info', 'Stack Used Info'])
|
194 |
with tab1:
|
195 |
player_counts = contest_players.value_counts()
|
196 |
player_frame = player_counts.to_frame().reset_index().rename(columns={'index': 'Player', 0: 'Count'})
|
global_func/load_contest_file.py
CHANGED
@@ -49,12 +49,13 @@ def load_contest_file(upload, sport):
|
|
49 |
if sport == 'MLB':
|
50 |
df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
|
51 |
ownership_dict = dict(zip(df['Player'], df['Own']))
|
|
|
52 |
cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
|
53 |
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
|
54 |
entry_list = list(set(df['BaseName']))
|
55 |
entry_list.sort()
|
56 |
|
57 |
-
return cleaned_df, ownership_dict, entry_list
|
58 |
except Exception as e:
|
59 |
st.error(f'Error loading file: {str(e)}')
|
60 |
return None
|
|
|
49 |
if sport == 'MLB':
|
50 |
df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
|
51 |
ownership_dict = dict(zip(df['Player'], df['Own']))
|
52 |
+
fpts_dict = dict(zip(df['Player'], df['FPTS']))
|
53 |
cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
|
54 |
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
|
55 |
entry_list = list(set(df['BaseName']))
|
56 |
entry_list.sort()
|
57 |
|
58 |
+
return cleaned_df, ownership_dict, fpts_dict, entry_list
|
59 |
except Exception as e:
|
60 |
st.error(f'Error loading file: {str(e)}')
|
61 |
return None
|