James McCool commited on
Commit
5f9c332
·
1 Parent(s): 3502a68

Refactor player data calculations in app.py for improved clarity and efficiency

Browse files

- Updated the logic for calculating player usage by creating copies of the working dataframe for contest players and using nlargest for percentage-based player selection.
- Enhanced the player counts calculation to flatten the player columns, ensuring accurate representation of player usage in the display.
- Streamlined the code for better readability and maintainability, contributing to overall application performance.

Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -184,15 +184,15 @@ with tab2:
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 = pd.Series(list(contest_players)).value_counts()
196
  st.write(player_counts)
197
  player_frame = player_counts.to_frame().reset_index().rename(columns={'index': 'Player', 0: 'Count'})
198
  player_frame['Percent'] = player_frame['Count'] / len(working_df)
 
184
  players_10per = set()
185
  players_20per = set()
186
  for col in player_columns:
187
+ contest_players = working_df.copy()
188
+ players_1per = working_df.nlargest(n=int(len(working_df) * 0.01), columns='actual')
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 = pd.Series(list(contest_players[player_columns].values.flatten())).value_counts()
196
  st.write(player_counts)
197
  player_frame = player_counts.to_frame().reset_index().rename(columns={'index': 'Player', 0: 'Count'})
198
  player_frame['Percent'] = player_frame['Count'] / len(working_df)