James McCool
commited on
Commit
·
4ad4038
1
Parent(s):
e64137a
Add input validation for contest and projection files in app.py
Browse files- Introduced a new function, is_valid_input, to check if the uploaded files are valid DataFrames and not empty.
- Updated the condition for executing name matching functions to utilize the new validation, enhancing data integrity and user experience.
app.py
CHANGED
@@ -40,6 +40,12 @@ from global_func.create_stack_size_exposures import create_stack_size_exposures
|
|
40 |
from global_func.create_general_exposures import create_general_exposures
|
41 |
from global_func.grab_contest_data import grab_contest_data
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
player_exposure_format = {'Exposure Overall': '{:.2%}', 'Exposure Top 1%': '{:.2%}', 'Exposure Top 5%': '{:.2%}', 'Exposure Top 10%': '{:.2%}', 'Exposure Top 20%': '{:.2%}'}
|
44 |
|
45 |
tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
|
@@ -112,7 +118,7 @@ with tab1:
|
|
112 |
st.success('Projections file loaded successfully!')
|
113 |
st.dataframe(st.session_state['projections_df'].head(10))
|
114 |
|
115 |
-
if Contest_file and projections_file:
|
116 |
st.subheader("Name Matching functions")
|
117 |
if 'Adj_Contest' not in st.session_state:
|
118 |
try:
|
|
|
40 |
from global_func.create_general_exposures import create_general_exposures
|
41 |
from global_func.grab_contest_data import grab_contest_data
|
42 |
|
43 |
+
def is_valid_input(file):
|
44 |
+
if isinstance(file, pd.DataFrame):
|
45 |
+
return not file.empty
|
46 |
+
else:
|
47 |
+
return file is not None # For Streamlit uploader objects
|
48 |
+
|
49 |
player_exposure_format = {'Exposure Overall': '{:.2%}', 'Exposure Top 1%': '{:.2%}', 'Exposure Top 5%': '{:.2%}', 'Exposure Top 10%': '{:.2%}', 'Exposure Top 20%': '{:.2%}'}
|
50 |
|
51 |
tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
|
|
|
118 |
st.success('Projections file loaded successfully!')
|
119 |
st.dataframe(st.session_state['projections_df'].head(10))
|
120 |
|
121 |
+
if is_valid_input(Contest_file) and is_valid_input(projections_file):
|
122 |
st.subheader("Name Matching functions")
|
123 |
if 'Adj_Contest' not in st.session_state:
|
124 |
try:
|