James McCool
commited on
Commit
·
e7e2a49
1
Parent(s):
33dca61
Refactor projections file handling in app.py for improved clarity and functionality
Browse files- Removed the projections file upload section and associated logic to streamline the user interface.
- Updated the handling of ownership and actual data dictionaries to directly utilize session state variables, enhancing data accessibility.
- These changes contribute to ongoing efforts to simplify the application and improve user experience.
app.py
CHANGED
|
@@ -92,46 +92,12 @@ with tab1:
|
|
| 92 |
if st.session_state['Contest'] is not None:
|
| 93 |
st.success('Contest file loaded successfully!')
|
| 94 |
st.dataframe(st.session_state['Contest'].head(10))
|
| 95 |
-
|
| 96 |
-
with col2:
|
| 97 |
-
st.subheader("Projections File")
|
| 98 |
-
st.info("upload a projections file that has 'player_names', 'salary', 'median', 'ownership', and 'captain ownership' (Needed for Showdown) columns. Note that the salary for showdown needs to be the FLEX salary, not the captain salary.")
|
| 99 |
-
|
| 100 |
-
# Create two columns for the uploader and template button
|
| 101 |
-
upload_col, template_col = st.columns([3, 1])
|
| 102 |
-
|
| 103 |
-
with upload_col:
|
| 104 |
-
projections_file = st.file_uploader("Upload Projections File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
| 105 |
-
if 'projections_df' in st.session_state:
|
| 106 |
-
del st.session_state['projections_df']
|
| 107 |
-
|
| 108 |
-
with template_col:
|
| 109 |
-
# Create empty DataFrame with required columns
|
| 110 |
-
template_df = pd.DataFrame(columns=['player_names', 'position', 'team', 'salary', 'median', 'ownership', 'captain ownership'])
|
| 111 |
-
# Add download button for template
|
| 112 |
-
st.download_button(
|
| 113 |
-
label="Template",
|
| 114 |
-
data=template_df.to_csv(index=False),
|
| 115 |
-
file_name="projections_template.csv",
|
| 116 |
-
mime="text/csv"
|
| 117 |
-
)
|
| 118 |
-
|
| 119 |
-
if projections_file and 'Adj_projections_df' not in st.session_state:
|
| 120 |
-
export_projections, st.session_state['projections_df'] = load_file(projections_file)
|
| 121 |
-
if st.session_state['projections_df'] is not None:
|
| 122 |
-
st.success('Projections file loaded successfully!')
|
| 123 |
-
st.dataframe(st.session_state['projections_df'].head(10))
|
| 124 |
|
| 125 |
-
if 'Contest_file' in st.session_state
|
| 126 |
-
st.
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
except:
|
| 131 |
-
st.warning('Please manage name matching to move forward')
|
| 132 |
-
st.session_state['Adj_projections_df']['salary'] = (st.session_state['Adj_projections_df']['salary'].astype(str).str.replace(',', '').astype(float).astype(int))
|
| 133 |
-
st.session_state['ownership_dict'] = dict(zip(st.session_state['Adj_ownership_df']['Player'], st.session_state['Adj_ownership_df']['Own']))
|
| 134 |
-
st.session_state['actual_dict'] = dict(zip(st.session_state['Adj_actual_df']['Player'], st.session_state['Adj_actual_df']['FPTS']))
|
| 135 |
|
| 136 |
|
| 137 |
with tab2:
|
|
|
|
| 92 |
if st.session_state['Contest'] is not None:
|
| 93 |
st.success('Contest file loaded successfully!')
|
| 94 |
st.dataframe(st.session_state['Contest'].head(10))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
if 'Contest_file' in st.session_state:
|
| 97 |
+
st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_df']['Player'], st.session_state['ownership_df']['Own']))
|
| 98 |
+
st.session_state['actual_dict'] = dict(zip(st.session_state['actual_df']['Player'], st.session_state['actual_df']['FPTS']))
|
| 99 |
+
st.write(st.session_state['ownership_dict'])
|
| 100 |
+
st.write(st.session_state['actual_dict'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
with tab2:
|