James McCool
commited on
Commit
·
31a2d34
1
Parent(s):
add3343
Add general comparison feature in app.py and create_general_comparison.py
Browse files- Introduced a new function, create_general_comparison, to facilitate the comparison of general exposures based on user selections.
- Updated app.py to include a form for selecting generals to compare, enhancing user interaction and data analysis capabilities.
- Improved data display for general comparisons, ensuring accurate representation of exposure data in the DataFrame.
- app.py +24 -8
- global_func/create_general_comparison.py +33 -0
app.py
CHANGED
|
@@ -66,6 +66,7 @@ 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):
|
|
@@ -551,14 +552,29 @@ with tab2:
|
|
| 551 |
hide_index=True)
|
| 552 |
|
| 553 |
with tab4:
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
else:
|
| 560 |
-
st.session_state['
|
| 561 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
with tab5:
|
| 564 |
with st.form(key='dupe_form'):
|
|
@@ -580,7 +596,7 @@ with tab2:
|
|
| 580 |
dupe_frame['under_5%'] = dupe_frame['under_5'] / dupe_frame['EntryCount']
|
| 581 |
dupe_frame['under_10%'] = dupe_frame['under_10'] / dupe_frame['EntryCount']
|
| 582 |
dupe_frame = dupe_frame[['BaseName', 'EntryCount', 'average_dupes', 'uniques', 'uniques%', 'under_5', 'under_5%', 'under_10', 'under_10%']].drop_duplicates(subset='BaseName', keep='first')
|
| 583 |
-
st.session_state['duplication_frame'] = dupe_frame.sort_values(by='
|
| 584 |
if user_dupe_var == 'Specific':
|
| 585 |
st.session_state['duplication_frame'] = st.session_state['duplication_frame'][st.session_state['duplication_frame']['BaseName'].isin(user_dupe_select)]
|
| 586 |
|
|
|
|
| 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 |
+
from global_func.create_general_comparison import create_general_comparison
|
| 70 |
|
| 71 |
def is_valid_input(file):
|
| 72 |
if isinstance(file, pd.DataFrame):
|
|
|
|
| 552 |
hide_index=True)
|
| 553 |
|
| 554 |
with tab4:
|
| 555 |
+
with st.form(key='general_comp_form'):
|
| 556 |
+
col1, col2 = st.columns(2)
|
| 557 |
+
with col1:
|
| 558 |
+
comp_general_var = st.selectbox("Would you like to compare with anyone?", ['No', 'Yes'], key='comp_general_var')
|
| 559 |
+
with col2:
|
| 560 |
+
comp_general_select = st.multiselect("Select generals to compare with:", st.session_state['display_contest_info']['BaseName'].sort_values().unique(), key='comp_general_select')
|
| 561 |
+
submitted = st.form_submit_button("Submit")
|
| 562 |
+
if submitted:
|
| 563 |
+
if comp_general_var == 'No':
|
| 564 |
+
comp_general_select = None
|
| 565 |
+
else:
|
| 566 |
+
comp_general_select = comp_general_select
|
| 567 |
+
if comp_general_var == 'Yes':
|
| 568 |
+
general_comp = create_general_comparison(st.session_state['display_contest_info'], comp_general_select)
|
| 569 |
+
st.dataframe(general_comp.style.background_gradient(cmap='RdYlGn', axis=0).format(formatter='{:.2%}', subset=general_comp.select_dtypes(include=['number']).columns), hide_index=True)
|
| 570 |
else:
|
| 571 |
+
if st.session_state['entry_parse_var'] == 'All':
|
| 572 |
+
st.session_state['general_frame'] = create_general_exposures(st.session_state['display_contest_info'])
|
| 573 |
+
st.dataframe(st.session_state['general_frame'].style.background_gradient(cmap='RdYlGn', axis=1).format(precision=2), hide_index=True)
|
| 574 |
+
|
| 575 |
+
else:
|
| 576 |
+
st.session_state['general_frame'] = create_general_exposures(st.session_state['display_contest_info'], st.session_state['entry_names'])
|
| 577 |
+
st.dataframe(st.session_state['general_frame'].style.background_gradient(cmap='RdYlGn', axis=1).format(precision=2), hide_index=True)
|
| 578 |
|
| 579 |
with tab5:
|
| 580 |
with st.form(key='dupe_form'):
|
|
|
|
| 596 |
dupe_frame['under_5%'] = dupe_frame['under_5'] / dupe_frame['EntryCount']
|
| 597 |
dupe_frame['under_10%'] = dupe_frame['under_10'] / dupe_frame['EntryCount']
|
| 598 |
dupe_frame = dupe_frame[['BaseName', 'EntryCount', 'average_dupes', 'uniques', 'uniques%', 'under_5', 'under_5%', 'under_10', 'under_10%']].drop_duplicates(subset='BaseName', keep='first')
|
| 599 |
+
st.session_state['duplication_frame'] = dupe_frame.sort_values(by='uniques%', ascending=False)
|
| 600 |
if user_dupe_var == 'Specific':
|
| 601 |
st.session_state['duplication_frame'] = st.session_state['duplication_frame'][st.session_state['duplication_frame']['BaseName'].isin(user_dupe_select)]
|
| 602 |
|
global_func/create_general_comparison.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
def create_general_comparison(df: pd.DataFrame, entrants: list = None):
|
| 4 |
+
loop_list = ['Overall'] + entrants
|
| 5 |
+
for entrant in loop_list:
|
| 6 |
+
check_cols = ['salary', 'actual_fpts', 'actual_own', 'dupes', 'uniques', 'under_5', 'under_10']
|
| 7 |
+
general_exposures = pd.DataFrame()
|
| 8 |
+
for each_col in check_cols:
|
| 9 |
+
general_frame = pd.DataFrame()
|
| 10 |
+
|
| 11 |
+
if entrant == 'Overall':
|
| 12 |
+
overall_general = pd.Series(list(df[each_col])).sum()
|
| 13 |
+
else:
|
| 14 |
+
overall_general = pd.Series(list(df[df['BaseName'] == entrant][each_col])).sum()
|
| 15 |
+
general_contest_len = len(df)
|
| 16 |
+
each_set_name = ['Overall']
|
| 17 |
+
each_general_set = [overall_general]
|
| 18 |
+
each_general_len_set = [general_contest_len]
|
| 19 |
+
general_count_var = 0
|
| 20 |
+
for each_general in each_general_set:
|
| 21 |
+
general_frame['Stat'] = [each_col]
|
| 22 |
+
try:
|
| 23 |
+
general_frame['Average'] = [each_general / each_general_len_set[general_count_var]]
|
| 24 |
+
except:
|
| 25 |
+
general_frame['Average'] = [0]
|
| 26 |
+
general_frame = general_frame.rename(columns={'Average': f'Average {entrant}'})
|
| 27 |
+
general_exposures = pd.concat([general_exposures, general_frame], ignore_index = True, axis = 0)
|
| 28 |
+
general_exposures['Stat'] = general_exposures['Stat'].replace(['salary', 'actual_fpts', 'actual_own', 'dupes', 'uniques', 'under_5', 'under_10'], ['Salary Used', 'Finishing Points', 'Total Ownership', 'Duplications', 'Uniques', 'Under 5', 'Under 10'])
|
| 29 |
+
if entrant == 'Overall':
|
| 30 |
+
final_exposures = general_exposures
|
| 31 |
+
else:
|
| 32 |
+
final_exposures = pd.merge(final_exposures, general_exposures, on='Stat', how='outer')
|
| 33 |
+
return final_exposures
|