James McCool
commited on
Commit
·
6a12985
1
Parent(s):
c4807f3
Enhance find_name_mismatches function and app.py session state management
Browse files- Updated the find_name_mismatches function to include a new parameter for calc_toggle, allowing for better tracking of calculation states.
- Modified app.py to ensure calc_toggle is properly managed within session state, improving the overall functionality and user experience during name matching processes.
- Streamlined the handling of data frames by removing unnecessary columns, focusing on relevant metrics for clearer data presentation.
- app.py +7 -8
- global_func/find_name_mismatches.py +6 -6
app.py
CHANGED
@@ -18,11 +18,13 @@ from global_func.load_csv import load_csv
|
|
18 |
from global_func.find_csv_mismatches import find_csv_mismatches
|
19 |
|
20 |
player_exposure_format = {'Exposure Overall': '{:.2%}', 'Exposure Top 1%': '{:.2%}', 'Exposure Top 5%': '{:.2%}', 'Exposure Top 10%': '{:.2%}', 'Exposure Top 20%': '{:.2%}'}
|
|
|
21 |
|
22 |
tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
|
23 |
with tab1:
|
24 |
if st.button('Clear data', key='reset1'):
|
25 |
st.session_state.clear()
|
|
|
26 |
sport_select = st.selectbox("Select Sport", ['MLB', 'NBA', 'NFL'])
|
27 |
# Add file uploaders to your app
|
28 |
col1, col2 = st.columns(2)
|
@@ -71,15 +73,15 @@ with tab1:
|
|
71 |
st.success('Projections file loaded successfully!')
|
72 |
st.dataframe(st.session_state['projections_df'].head(10))
|
73 |
|
|
|
|
|
74 |
if Contest_file and projections_file:
|
75 |
st.subheader("Name Matching functions")
|
76 |
-
st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'])
|
77 |
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
78 |
st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_dict']['Player'], st.session_state['ownership_dict']['Own']))
|
79 |
st.session_state['actual_dict'] = dict(zip(st.session_state['actual_dict']['Player'], st.session_state['actual_dict']['FPTS']))
|
80 |
|
81 |
-
|
82 |
-
with tab2:
|
83 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
84 |
col1, col2 = st.columns([1, 8])
|
85 |
excluded_cols = ['BaseName', 'EntryCount']
|
@@ -251,8 +253,7 @@ with tab2:
|
|
251 |
for each_set in each_frame_set:
|
252 |
set_frame = each_set.to_frame().reset_index().rename(columns={'index': 'Player', 'count': 'Count'})
|
253 |
set_frame['Percent'] = set_frame['Count'] / each_len_set[player_count_var]
|
254 |
-
set_frame = set_frame[['Player', '
|
255 |
-
set_frame = set_frame.rename(columns={'Count': f'Count {each_set_name[player_count_var]}'})
|
256 |
set_frame = set_frame.rename(columns={'Percent': f'Exposure {each_set_name[player_count_var]}'})
|
257 |
if 'player_frame' not in st.session_state:
|
258 |
st.session_state['player_frame'] = set_frame
|
@@ -313,9 +314,7 @@ with tab2:
|
|
313 |
for each_stack in each_stacks_set:
|
314 |
stack_frame = each_stack.to_frame().reset_index().rename(columns={'index': 'Stack', 'count': 'Count'})
|
315 |
stack_frame['Percent'] = stack_frame['Count'] / each_stacks_len_set[stack_count_var]
|
316 |
-
stack_frame = stack_frame[['Stack', '
|
317 |
-
st.write(stack_frame['Count'])
|
318 |
-
stack_frame = stack_frame.rename(columns={'Count': f'Count {each_set_name[stack_count_var]}'})
|
319 |
stack_frame = stack_frame.rename(columns={'Percent': f'Exposure {each_set_name[stack_count_var]}'})
|
320 |
if 'stack_frame' not in st.session_state:
|
321 |
st.session_state['stack_frame'] = stack_frame
|
|
|
18 |
from global_func.find_csv_mismatches import find_csv_mismatches
|
19 |
|
20 |
player_exposure_format = {'Exposure Overall': '{:.2%}', 'Exposure Top 1%': '{:.2%}', 'Exposure Top 5%': '{:.2%}', 'Exposure Top 10%': '{:.2%}', 'Exposure Top 20%': '{:.2%}'}
|
21 |
+
st.session_state['calc_toggle'] = False
|
22 |
|
23 |
tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
|
24 |
with tab1:
|
25 |
if st.button('Clear data', key='reset1'):
|
26 |
st.session_state.clear()
|
27 |
+
st.session_state['calc_toggle'] = False
|
28 |
sport_select = st.selectbox("Select Sport", ['MLB', 'NBA', 'NFL'])
|
29 |
# Add file uploaders to your app
|
30 |
col1, col2 = st.columns(2)
|
|
|
73 |
st.success('Projections file loaded successfully!')
|
74 |
st.dataframe(st.session_state['projections_df'].head(10))
|
75 |
|
76 |
+
|
77 |
+
with tab2:
|
78 |
if Contest_file and projections_file:
|
79 |
st.subheader("Name Matching functions")
|
80 |
+
st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'], st.session_state['calc_toggle'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'], st.session_state['calc_toggle'])
|
81 |
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
82 |
st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_dict']['Player'], st.session_state['ownership_dict']['Own']))
|
83 |
st.session_state['actual_dict'] = dict(zip(st.session_state['actual_dict']['Player'], st.session_state['actual_dict']['FPTS']))
|
84 |
|
|
|
|
|
85 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
86 |
col1, col2 = st.columns([1, 8])
|
87 |
excluded_cols = ['BaseName', 'EntryCount']
|
|
|
253 |
for each_set in each_frame_set:
|
254 |
set_frame = each_set.to_frame().reset_index().rename(columns={'index': 'Player', 'count': 'Count'})
|
255 |
set_frame['Percent'] = set_frame['Count'] / each_len_set[player_count_var]
|
256 |
+
set_frame = set_frame[['Player', 'Percent']]
|
|
|
257 |
set_frame = set_frame.rename(columns={'Percent': f'Exposure {each_set_name[player_count_var]}'})
|
258 |
if 'player_frame' not in st.session_state:
|
259 |
st.session_state['player_frame'] = set_frame
|
|
|
314 |
for each_stack in each_stacks_set:
|
315 |
stack_frame = each_stack.to_frame().reset_index().rename(columns={'index': 'Stack', 'count': 'Count'})
|
316 |
stack_frame['Percent'] = stack_frame['Count'] / each_stacks_len_set[stack_count_var]
|
317 |
+
stack_frame = stack_frame[['Stack', 'Percent']]
|
|
|
|
|
318 |
stack_frame = stack_frame.rename(columns={'Percent': f'Exposure {each_set_name[stack_count_var]}'})
|
319 |
if 'stack_frame' not in st.session_state:
|
320 |
st.session_state['stack_frame'] = stack_frame
|
global_func/find_name_mismatches.py
CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
|
|
4 |
import time
|
5 |
from fuzzywuzzy import process
|
6 |
|
7 |
-
def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df):
|
8 |
|
9 |
name_columns = [col for col in contest_df.columns if not col in ['BaseName', 'EntryCount']]
|
10 |
|
@@ -90,11 +90,10 @@ def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df):
|
|
90 |
st.write(contest_name + ' ' + projection_name)
|
91 |
st.success(f"Replaced '{selected_name}' with '{projection_name}'")
|
92 |
|
|
|
|
|
93 |
st.success("All changes applied successfully!")
|
94 |
-
return contest_df, projections_df, ownership_df, fpts_df
|
95 |
-
else:
|
96 |
-
st.success("No changes applied")
|
97 |
-
return contest_df, projections_df, ownership_df, fpts_df
|
98 |
else:
|
99 |
st.success("All players have been automatically matched!")
|
100 |
# Apply automatic matches
|
@@ -104,4 +103,5 @@ def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df):
|
|
104 |
ownership_df['Player'] = ownership_df['Player'].replace(contest_name, projection_name)
|
105 |
fpts_df['Player'] = fpts_df['Player'].replace(contest_name, projection_name)
|
106 |
st.write(contest_name + ' ' + projection_name)
|
107 |
-
|
|
|
|
4 |
import time
|
5 |
from fuzzywuzzy import process
|
6 |
|
7 |
+
def find_name_mismatches(contest_df, projections_df, ownership_df, fpts_df, calc_toggle):
|
8 |
|
9 |
name_columns = [col for col in contest_df.columns if not col in ['BaseName', 'EntryCount']]
|
10 |
|
|
|
90 |
st.write(contest_name + ' ' + projection_name)
|
91 |
st.success(f"Replaced '{selected_name}' with '{projection_name}'")
|
92 |
|
93 |
+
calc_toggle = True
|
94 |
+
|
95 |
st.success("All changes applied successfully!")
|
96 |
+
return contest_df, projections_df, ownership_df, fpts_df, calc_toggle
|
|
|
|
|
|
|
97 |
else:
|
98 |
st.success("All players have been automatically matched!")
|
99 |
# Apply automatic matches
|
|
|
103 |
ownership_df['Player'] = ownership_df['Player'].replace(contest_name, projection_name)
|
104 |
fpts_df['Player'] = fpts_df['Player'].replace(contest_name, projection_name)
|
105 |
st.write(contest_name + ' ' + projection_name)
|
106 |
+
calc_toggle = True
|
107 |
+
return contest_df, projections_df, ownership_df, fpts_df, calc_toggle
|