James McCool
commited on
Commit
·
d765ee8
1
Parent(s):
678dd59
Enhance player filtering and metric calculations in app.py
Browse files- Reorganized the player selection form within an expander for better user experience.
- Added logic to calculate 'stack' and 'stack_size' metrics based on player data for the 'Classic' game type, improving data analysis capabilities.
- Streamlined the application of filters to ensure accurate data processing and user interaction.
app.py
CHANGED
@@ -4,7 +4,7 @@ import numpy as np
|
|
4 |
import pandas as pd
|
5 |
import time
|
6 |
from fuzzywuzzy import process
|
7 |
-
import
|
8 |
|
9 |
## import global functions
|
10 |
from global_func.clean_player_name import clean_player_name
|
@@ -101,18 +101,33 @@ with tab2:
|
|
101 |
working_df = st.session_state['Contest'].copy()
|
102 |
|
103 |
with col1:
|
104 |
-
with st.
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
113 |
|
114 |
# Calculate metrics based on game type
|
115 |
if type_var == 'Classic':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
working_df['salary'] = working_df.apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
117 |
working_df['median'] = working_df.apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
118 |
working_df['Own'] = working_df.apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
|
|
4 |
import pandas as pd
|
5 |
import time
|
6 |
from fuzzywuzzy import process
|
7 |
+
from collections import Counter
|
8 |
|
9 |
## import global functions
|
10 |
from global_func.clean_player_name import clean_player_name
|
|
|
101 |
working_df = st.session_state['Contest'].copy()
|
102 |
|
103 |
with col1:
|
104 |
+
with st.expander("Info and filters"):
|
105 |
+
with st.form(key='filter_form'):
|
106 |
+
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
107 |
+
entry_parse_var = st.selectbox("Do you want to view a specific player(s) or a group of players?", ['All', 'Specific'])
|
108 |
+
entry_names = st.multiselect("Select players", options=st.session_state['entry_list'], default=[])
|
109 |
+
submitted = st.form_submit_button("Submit")
|
110 |
+
if submitted:
|
111 |
+
# Apply entry name filter if specific entries are selected
|
112 |
+
if entry_parse_var == 'Specific' and entry_names:
|
113 |
+
working_df = working_df[working_df['BaseName'].isin(entry_names)]
|
114 |
|
115 |
# Calculate metrics based on game type
|
116 |
if type_var == 'Classic':
|
117 |
+
working_df['stack'] = working_df.apply(
|
118 |
+
lambda row: Counter(
|
119 |
+
map_dict['team_map'].get(player, '') for player in row
|
120 |
+
if map_dict['team_map'].get(player, '') != ''
|
121 |
+
).most_common(1)[0][0] if any(map_dict['team_map'].get(player, '') for player in row) else '',
|
122 |
+
axis=1
|
123 |
+
)
|
124 |
+
working_df['stack_size'] = working_df.apply(
|
125 |
+
lambda row: Counter(
|
126 |
+
map_dict['team_map'].get(player, '') for player in row
|
127 |
+
if map_dict['team_map'].get(player, '') != ''
|
128 |
+
).most_common(1)[0][1] if any(map_dict['team_map'].get(player, '') for player in row) else '',
|
129 |
+
axis=1
|
130 |
+
)
|
131 |
working_df['salary'] = working_df.apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
132 |
working_df['median'] = working_df.apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
133 |
working_df['Own'] = working_df.apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|