James McCool commited on
Commit
7a401f2
·
1 Parent(s): 2e2f822

Enhance export options in app.py: introduce a selection for 'Simple' or 'Advanced' download types, allowing users to choose between direct portfolio export or customized stack adjustments, improving flexibility and user experience during data export.

Browse files
Files changed (1) hide show
  1. app.py +63 -59
app.py CHANGED
@@ -878,67 +878,71 @@ with tab3:
878
  st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
879
  with st.expander("Download options"):
880
  if stack_dict is not None:
881
- with st.form(key='stack_form'):
882
- st.subheader("Stack Count Adjustments")
883
- st.info("This allows you to fine tune the stacks that you wish to export. If you want to make sure you don't export any of a specific stack you can 0 it out.")
884
- # Create a container for stack value inputs
885
- sort_container = st.container()
886
- with sort_container:
887
- sort_var = st.selectbox("Sort export portfolio by:", options=['median', 'Lineup Edge', 'Own'])
888
-
889
- # Get unique stack values
890
- unique_stacks = sorted(list(set(stack_dict.values())))
891
-
892
- # Create a dictionary to store stack multipliers
893
- if 'stack_multipliers' not in st.session_state:
894
- st.session_state.stack_multipliers = {stack: 0.0 for stack in unique_stacks}
895
-
896
- # Create columns for the stack inputs
897
- num_cols = 6 # Number of columns to display
898
- for i in range(0, len(unique_stacks), num_cols):
899
- cols = st.columns(num_cols)
900
- for j, stack in enumerate(unique_stacks[i:i+num_cols]):
901
- with cols[j]:
902
- # Create a unique key for each number input
903
- key = f"stack_count_{stack}"
904
- # Get the current count of this stack in the portfolio
905
- current_stack_count = len(st.session_state['portfolio'][st.session_state['portfolio']['Stack'] == stack])
906
- # Create number input with current value and max value based on actual count
907
- st.session_state.stack_multipliers[stack] = st.number_input(
908
- f"{stack} count",
909
- min_value=0.0,
910
- max_value=float(current_stack_count),
911
- value=0.0,
912
- step=1.0,
913
- key=key
914
- )
915
-
916
- portfolio_copy = st.session_state['portfolio'].copy()
917
-
918
- submitted = st.form_submit_button("Submit")
919
- if submitted:
920
- # Create a list to store selected rows
921
- selected_rows = []
922
 
923
- # For each stack, select the top N rows based on the count value
924
- for stack in unique_stacks:
925
- if stack in st.session_state.stack_multipliers:
926
- count = int(st.session_state.stack_multipliers[stack])
927
- # Get rows for this stack
928
- stack_rows = portfolio_copy[portfolio_copy['Stack'] == stack]
929
- # Sort by median and take top N rows
930
- top_rows = stack_rows.nlargest(count, sort_var)
931
- selected_rows.append(top_rows)
932
-
933
- # Combine all selected rows
934
- portfolio_concat = pd.concat(selected_rows)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935
 
936
- # Update export_file with filtered data
937
- st.session_state['export_file'] = portfolio_concat.copy()
938
- for col in st.session_state['export_file'].columns:
939
- if col not in excluded_cols:
940
- st.session_state['export_file'][col] = st.session_state['export_file'][col].map(st.session_state['export_dict'])
941
- st.write('Export portfolio updated!')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
942
  else:
943
  st.session_state['export_file'] = st.session_state['portfolio'].copy()
944
  if 'export_file' in st.session_state:
 
878
  st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
879
  with st.expander("Download options"):
880
  if stack_dict is not None:
881
+ download_type = st.selectbox("Simple or Advanced Download?", options=['Simple', 'Advanced'], key='download_choice')
882
+ if download_type == 'Simple':
883
+ st.session_state['export_file'] = st.session_state['portfolio'].copy()
884
+ else:
885
+ with st.form(key='stack_form'):
886
+ st.subheader("Stack Count Adjustments")
887
+ st.info("This allows you to fine tune the stacks that you wish to export. If you want to make sure you don't export any of a specific stack you can 0 it out.")
888
+ # Create a container for stack value inputs
889
+ sort_container = st.container()
890
+ with sort_container:
891
+ sort_var = st.selectbox("Sort export portfolio by:", options=['median', 'Lineup Edge', 'Own'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
892
 
893
+ # Get unique stack values
894
+ unique_stacks = sorted(list(set(stack_dict.values())))
895
+
896
+ # Create a dictionary to store stack multipliers
897
+ if 'stack_multipliers' not in st.session_state:
898
+ st.session_state.stack_multipliers = {stack: 0.0 for stack in unique_stacks}
899
+
900
+ # Create columns for the stack inputs
901
+ num_cols = 6 # Number of columns to display
902
+ for i in range(0, len(unique_stacks), num_cols):
903
+ cols = st.columns(num_cols)
904
+ for j, stack in enumerate(unique_stacks[i:i+num_cols]):
905
+ with cols[j]:
906
+ # Create a unique key for each number input
907
+ key = f"stack_count_{stack}"
908
+ # Get the current count of this stack in the portfolio
909
+ current_stack_count = len(st.session_state['portfolio'][st.session_state['portfolio']['Stack'] == stack])
910
+ # Create number input with current value and max value based on actual count
911
+ st.session_state.stack_multipliers[stack] = st.number_input(
912
+ f"{stack} count",
913
+ min_value=0.0,
914
+ max_value=float(current_stack_count),
915
+ value=0.0,
916
+ step=1.0,
917
+ key=key
918
+ )
919
 
920
+ portfolio_copy = st.session_state['portfolio'].copy()
921
+
922
+ submitted = st.form_submit_button("Submit")
923
+ if submitted:
924
+ # Create a list to store selected rows
925
+ selected_rows = []
926
+
927
+ # For each stack, select the top N rows based on the count value
928
+ for stack in unique_stacks:
929
+ if stack in st.session_state.stack_multipliers:
930
+ count = int(st.session_state.stack_multipliers[stack])
931
+ # Get rows for this stack
932
+ stack_rows = portfolio_copy[portfolio_copy['Stack'] == stack]
933
+ # Sort by median and take top N rows
934
+ top_rows = stack_rows.nlargest(count, sort_var)
935
+ selected_rows.append(top_rows)
936
+
937
+ # Combine all selected rows
938
+ portfolio_concat = pd.concat(selected_rows)
939
+
940
+ # Update export_file with filtered data
941
+ st.session_state['export_file'] = portfolio_concat.copy()
942
+ for col in st.session_state['export_file'].columns:
943
+ if col not in excluded_cols:
944
+ st.session_state['export_file'][col] = st.session_state['export_file'][col].map(st.session_state['export_dict'])
945
+ st.write('Export portfolio updated!')
946
  else:
947
  st.session_state['export_file'] = st.session_state['portfolio'].copy()
948
  if 'export_file' in st.session_state: