James McCool
commited on
Commit
Β·
f978d14
1
Parent(s):
22ba691
Enhance player and stack data presentation in app.py
Browse files- Introduced new logic to display player usage and stack information in separate tabs, improving data visibility and user interaction.
- Updated pagination controls to maintain functionality while displaying a paginated dataframe with enhanced styling for better clarity.
- Ensured accurate calculation of player counts and stack percentages, streamlining data analysis capabilities.
app.py
CHANGED
@@ -175,32 +175,58 @@ with tab2:
|
|
175 |
)
|
176 |
working_df['dupes'] = working_df.groupby('sorted').transform('size')
|
177 |
working_df = working_df.drop('sorted', axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
#
|
180 |
-
|
181 |
-
|
182 |
|
183 |
-
#
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
|
188 |
-
#
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
|
199 |
-
#
|
200 |
-
|
201 |
-
|
202 |
|
203 |
# Display the paginated dataframe
|
204 |
-
st.
|
205 |
-
working_df
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
)
|
|
|
175 |
)
|
176 |
working_df['dupes'] = working_df.groupby('sorted').transform('size')
|
177 |
working_df = working_df.drop('sorted', axis=1)
|
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', 'Projection 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'})
|
188 |
+
player_frame['Percent'] = player_frame['Count'] / len(working_df)
|
189 |
+
player_frame = player_frame[['Player', 'Count', 'Percent']]
|
190 |
+
st.dataframe(player_frame)
|
191 |
+
with tab2:
|
192 |
+
stack_counts = working_df['stack'].value_counts()
|
193 |
+
stack_frame = stack_counts.to_frame().reset_index().rename(columns={'index': 'Stack', 0: 'Count'})
|
194 |
+
stack_frame['Percent'] = stack_frame['Count'] / len(working_df)
|
195 |
+
stack_frame = stack_frame[['Stack', 'Count', 'Percent']]
|
196 |
+
st.dataframe(stack_frame)
|
197 |
+
|
198 |
|
199 |
+
# Initialize pagination in session state if not exists
|
200 |
+
if 'current_page' not in st.session_state:
|
201 |
+
st.session_state.current_page = 0
|
202 |
|
203 |
+
# Calculate total pages
|
204 |
+
rows_per_page = 500
|
205 |
+
total_rows = len(working_df)
|
206 |
+
total_pages = (total_rows + rows_per_page - 1) // rows_per_page
|
207 |
|
208 |
+
# Create pagination controls in a single row
|
209 |
+
pagination_cols = st.columns([4, 1, 1, 1, 4])
|
210 |
+
with pagination_cols[1]:
|
211 |
+
if st.button("β Previous", disabled=st.session_state.current_page == 0):
|
212 |
+
st.session_state.current_page -= 1
|
213 |
+
with pagination_cols[2]:
|
214 |
+
st.markdown(f"**Page {st.session_state.current_page + 1} of {total_pages}**", unsafe_allow_html=True)
|
215 |
+
with pagination_cols[3]:
|
216 |
+
if st.button("Next β", disabled=st.session_state.current_page == total_pages - 1):
|
217 |
+
st.session_state.current_page += 1
|
218 |
|
219 |
+
# Calculate start and end indices for current page
|
220 |
+
start_idx = st.session_state.current_page * rows_per_page
|
221 |
+
end_idx = min((st.session_state.current_page + 1) * rows_per_page, total_rows)
|
222 |
|
223 |
# Display the paginated dataframe
|
224 |
+
st.dataframe(
|
225 |
+
working_df.iloc[start_idx:end_idx].style
|
226 |
+
.background_gradient(axis=0)
|
227 |
+
.background_gradient(cmap='RdYlGn')
|
228 |
+
.format(precision=2),
|
229 |
+
height=1000,
|
230 |
+
use_container_width=True,
|
231 |
+
hide_index=True
|
232 |
)
|