James McCool
commited on
Commit
·
9746a04
1
Parent(s):
4f6b05a
Refactor player counts display logic in app.py for enhanced data aggregation
Browse files- Consolidated player counts for various percentage thresholds into a single dataframe for improved clarity and efficiency in presentation.
- Streamlined the logic for displaying player and stack counts, ensuring consistent data representation across the application.
- Enhanced user interaction by maintaining player data in session state, allowing for better data management and visibility.
app.py
CHANGED
@@ -189,18 +189,25 @@ with tab2:
|
|
189 |
players_5per = working_df.nlargest(n=int(len(working_df) * 0.05), columns='actual')
|
190 |
players_10per = working_df.nlargest(n=int(len(working_df) * 0.10), columns='actual')
|
191 |
players_20per = working_df.nlargest(n=int(len(working_df) * 0.20), columns='actual')
|
|
|
|
|
|
|
|
|
|
|
192 |
with st.container():
|
193 |
tab1, tab2 = st.tabs(['Player Used Info', 'Stack Used Info'])
|
194 |
with tab1:
|
195 |
-
player_counts
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
201 |
with tab2:
|
202 |
-
stack_counts = pd.Series(list(working_df['stack']
|
203 |
-
st.write(stack_counts)
|
204 |
stack_frame = stack_counts.to_frame().reset_index().rename(columns={'index': 'Stack', 'count': 'Count'})
|
205 |
stack_frame['Percent'] = stack_frame['Count'] / len(working_df)
|
206 |
stack_frame = stack_frame[['Stack', 'Count', 'Percent']]
|
|
|
189 |
players_5per = working_df.nlargest(n=int(len(working_df) * 0.05), columns='actual')
|
190 |
players_10per = working_df.nlargest(n=int(len(working_df) * 0.10), columns='actual')
|
191 |
players_20per = working_df.nlargest(n=int(len(working_df) * 0.20), columns='actual')
|
192 |
+
player_counts = pd.Series(list(contest_players[player_columns].values.flatten())).value_counts()
|
193 |
+
player_1per_counts = pd.Series(list(players_1per[player_columns].values.flatten())).value_counts()
|
194 |
+
player_5per_counts = pd.Series(list(players_5per[player_columns].values.flatten())).value_counts()
|
195 |
+
player_10per_counts = pd.Series(list(players_10per[player_columns].values.flatten())).value_counts()
|
196 |
+
player20_per_counts = pd.Series(list(players_20per[player_columns].values.flatten())).value_counts()
|
197 |
with st.container():
|
198 |
tab1, tab2 = st.tabs(['Player Used Info', 'Stack Used Info'])
|
199 |
with tab1:
|
200 |
+
for each_set in [player_counts, player_1per_counts, player_5per_counts, player_10per_counts, player20_per_counts]:
|
201 |
+
set_frame = each_set.to_frame().reset_index().rename(columns={'index': 'Player', 'count': 'Count'})
|
202 |
+
set_frame['Percent'] = set_frame['Count'] / len(working_df)
|
203 |
+
set_frame = set_frame[['Player', 'Count', 'Percent']]
|
204 |
+
if 'player_frame' not in st.session_state:
|
205 |
+
st.session_state['player_frame'] = set_frame
|
206 |
+
else:
|
207 |
+
st.session_state['player_frame'] = pd.merge(st.session_state['player_frame'], set_frame, on='Player', how='outer')
|
208 |
+
st.dataframe(st.session_state['player_frame'])
|
209 |
with tab2:
|
210 |
+
stack_counts = pd.Series(list(working_df['stack'])).value_counts()
|
|
|
211 |
stack_frame = stack_counts.to_frame().reset_index().rename(columns={'index': 'Stack', 'count': 'Count'})
|
212 |
stack_frame['Percent'] = stack_frame['Count'] / len(working_df)
|
213 |
stack_frame = stack_frame[['Stack', 'Count', 'Percent']]
|