James McCool
commited on
Commit
·
869c271
1
Parent(s):
cb50269
Add player information retrieval in app.py for enhanced contest data processing
Browse files- Introduced a new function, grab_contest_player_info, to fetch player details based on contest selection, improving data accessibility.
- Updated session state management to store player information and related mappings, enhancing user experience during contest analysis.
- Maintained existing functionality while expanding the capabilities of contest data handling.
app.py
CHANGED
@@ -32,6 +32,27 @@ def grab_contest_names(db, sport, type):
|
|
32 |
|
33 |
return contest_names, contest_id_map, curr_info
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
db = init_conn()
|
36 |
|
37 |
## import global functions
|
@@ -84,6 +105,7 @@ with tab1:
|
|
84 |
if 'Contest_file' not in st.session_state:
|
85 |
if st.button('Load Contest Data', key='load_contest_data'):
|
86 |
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select, date_select2)
|
|
|
87 |
else:
|
88 |
pass
|
89 |
with col2:
|
@@ -101,12 +123,10 @@ with tab1:
|
|
101 |
pass
|
102 |
|
103 |
if 'Contest_file' in st.session_state:
|
104 |
-
st.table(st.session_state['Contest_file'].head(100))
|
105 |
-
st.write(st.session_state['Contest_file_helper'])
|
106 |
if 'Contest_file_helper' in st.session_state:
|
107 |
-
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['
|
108 |
else:
|
109 |
-
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['
|
110 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
111 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
112 |
if st.session_state['Contest'] is not None:
|
@@ -116,9 +136,9 @@ with tab1:
|
|
116 |
if 'Contest_file' in st.session_state:
|
117 |
st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_df']['Player'], st.session_state['ownership_df']['Own']))
|
118 |
st.session_state['actual_dict'] = dict(zip(st.session_state['actual_df']['Player'], st.session_state['actual_df']['FPTS']))
|
119 |
-
st.session_state['salary_dict'] =
|
120 |
-
st.session_state['team_dict'] =
|
121 |
-
st.session_state['pos_dict'] =
|
122 |
|
123 |
st.write(st.session_state['salary_dict'])
|
124 |
|
|
|
32 |
|
33 |
return contest_names, contest_id_map, curr_info
|
34 |
|
35 |
+
def grab_contest_player_info(db, sport, type, contest_name, contest_id_map):
|
36 |
+
if type == 'Classic':
|
37 |
+
db_type = 'reg'
|
38 |
+
elif type == 'Showdown':
|
39 |
+
db_type = 'sd'
|
40 |
+
collection = db[f'{sport}_{db_type}_player_info']
|
41 |
+
cursor = collection.find()
|
42 |
+
|
43 |
+
player_info = pd.DataFrame(list(cursor)).drop('_id', axis=1)
|
44 |
+
player_info = player_info[player_info['Contest ID'] == contest_id_map[contest_name]]
|
45 |
+
|
46 |
+
info_maps = {
|
47 |
+
'position_dict': dict(zip(player_info['Display Name'], player_info['Position'])),
|
48 |
+
'salary_dict': dict(zip(player_info['Display Name'], player_info['Salary'])),
|
49 |
+
'team_dict': dict(zip(player_info['Display Name'], player_info['Team'])),
|
50 |
+
'opp_dict': dict(zip(player_info['Display Name'], player_info['Opp'])),
|
51 |
+
'fpts_avg_dict': dict(zip(player_info['Display Name'], player_info['Avg FPTS']))
|
52 |
+
}
|
53 |
+
|
54 |
+
return player_info, info_maps
|
55 |
+
|
56 |
db = init_conn()
|
57 |
|
58 |
## import global functions
|
|
|
105 |
if 'Contest_file' not in st.session_state:
|
106 |
if st.button('Load Contest Data', key='load_contest_data'):
|
107 |
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select, date_select2)
|
108 |
+
st.session_state['player_info'], st.session_state['info_maps'] = grab_contest_player_info(db, sport_select, type_var, contest_name_var, contest_id_map)
|
109 |
else:
|
110 |
pass
|
111 |
with col2:
|
|
|
123 |
pass
|
124 |
|
125 |
if 'Contest_file' in st.session_state:
|
|
|
|
|
126 |
if 'Contest_file_helper' in st.session_state:
|
127 |
+
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], st.session_state['Contest_file_helper'], sport_select)
|
128 |
else:
|
129 |
+
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], None, sport_select)
|
130 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
131 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
132 |
if st.session_state['Contest'] is not None:
|
|
|
136 |
if 'Contest_file' in st.session_state:
|
137 |
st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_df']['Player'], st.session_state['ownership_df']['Own']))
|
138 |
st.session_state['actual_dict'] = dict(zip(st.session_state['actual_df']['Player'], st.session_state['actual_df']['FPTS']))
|
139 |
+
st.session_state['salary_dict'] = st.session_state['info_maps']['salary_dict']
|
140 |
+
st.session_state['team_dict'] = st.session_state['info_maps']['team_dict']
|
141 |
+
st.session_state['pos_dict'] = st.session_state['info_maps']['position_dict']
|
142 |
|
143 |
st.write(st.session_state['salary_dict'])
|
144 |
|