James McCool
commited on
Commit
·
5647915
1
Parent(s):
352ec5e
Refactor export functionality in app.py: streamline portfolio download and merging processes, introduce export base for consolidated data management, and enhance display options for portfolio and export data.
Browse files
app.py
CHANGED
@@ -985,7 +985,6 @@ with tab2:
|
|
985 |
st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
|
986 |
|
987 |
with col2:
|
988 |
-
st.write('initiated')
|
989 |
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
990 |
if 'trimming_dict_maxes' not in st.session_state:
|
991 |
st.session_state['trimming_dict_maxes'] = {
|
@@ -1096,53 +1095,73 @@ with tab2:
|
|
1096 |
st.write('Export portfolio updated!')
|
1097 |
else:
|
1098 |
st.session_state['export_file'] = st.session_state['portfolio'].copy()
|
|
|
1099 |
for col in st.session_state['export_file'].columns:
|
1100 |
if col not in excluded_cols:
|
1101 |
st.session_state['export_file'][col] = st.session_state['export_file'][col].map(st.session_state['export_dict'])
|
1102 |
-
if 'export_file' in st.session_state:
|
1103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1104 |
else:
|
1105 |
st.error("No portfolio to download")
|
1106 |
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
|
|
|
|
1111 |
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1146 |
|
1147 |
# Create player summary dataframe
|
1148 |
player_stats = []
|
|
|
985 |
st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
|
986 |
|
987 |
with col2:
|
|
|
988 |
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
989 |
if 'trimming_dict_maxes' not in st.session_state:
|
990 |
st.session_state['trimming_dict_maxes'] = {
|
|
|
1095 |
st.write('Export portfolio updated!')
|
1096 |
else:
|
1097 |
st.session_state['export_file'] = st.session_state['portfolio'].copy()
|
1098 |
+
st.session_state['export_base'] = pd.DataFrame(columns=st.session_state['portfolio'].columns)
|
1099 |
for col in st.session_state['export_file'].columns:
|
1100 |
if col not in excluded_cols:
|
1101 |
st.session_state['export_file'][col] = st.session_state['export_file'][col].map(st.session_state['export_dict'])
|
1102 |
+
if 'export_file' in st.session_state:
|
1103 |
+
download_port, merge_port, blank_export_col = st.columns([1, 1, 8])
|
1104 |
+
with download_port:
|
1105 |
+
st.download_button(label="Download Portfolio", data=st.session_state['export_file'].to_csv(index=False), file_name="portfolio.csv", mime="text/csv")
|
1106 |
+
with merge_port:
|
1107 |
+
with st.button("Add to export"):
|
1108 |
+
st.session_state['export_base'] = pd.concat([st.session_state['export_base'], st.session_state['export_file']])
|
1109 |
+
with blank_export_col:
|
1110 |
+
st.button("Clear export portfolio")
|
1111 |
else:
|
1112 |
st.error("No portfolio to download")
|
1113 |
|
1114 |
+
display_frame_source = st.selectbox("Display:", options=['Portfolio', 'Export Base'], key='display_frame_source')
|
1115 |
+
if display_frame_source == 'Portfolio':
|
1116 |
+
# Add pagination controls below the dataframe
|
1117 |
+
total_rows = len(st.session_state['portfolio'])
|
1118 |
+
rows_per_page = 500
|
1119 |
+
total_pages = (total_rows + rows_per_page - 1) // rows_per_page # Ceiling division
|
1120 |
|
1121 |
+
# Initialize page number in session state if not exists
|
1122 |
+
if 'current_page' not in st.session_state:
|
1123 |
+
st.session_state.current_page = 1
|
1124 |
|
1125 |
+
# Display current page range info and pagination control in a single line
|
1126 |
+
st.write(
|
1127 |
+
f"Showing rows {(st.session_state.current_page - 1) * rows_per_page + 1} "
|
1128 |
+
f"to {min(st.session_state.current_page * rows_per_page, total_rows)} of {total_rows}"
|
1129 |
+
)
|
1130 |
+
|
1131 |
+
# Add page number input
|
1132 |
+
st.session_state.current_page = st.number_input(
|
1133 |
+
f"Page (1-{total_pages})",
|
1134 |
+
min_value=1,
|
1135 |
+
max_value=total_pages,
|
1136 |
+
value=st.session_state.current_page
|
1137 |
+
)
|
1138 |
|
1139 |
+
# Calculate start and end indices for current page
|
1140 |
+
start_idx = (st.session_state.current_page - 1) * rows_per_page
|
1141 |
+
end_idx = min(start_idx + rows_per_page, total_rows)
|
1142 |
|
1143 |
+
# Get the subset of data for the current page
|
1144 |
+
current_page_data = st.session_state['portfolio'].iloc[start_idx:end_idx]
|
1145 |
+
# Display the paginated dataframe first
|
1146 |
+
st.dataframe(
|
1147 |
+
current_page_data.style
|
1148 |
+
.background_gradient(axis=0)
|
1149 |
+
.background_gradient(cmap='RdYlGn')
|
1150 |
+
.background_gradient(cmap='RdYlGn_r', subset=['Finish_percentile', 'Own', 'Dupes'])
|
1151 |
+
.format(freq_format, precision=2),
|
1152 |
+
height=1000,
|
1153 |
+
use_container_width=True
|
1154 |
+
)
|
1155 |
+
elif display_frame_source == 'Export Base':
|
1156 |
+
st.dataframe(
|
1157 |
+
st.session_state['export_base'].style
|
1158 |
+
.background_gradient(axis=0)
|
1159 |
+
.background_gradient(cmap='RdYlGn')
|
1160 |
+
.background_gradient(cmap='RdYlGn_r', subset=['Finish_percentile', 'Own', 'Dupes'])
|
1161 |
+
.format(freq_format, precision=2),
|
1162 |
+
height=1000,
|
1163 |
+
use_container_width=True
|
1164 |
+
)
|
1165 |
|
1166 |
# Create player summary dataframe
|
1167 |
player_stats = []
|