HaLim
add streamlit and clean the optimizer
46e0ea9
raw
history blame
7.16 kB
import streamlit as st
# Page configuration - MUST be first Streamlit command
st.set_page_config(
page_title="SD Roster Tool - Home",
page_icon="🏠",
layout="wide",
initial_sidebar_state="expanded"
)
# Now import everything else
import pandas as pd
import sys
import os
from datetime import datetime
# Add src to path for imports
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
# Custom CSS for better styling
st.markdown("""
<style>
.main-header {
font-size: 3rem;
font-weight: bold;
color: #1f77b4;
margin-bottom: 2rem;
text-align: center;
}
.section-header {
font-size: 1.8rem;
font-weight: bold;
color: #2c3e50;
margin: 1.5rem 0;
}
.feature-card {
background-color: #ffffff;
padding: 1.5rem;
border-radius: 0.8rem;
border-left: 5px solid #1f77b4;
margin-bottom: 1.5rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.15);
color: #2c3e50;
border: 1px solid #e9ecef;
}
.feature-card h3 {
color: #1f77b4;
margin-top: 0;
}
.feature-card p {
color: #2c3e50;
}
.feature-card ul {
color: #2c3e50;
}
.navigation-button {
width: 100%;
height: 80px;
font-size: 1.2rem;
margin: 10px 0;
}
</style>
""", unsafe_allow_html=True)
# Initialize session state for shared variables
if 'data_path' not in st.session_state:
st.session_state.data_path = "data/my_roster_data"
if 'target_date' not in st.session_state:
st.session_state.target_date = ""
# Title
st.markdown('<h1 class="main-header">🏠 SD Roster Optimization Tool</h1>', unsafe_allow_html=True)
# Introduction section
col1, col2 = st.columns([2, 1])
with col1:
st.markdown("""
## πŸ“‹ Welcome to the Supply Chain Roster Optimization Tool
This comprehensive tool helps you optimize workforce allocation and production scheduling
using advanced mathematical optimization techniques. Navigate through the different sections
to analyze your data and run optimizations.
### πŸ”§ Key Features:
- **Advanced Optimization Engine**: Built on Google OR-Tools for mixed-integer programming
- **Multi-constraint Support**: Handle complex business rules and staffing requirements
- **Real-time Data Integration**: Work with your existing CSV data files
- **Interactive Visualizations**: Rich charts and analytics for decision making
- **Flexible Configuration**: Adjust parameters for different business scenarios
""")
with col2:
st.markdown("### πŸš€ Quick Start")
# Navigation buttons
if st.button("πŸ“Š View Dataset Metadata", key="nav_metadata", help="Explore your data overview"):
st.switch_page("pages/1_πŸ“Š_Dataset_Metadata.py")
if st.button("🎯 Run Optimization", key="nav_optimization", help="Configure and run optimization"):
st.switch_page("pages/2_🎯_Optimization.py")
# Global settings section
st.markdown("---")
st.markdown('<h2 class="section-header">🌐 Global Settings</h2>', unsafe_allow_html=True)
col_set1, col_set2 = st.columns(2)
with col_set1:
st.markdown("### πŸ“ Data Configuration")
new_data_path = st.text_input(
"Data Path",
value=st.session_state.data_path,
help="Path to your CSV data files. This setting is shared across all pages."
)
if new_data_path != st.session_state.data_path:
st.session_state.data_path = new_data_path
st.success("βœ… Data path updated globally!")
st.info(f"**Current data path:** `{st.session_state.data_path}`")
with col_set2:
st.markdown("### πŸ“… Date Configuration")
# Try to load available dates
try:
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
import src.etl.transform as transform
date_ranges = transform.get_date_ranges()
if date_ranges:
date_range_options = [""] + [f"{start.strftime('%Y-%m-%d')} to {end.strftime('%Y-%m-%d')}" for start, end in date_ranges]
selected_range_str = st.selectbox(
"Available Date Ranges:",
options=date_range_options,
help="Select from available date ranges in your data"
)
if selected_range_str:
selected_index = date_range_options.index(selected_range_str) - 1
start_date, end_date = date_ranges[selected_index]
st.session_state.date_range = (start_date, end_date)
st.success(f"βœ… Selected: {start_date} to {end_date}")
except Exception as e:
st.warning(f"Could not load date ranges: {e}")
st.info("Date ranges will be available when data is properly configured.")
# Overview sections
st.markdown("---")
col_info1, col_info2, col_info3 = st.columns(3)
with col_info1:
st.markdown("""
<div class="feature-card">
<h3>πŸ“Š Dataset Metadata</h3>
<p>Comprehensive overview of your data including:</p>
<ul>
<li>Demand analysis and forecasting</li>
<li>Employee availability and costs</li>
<li>Production line capacities</li>
<li>Historical performance data</li>
</ul>
</div>
""", unsafe_allow_html=True)
with col_info2:
st.markdown("""
<div class="feature-card">
<h3>🎯 Optimization Engine</h3>
<p>Advanced optimization features:</p>
<ul>
<li>Multi-objective optimization</li>
<li>Constraint satisfaction</li>
<li>Scenario analysis</li>
<li>Cost minimization</li>
</ul>
</div>
""", unsafe_allow_html=True)
with col_info3:
st.markdown("""
<div class="feature-card">
<h3>πŸ“ˆ Analytics & Reports</h3>
<p>Rich visualization and reporting:</p>
<ul>
<li>Interactive dashboards</li>
<li>Cost analysis charts</li>
<li>Performance metrics</li>
<li>Export capabilities</li>
</ul>
</div>
""", unsafe_allow_html=True)
# System status
st.markdown("---")
st.markdown("### πŸ” System Status")
col_status1, col_status2, col_status3, col_status4 = st.columns(4)
# Check system components
try:
import ortools
ortools_status = "βœ… Available"
except:
ortools_status = "❌ Not installed"
try:
import plotly
plotly_status = "βœ… Available"
except:
plotly_status = "❌ Not installed"
data_status = "βœ… Configured" if os.path.exists(st.session_state.data_path) else "⚠️ Path not found"
with col_status1:
st.metric("OR-Tools", ortools_status)
with col_status2:
st.metric("Plotly", plotly_status)
with col_status3:
st.metric("Data Path", data_status)
with col_status4:
st.metric("Session State", "βœ… Active")
# Footer
st.markdown("---")
st.markdown("""
<div style='text-align: center; color: gray; padding: 2rem;'>
<small>SD Roster Optimization Tool | Built with Streamlit & OR-Tools | Version 1.0</small>
</div>
""", unsafe_allow_html=True)