HaLim commited on
Commit Β·
ac5a7da
1
Parent(s): 4003592
configuration page
Browse filesFiles changed (2)
- app.pyAdded+46
- config_page.pyAdded+379
12345678910111213141516171819202122232425262728293031323334353637383940414243444546"""Supply Roster Optimization Tool - Streamlit AppSimplified version with configuration and optimization results"""
import streamlit as stimport sysimport os
# Add src directory to path for importssys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
# Set page configst.set_page_config( page_title="Supply Roster Optimization Tool", page_icon="π¦", layout="wide", initial_sidebar_state="expanded")
# Sidebar navigationst.sidebar.title("π¦ Supply Roster Tool")st.sidebar.markdown("---")
# Navigationpage = st.sidebar.selectbox( "Navigate to:", ["βοΈ Configuration", "π Optimization Results"], index=0)
# Main app contentif page == "βοΈ Configuration": # Import and render the config page from config_page import render_config_page st.title("π¦ Supply Roster Optimization Tool") st.markdown("---") render_config_page()
elif page == "π Optimization Results": # Import and render the optimization page from optimization_page import render_optimization_page render_optimization_page()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379"""Configuration Page for Supply Roster Optimization ToolContains all user input controls with default values from config"""
import streamlit as stimport datetimeimport sysimport os
# Add src directory to path for importssys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
def render_config_page(): """Render the configuration page with all user input controls""" st.title("βοΈ Configuration") st.markdown("---") st.markdown("Configure optimization parameters and constraints for roster planning.") # Initialize session state for all configuration values initialize_session_state() # Create tabs for better organization tab1, tab2, tab3, tab4 = st.tabs(["π
Schedule", "π₯ Workforce", "π Operations", "π° Cost"]) with tab1: render_schedule_config() with tab2: render_workforce_config() with tab3: render_operations_config() with tab4: render_cost_config() # Save configuration button st.markdown("---") col1, col2, col3 = st.columns([1, 1, 1]) with col2: if st.button("πΎ Save Configuration", type="primary", use_container_width=True): save_configuration() st.success("β
Configuration saved successfully!")
def initialize_session_state(): """Initialize session state with default values from config""" # Default values based on optimization_config.py defaults = { # Schedule configuration 'start_date': datetime.date(2025, 7, 7), 'end_date': datetime.date(2025, 7, 11), 'schedule_type': 'daily', # Shift configuration 'evening_shift_mode': 'normal', 'evening_shift_threshold': 0.9, # Fixed staff configuration 'fixed_staff_mode': 'priority', # Payment configuration 'payment_mode_shift_1': 'bulk', 'payment_mode_shift_2': 'bulk', 'payment_mode_shift_3': 'partial', # Workforce limits 'max_unicef_per_day': 8, 'max_humanizer_per_day': 10, # Operations 'max_parallel_workers_long_line': 15, 'max_parallel_workers_mini_load': 15, 'max_hour_per_person_per_day': 14, # Shift hours 'max_hours_shift_1': 7.5, 'max_hours_shift_2': 7.5, 'max_hours_shift_3': 5.0, # Line counts (will be loaded from data) 'line_count_long_line': 6, 'line_count_mini_load': 7, } # Initialize session state with defaults if not already set for key, value in defaults.items(): if key not in st.session_state: st.session_state[key] = value
def render_schedule_config(): """Render schedule configuration section""" st.header("π
Schedule Configuration") col1, col2 = st.columns(2) with col1: st.session_state.start_date = st.date_input( "Start Date", value=st.session_state.start_date, help="Start date for the optimization period" ) with col2: st.session_state.end_date = st.date_input( "End Date", value=st.session_state.end_date, help="End date for the optimization period" ) # Validate date range if st.session_state.start_date > st.session_state.end_date: st.error("β οΈ Start date must be before or equal to end date!") # Schedule type st.session_state.schedule_type = st.selectbox( "Schedule Type", options=['daily', 'weekly'], index=0 if st.session_state.schedule_type == 'daily' else 1, help="Choose between daily or weekly scheduling" ) # Evening shift configuration st.subheader("π Evening Shift Configuration") st.session_state.evening_shift_mode = st.selectbox( "Evening Shift Mode", options=['normal', 'activate_evening', 'always_available'], index=['normal', 'activate_evening', 'always_available'].index(st.session_state.evening_shift_mode), help=""" - **Normal**: Only regular shift (1) and overtime shift (3) - **Activate Evening**: Allow evening shift (2) when demand is high - **Always Available**: Evening shift always available as option """ ) if st.session_state.evening_shift_mode == 'activate_evening': st.session_state.evening_shift_threshold = st.slider( "Evening Shift Activation Threshold", min_value=0.1, max_value=1.0, value=st.session_state.evening_shift_threshold, step=0.1, help="Activate evening shift if regular+overtime capacity < threshold of demand" )
def render_workforce_config(): """Render workforce configuration section""" st.header("π₯ Workforce Configuration") # Fixed staff constraint mode st.session_state.fixed_staff_mode = st.selectbox( "Fixed Staff Constraint Mode", options=['mandatory', 'available', 'priority', 'none'], index=['mandatory', 'available', 'priority', 'none'].index(st.session_state.fixed_staff_mode), help=""" - **Mandatory**: Forces all fixed staff to work full hours every day - **Available**: Staff available up to limits but not forced - **Priority**: Fixed staff used first, then temporary staff (recommended) - **None**: Purely demand-driven scheduling """ ) # Workforce limits st.subheader("π¨βπΌ Daily Workforce Limits") col1, col2 = st.columns(2) with col1: st.session_state.max_unicef_per_day = st.number_input( "Max UNICEF Fixed Term per Day", min_value=1, max_value=50, value=st.session_state.max_unicef_per_day, help="Maximum number of UNICEF fixed term employees per day" ) with col2: st.session_state.max_humanizer_per_day = st.number_input( "Max Humanizer per Day", min_value=1, max_value=50, value=st.session_state.max_humanizer_per_day, help="Maximum number of Humanizer employees per day" ) # Working hours configuration st.subheader("β° Working Hours Configuration") st.session_state.max_hour_per_person_per_day = st.number_input( "Max Hours per Person per Day", min_value=1, max_value=24, value=st.session_state.max_hour_per_person_per_day, help="Legal maximum working hours per person per day" ) col1, col2, col3 = st.columns(3) with col1: st.session_state.max_hours_shift_1 = st.number_input( "Max Hours - Shift 1 (Regular)", min_value=1.0, max_value=12.0, value=st.session_state.max_hours_shift_1, step=0.5, help="Maximum hours per person for regular shift" ) with col2: st.session_state.max_hours_shift_2 = st.number_input( "Max Hours - Shift 2 (Evening)", min_value=1.0, max_value=12.0, value=st.session_state.max_hours_shift_2, step=0.5, help="Maximum hours per person for evening shift" ) with col3: st.session_state.max_hours_shift_3 = st.number_input( "Max Hours - Shift 3 (Overtime)", min_value=1.0, max_value=12.0, value=st.session_state.max_hours_shift_3, step=0.5, help="Maximum hours per person for overtime shift" )
def render_operations_config(): """Render operations configuration section""" st.header("π Operations Configuration") # Line configuration st.subheader("π¦ Production Line Configuration") col1, col2 = st.columns(2) with col1: st.session_state.line_count_long_line = st.number_input( "Number of Long Lines", min_value=1, max_value=20, value=st.session_state.line_count_long_line, help="Number of long line production lines available" ) st.session_state.max_parallel_workers_long_line = st.number_input( "Max Workers per Long Line", min_value=1, max_value=50, value=st.session_state.max_parallel_workers_long_line, help="Maximum number of workers that can work simultaneously on a long line" ) with col2: st.session_state.line_count_mini_load = st.number_input( "Number of Mini Load Lines", min_value=1, max_value=20, value=st.session_state.line_count_mini_load, help="Number of mini load production lines available" ) st.session_state.max_parallel_workers_mini_load = st.number_input( "Max Workers per Mini Load Line", min_value=1, max_value=50, value=st.session_state.max_parallel_workers_mini_load, help="Maximum number of workers that can work simultaneously on a mini load line" )
def render_cost_config(): """Render cost configuration section""" st.header("π° Cost Configuration") # Payment mode configuration st.subheader("π³ Payment Mode Configuration") st.markdown(""" **Payment Modes:** - **Bulk**: If employee works any hours in shift, pay for full shift hours - **Partial**: Pay only for actual hours worked """) col1, col2, col3 = st.columns(3) with col1: st.session_state.payment_mode_shift_1 = st.selectbox( "Shift 1 (Regular) Payment", options=['bulk', 'partial'], index=0 if st.session_state.payment_mode_shift_1 == 'bulk' else 1, help="Payment mode for regular shift" ) with col2: st.session_state.payment_mode_shift_2 = st.selectbox( "Shift 2 (Evening) Payment", options=['bulk', 'partial'], index=0 if st.session_state.payment_mode_shift_2 == 'bulk' else 1, help="Payment mode for evening shift" ) with col3: st.session_state.payment_mode_shift_3 = st.selectbox( "Shift 3 (Overtime) Payment", options=['bulk', 'partial'], index=0 if st.session_state.payment_mode_shift_3 == 'bulk' else 1, help="Payment mode for overtime shift" ) # Cost information display (read-only from config) st.subheader("π΅ Hourly Rates (From Configuration)") # Display current cost configuration cost_info = """ **UNICEF Fixed Term:** - Shift 1 (Regular): β¬43.27/hour - Shift 2 (Evening): β¬43.27/hour - Shift 3 (Overtime): β¬64.91/hour **Humanizer:** - Shift 1 (Regular): β¬27.94/hour - Shift 2 (Evening): β¬27.94/hour - Shift 3 (Overtime): β¬41.91/hour """ st.info(cost_info)
def save_configuration(): """Save current configuration to session state and potentially to file""" # Create configuration dictionary config = { 'date_range': { 'start_date': st.session_state.start_date, 'end_date': st.session_state.end_date, }, 'schedule_type': st.session_state.schedule_type, 'evening_shift_mode': st.session_state.evening_shift_mode, 'evening_shift_threshold': st.session_state.evening_shift_threshold, 'fixed_staff_mode': st.session_state.fixed_staff_mode, 'payment_mode_config': { 1: st.session_state.payment_mode_shift_1, 2: st.session_state.payment_mode_shift_2, 3: st.session_state.payment_mode_shift_3, }, 'workforce_limits': { 'max_unicef_per_day': st.session_state.max_unicef_per_day, 'max_humanizer_per_day': st.session_state.max_humanizer_per_day, }, 'working_hours': { 'max_hour_per_person_per_day': st.session_state.max_hour_per_person_per_day, 'max_hours_per_shift': { 1: st.session_state.max_hours_shift_1, 2: st.session_state.max_hours_shift_2, 3: st.session_state.max_hours_shift_3, } }, 'operations': { 'line_counts': { 'long_line': st.session_state.line_count_long_line, 'mini_load': st.session_state.line_count_mini_load, }, 'max_parallel_workers': { 6: st.session_state.max_parallel_workers_long_line, # long line id 7: st.session_state.max_parallel_workers_mini_load, # mini load id } } } # Store in session state for other pages to access st.session_state.optimization_config = config # Display configuration summary with st.expander("π Configuration Summary", expanded=False): st.json(config)app.pyAdded+46
config_page.pyAdded+379