James McCool
commited on
Commit
·
c6bf99d
1
Parent(s):
c744629
Add size comparison feature in app.py and create_size_comparison.py
Browse files- Introduced a new function, create_size_comparison, to enable comparison of stack sizes based on user selections.
- Updated app.py to include a form for selecting sizes to compare, enhancing user interaction and data analysis capabilities.
- Improved data display for size comparisons, ensuring accurate representation of exposure data in the DataFrame.
- app.py +30 -14
- global_func/create_size_comparison.py +22 -0
app.py
CHANGED
|
@@ -65,6 +65,7 @@ from global_func.create_general_exposures import create_general_exposures
|
|
| 65 |
from global_func.grab_contest_data import grab_contest_data
|
| 66 |
from global_func.create_player_comparison import create_player_comparison
|
| 67 |
from global_func.create_stack_comparison import create_stack_comparison
|
|
|
|
| 68 |
|
| 69 |
def is_valid_input(file):
|
| 70 |
if isinstance(file, pd.DataFrame):
|
|
@@ -518,21 +519,36 @@ with tab2:
|
|
| 518 |
format(formatter='{:.2%}', subset=st.session_state['stack_frame'].iloc[:, 1:].select_dtypes(include=['number']).columns),
|
| 519 |
hide_index=True)
|
| 520 |
with tab3:
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
else:
|
| 530 |
-
st.session_state['
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
|
| 537 |
with tab4:
|
| 538 |
|
|
|
|
| 65 |
from global_func.grab_contest_data import grab_contest_data
|
| 66 |
from global_func.create_player_comparison import create_player_comparison
|
| 67 |
from global_func.create_stack_comparison import create_stack_comparison
|
| 68 |
+
from global_func.create_size_comparison import create_size_comparison
|
| 69 |
|
| 70 |
def is_valid_input(file):
|
| 71 |
if isinstance(file, pd.DataFrame):
|
|
|
|
| 519 |
format(formatter='{:.2%}', subset=st.session_state['stack_frame'].iloc[:, 1:].select_dtypes(include=['number']).columns),
|
| 520 |
hide_index=True)
|
| 521 |
with tab3:
|
| 522 |
+
with st.form(key='size_exp_comp_form'):
|
| 523 |
+
col1, col2 = st.columns(2)
|
| 524 |
+
with col1:
|
| 525 |
+
comp_size_var = st.selectbox("Would you like to compare with anyone?", ['No', 'Yes'], key='comp_size_var')
|
| 526 |
+
with col2:
|
| 527 |
+
comp_size_select = st.multiselect("Select sizes to compare with:", st.session_state['display_contest_info']['BaseName'].sort_values().unique(), key='comp_size_select')
|
| 528 |
+
submitted = st.form_submit_button("Submit")
|
| 529 |
+
if submitted:
|
| 530 |
+
if comp_size_var == 'No':
|
| 531 |
+
comp_size_select = None
|
| 532 |
+
else:
|
| 533 |
+
comp_size_select = comp_size_select
|
| 534 |
+
if comp_size_var == 'Yes':
|
| 535 |
+
size_exp_comp = create_size_comparison(st.session_state['display_contest_info'], comp_size_select)
|
| 536 |
+
st.dataframe(size_exp_comp.style.background_gradient(cmap='RdYlGn', axis=0).format(formatter='{:.2%}', subset=size_exp_comp.select_dtypes(include=['number']).columns), hide_index=True)
|
| 537 |
else:
|
| 538 |
+
if st.session_state['entry_parse_var'] == 'All':
|
| 539 |
+
st.session_state['stack_size_frame'] = create_stack_size_exposures(st.session_state['display_contest_info'])
|
| 540 |
+
st.dataframe(st.session_state['stack_size_frame'].
|
| 541 |
+
sort_values(by='Exposure Overall', ascending=False).
|
| 542 |
+
style.background_gradient(cmap='RdYlGn').
|
| 543 |
+
format(formatter='{:.2%}', subset=st.session_state['stack_size_frame'].iloc[:, 1:].select_dtypes(include=['number']).columns),
|
| 544 |
+
hide_index=True)
|
| 545 |
+
else:
|
| 546 |
+
st.session_state['stack_size_frame'] = create_stack_size_exposures(st.session_state['display_contest_info'], st.session_state['entry_names'])
|
| 547 |
+
st.dataframe(st.session_state['stack_size_frame'].
|
| 548 |
+
sort_values(by='Exposure Overall', ascending=False).
|
| 549 |
+
style.background_gradient(cmap='RdYlGn').
|
| 550 |
+
format(formatter='{:.2%}', subset=st.session_state['stack_size_frame'].iloc[:, 1:].select_dtypes(include=['number']).columns),
|
| 551 |
+
hide_index=True)
|
| 552 |
|
| 553 |
with tab4:
|
| 554 |
|
global_func/create_size_comparison.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
def create_stack_comparison(df: pd.DataFrame, entrants: list):
|
| 4 |
+
overall_players = pd.Series(list(df['stack_size'])).value_counts()
|
| 5 |
+
contest_len = len(df)
|
| 6 |
+
|
| 7 |
+
set_frame = overall_players.to_frame().reset_index().rename(columns={'index': 'Player', 'count': 'Count'})
|
| 8 |
+
set_frame['Percent'] = set_frame['Count'] / contest_len
|
| 9 |
+
set_frame = set_frame[['Player', 'Percent']]
|
| 10 |
+
set_frame = set_frame.rename(columns={'Percent': f'Exposure Overall'})
|
| 11 |
+
player_frame = set_frame
|
| 12 |
+
|
| 13 |
+
for each_user in entrants:
|
| 14 |
+
overall_players = pd.Series(list(df[df['BaseName'] == each_user]['stack_size'])).value_counts()
|
| 15 |
+
|
| 16 |
+
set_frame = overall_players.to_frame().reset_index().rename(columns={'index': 'Player', 'count': 'Count'})
|
| 17 |
+
set_frame['Percent'] = set_frame['Count'] / len(df[df['BaseName'] == each_user])
|
| 18 |
+
set_frame = set_frame[['Player', 'Percent']]
|
| 19 |
+
set_frame = set_frame.rename(columns={'Percent': f'Exposure {each_user}'})
|
| 20 |
+
player_frame = pd.merge(player_frame, set_frame, on='Player', how='outer')
|
| 21 |
+
|
| 22 |
+
return player_frame.sort_values(by='Exposure Overall', ascending=False)
|