James McCool
commited on
Commit
·
28939d0
1
Parent(s):
ede753b
Update session state management in app.py for adjusted dataframes
Browse files- Refactored session state variables to use 'Adj_' prefix for adjusted dataframes, enhancing clarity in data handling.
- Updated logic for name mismatches and salary formatting to reflect the new dataframe names.
- Improved player column processing and mapping dictionary creation to utilize adjusted dataframes, streamlining data processing and presentation.
app.py
CHANGED
|
@@ -74,34 +74,34 @@ with tab1:
|
|
| 74 |
|
| 75 |
if Contest_file and projections_file:
|
| 76 |
st.subheader("Name Matching functions")
|
| 77 |
-
st.session_state['
|
| 78 |
-
st.session_state['
|
| 79 |
-
st.session_state['ownership_dict'] = dict(zip(st.session_state['
|
| 80 |
-
st.session_state['actual_dict'] = dict(zip(st.session_state['
|
| 81 |
|
| 82 |
|
| 83 |
with tab2:
|
| 84 |
excluded_cols = ['BaseName', 'EntryCount']
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
|
| 104 |
-
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
| 105 |
if type_var == 'Classic':
|
| 106 |
working_df['stack'] = working_df.apply(
|
| 107 |
lambda row: Counter(
|
|
|
|
| 74 |
|
| 75 |
if Contest_file and projections_file:
|
| 76 |
st.subheader("Name Matching functions")
|
| 77 |
+
st.session_state['Adj_Contest'], st.session_state['Adj_projections_df'], st.session_state['Adj_ownership_df'], st.session_state['Adj_actual_df'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_df'], st.session_state['actual_df'])
|
| 78 |
+
st.session_state['Adj_projections_df']['salary'] = (st.session_state['Adj_projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
| 79 |
+
st.session_state['ownership_dict'] = dict(zip(st.session_state['Adj_ownership_df']['Player'], st.session_state['Adj_ownership_df']['Own']))
|
| 80 |
+
st.session_state['actual_dict'] = dict(zip(st.session_state['Adj_actual_df']['Player'], st.session_state['Adj_actual_df']['FPTS']))
|
| 81 |
|
| 82 |
|
| 83 |
with tab2:
|
| 84 |
excluded_cols = ['BaseName', 'EntryCount']
|
| 85 |
+
if 'Adj_Contest' in st.session_state and 'Adj_projections_df' in st.session_state:
|
| 86 |
+
player_columns = [col for col in st.session_state['Adj_Contest'].columns if col not in excluded_cols]
|
| 87 |
+
for col in player_columns:
|
| 88 |
+
st.session_state['Adj_Contest'][col] = st.session_state['Adj_Contest'][col].astype(str)
|
| 89 |
|
| 90 |
+
# Create mapping dictionaries
|
| 91 |
+
map_dict = {
|
| 92 |
+
'pos_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['position'])),
|
| 93 |
+
'team_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['team'])),
|
| 94 |
+
'salary_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['salary'])),
|
| 95 |
+
'proj_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['median'])),
|
| 96 |
+
'own_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['ownership'])),
|
| 97 |
+
'own_percent_rank': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['ownership'].rank(pct=True))),
|
| 98 |
+
'cpt_salary_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['salary'])),
|
| 99 |
+
'cpt_proj_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['median'] * 1.5)),
|
| 100 |
+
'cpt_own_map': dict(zip(st.session_state['Adj_projections_df']['player_names'], st.session_state['Adj_projections_df']['captain ownership']))
|
| 101 |
+
}
|
| 102 |
+
# Create a copy of the dataframe for calculations
|
| 103 |
+
working_df = st.session_state['Adj_Contest'].copy()
|
| 104 |
|
|
|
|
| 105 |
if type_var == 'Classic':
|
| 106 |
working_df['stack'] = working_df.apply(
|
| 107 |
lambda row: Counter(
|