[email protected]
commited on
Commit
Β·
51b84b9
1
Parent(s):
60e5fc6
π Reorganize project structure: Move UI files to dedicated directory
Browse files- Move app.py, config_page.py, optimization_results.py to ui/ directory
- Create proper UI package structure with pages/ and components/ subdirectories
- Update all import paths to reflect new structure
- Add main.py as new project entry point
- Update README.md with new project structure documentation
- Preserve Git history using git mv for all file moves
- Maintain separation of concerns: UI logic in ui/, business logic in src/
- Improve project maintainability and scalability
- README.md +77 -2
- main.py +49 -0
- ui/__init__.py +4 -0
- app.py β ui/app.py +6 -7
- ui/components/__init__.py +4 -0
- ui/pages/__init__.py +4 -0
- config_page.py β ui/pages/config_page.py +2 -2
- optimization_results.py β ui/pages/optimization_results.py +0 -0
README.md
CHANGED
|
@@ -5,10 +5,85 @@ colorFrom: blue
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: "1.28.0"
|
| 8 |
-
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
# Supply Roster Optimization
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: "1.28.0"
|
| 8 |
+
app_file: ui/app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
# Supply Roster Optimization
|
| 13 |
|
| 14 |
+
A comprehensive Streamlit application for optimizing supply roster management using OR-Tools with improved code organization and readability.
|
| 15 |
+
|
| 16 |
+
## π Quick Start
|
| 17 |
+
|
| 18 |
+
### Option 1: Using Main Entry Point (Recommended)
|
| 19 |
+
```bash
|
| 20 |
+
python main.py
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
### Option 2: Direct Streamlit Command
|
| 24 |
+
```bash
|
| 25 |
+
streamlit run ui/app.py
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## π Project Structure
|
| 29 |
+
|
| 30 |
+
```
|
| 31 |
+
SD_roster_real/
|
| 32 |
+
βββ main.py # Main entry point
|
| 33 |
+
βββ README.md
|
| 34 |
+
βββ requirements.txt
|
| 35 |
+
βββ docker-compose.yaml
|
| 36 |
+
βββ setup.py
|
| 37 |
+
β
|
| 38 |
+
βββ src/ # Core business logic
|
| 39 |
+
β βββ config/ # Configuration management
|
| 40 |
+
β β βββ constants.py
|
| 41 |
+
β β βββ optimization_config.py
|
| 42 |
+
β β βββ paths.yaml
|
| 43 |
+
β βββ models/ # Optimization models
|
| 44 |
+
β β βββ optimizer_real.py
|
| 45 |
+
β βββ preprocess/ # Data preprocessing
|
| 46 |
+
β β βββ data_preprocess.py
|
| 47 |
+
β β βββ extract.py
|
| 48 |
+
β β βββ transform.py
|
| 49 |
+
β β βββ ...
|
| 50 |
+
β βββ visualization/ # Chart generation
|
| 51 |
+
β βββ hierarchy_dashboard.py
|
| 52 |
+
β βββ kit_relationships.py
|
| 53 |
+
β
|
| 54 |
+
βββ ui/ # Streamlit UI components
|
| 55 |
+
β βββ app.py # Main Streamlit app
|
| 56 |
+
β βββ pages/ # Page components
|
| 57 |
+
β β βββ config_page.py # Settings page
|
| 58 |
+
β β βββ optimization_results.py # Results page
|
| 59 |
+
β β βββ __init__.py
|
| 60 |
+
β βββ components/ # Reusable UI components
|
| 61 |
+
β β βββ __init__.py
|
| 62 |
+
β βββ __init__.py
|
| 63 |
+
β
|
| 64 |
+
βββ data/ # Data files
|
| 65 |
+
βββ notebook/ # Jupyter notebooks
|
| 66 |
+
βββ venv/ # Virtual environment
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## π§ Features
|
| 70 |
+
|
| 71 |
+
- **Multi-page Interface**: Clean separation of settings, results, and validation
|
| 72 |
+
- **Real-time Optimization**: OR-Tools powered workforce scheduling
|
| 73 |
+
- **Data Validation**: Comprehensive demand data validation and visualization
|
| 74 |
+
- **Cost Analysis**: Detailed cost breakdown and analysis
|
| 75 |
+
- **Hierarchy Management**: Kit dependency tracking and visualization
|
| 76 |
+
- **Flexible Configuration**: Extensive parameter customization
|
| 77 |
+
|
| 78 |
+
## π Usage
|
| 79 |
+
|
| 80 |
+
1. **Settings Page**: Configure optimization parameters, workforce limits, and cost rates
|
| 81 |
+
2. **Optimization Results**: View detailed results with charts and analysis
|
| 82 |
+
3. **Demand Validation**: Validate input data and identify potential issues
|
| 83 |
+
|
| 84 |
+
## π οΈ Development
|
| 85 |
+
|
| 86 |
+
The project follows a clean architecture with:
|
| 87 |
+
- **Separation of Concerns**: UI logic separated from business logic
|
| 88 |
+
- **Modular Design**: Reusable components and clear interfaces
|
| 89 |
+
- **Git-friendly**: Proper file organization with preserved Git history
|
main.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Supply Roster Optimization Tool - Main Entry Point
|
| 4 |
+
Run this file to start the Streamlit application
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
"""Main entry point for the Supply Roster Optimization Tool"""
|
| 13 |
+
|
| 14 |
+
# Get the directory where this script is located
|
| 15 |
+
project_root = os.path.dirname(os.path.abspath(__file__))
|
| 16 |
+
|
| 17 |
+
# Add project root to Python path
|
| 18 |
+
sys.path.insert(0, project_root)
|
| 19 |
+
|
| 20 |
+
# Path to the Streamlit app
|
| 21 |
+
app_path = os.path.join(project_root, 'ui', 'app.py')
|
| 22 |
+
|
| 23 |
+
# Check if the app file exists
|
| 24 |
+
if not os.path.exists(app_path):
|
| 25 |
+
print(f"β Error: Could not find app.py at {app_path}")
|
| 26 |
+
print("Please ensure the project structure is correct.")
|
| 27 |
+
sys.exit(1)
|
| 28 |
+
|
| 29 |
+
print("π Starting Supply Roster Optimization Tool...")
|
| 30 |
+
print(f"π Project root: {project_root}")
|
| 31 |
+
print(f"π― App path: {app_path}")
|
| 32 |
+
print("π Opening in browser...")
|
| 33 |
+
|
| 34 |
+
# Run Streamlit
|
| 35 |
+
try:
|
| 36 |
+
subprocess.run([
|
| 37 |
+
sys.executable, '-m', 'streamlit', 'run', app_path,
|
| 38 |
+
'--server.headless', 'false',
|
| 39 |
+
'--server.address', 'localhost',
|
| 40 |
+
'--server.port', '8501'
|
| 41 |
+
], cwd=project_root)
|
| 42 |
+
except KeyboardInterrupt:
|
| 43 |
+
print("\nπ Application stopped by user")
|
| 44 |
+
except Exception as e:
|
| 45 |
+
print(f"β Error starting application: {e}")
|
| 46 |
+
sys.exit(1)
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
main()
|
ui/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
UI Package for Supply Roster Optimization Tool
|
| 3 |
+
Contains all Streamlit interface components
|
| 4 |
+
"""
|
app.py β ui/app.py
RENAMED
|
@@ -6,9 +6,11 @@ Simplified version with configuration and optimization results
|
|
| 6 |
import streamlit as st
|
| 7 |
import sys
|
| 8 |
import os
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
# Add src directory to path for imports
|
| 11 |
-
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 12 |
|
| 13 |
# Set page config
|
| 14 |
st.set_page_config(
|
|
@@ -32,16 +34,13 @@ page = st.sidebar.selectbox(
|
|
| 32 |
# Main app content
|
| 33 |
if page == "βοΈ Settings":
|
| 34 |
# Import and render the config page
|
| 35 |
-
from config_page import render_config_page
|
| 36 |
-
|
| 37 |
st.title("π¦ Supply Roster Optimization Tool")
|
| 38 |
st.markdown("---")
|
| 39 |
-
|
| 40 |
render_config_page()
|
| 41 |
|
| 42 |
elif page == "π Optimization Results":
|
| 43 |
# Import and render the optimization results page
|
| 44 |
-
|
| 45 |
|
| 46 |
# Check if we have results in session state
|
| 47 |
if 'optimization_results' in st.session_state and st.session_state.optimization_results:
|
|
@@ -64,7 +63,7 @@ elif page == "π Optimization Results":
|
|
| 64 |
elif page == "π Demand Validation":
|
| 65 |
# Import and render the demand validation page
|
| 66 |
try:
|
| 67 |
-
|
| 68 |
|
| 69 |
st.title("π Demand Data Validation")
|
| 70 |
st.markdown("---")
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
import sys
|
| 8 |
import os
|
| 9 |
+
from ui.pages.config_page import render_config_page
|
| 10 |
+
from ui.pages.optimization_results import display_optimization_results
|
| 11 |
+
from src.demand_validation_viz import display_demand_validation
|
| 12 |
# Add src directory to path for imports
|
| 13 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
|
| 14 |
|
| 15 |
# Set page config
|
| 16 |
st.set_page_config(
|
|
|
|
| 34 |
# Main app content
|
| 35 |
if page == "βοΈ Settings":
|
| 36 |
# Import and render the config page
|
|
|
|
|
|
|
| 37 |
st.title("π¦ Supply Roster Optimization Tool")
|
| 38 |
st.markdown("---")
|
|
|
|
| 39 |
render_config_page()
|
| 40 |
|
| 41 |
elif page == "π Optimization Results":
|
| 42 |
# Import and render the optimization results page
|
| 43 |
+
|
| 44 |
|
| 45 |
# Check if we have results in session state
|
| 46 |
if 'optimization_results' in st.session_state and st.session_state.optimization_results:
|
|
|
|
| 63 |
elif page == "π Demand Validation":
|
| 64 |
# Import and render the demand validation page
|
| 65 |
try:
|
| 66 |
+
|
| 67 |
|
| 68 |
st.title("π Demand Data Validation")
|
| 69 |
st.markdown("---")
|
ui/components/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
UI Components Package
|
| 3 |
+
Contains reusable UI components for the Streamlit app
|
| 4 |
+
"""
|
ui/pages/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
UI Pages Package
|
| 3 |
+
Contains individual page components for the Streamlit app
|
| 4 |
+
"""
|
config_page.py β ui/pages/config_page.py
RENAMED
|
@@ -11,7 +11,7 @@ from src.config import optimization_config
|
|
| 11 |
from src.config.constants import ShiftType, LineType
|
| 12 |
|
| 13 |
# Add src directory to path for imports
|
| 14 |
-
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
|
| 15 |
|
| 16 |
def render_config_page():
|
| 17 |
"""Render the configuration page with all user input controls"""
|
|
@@ -1174,5 +1174,5 @@ def check_critical_data_issues():
|
|
| 1174 |
|
| 1175 |
def display_optimization_results(results):
|
| 1176 |
"""Import and display optimization results"""
|
| 1177 |
-
from optimization_results import display_optimization_results as display_results
|
| 1178 |
display_results(results)
|
|
|
|
| 11 |
from src.config.constants import ShiftType, LineType
|
| 12 |
|
| 13 |
# Add src directory to path for imports
|
| 14 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
|
| 15 |
|
| 16 |
def render_config_page():
|
| 17 |
"""Render the configuration page with all user input controls"""
|
|
|
|
| 1174 |
|
| 1175 |
def display_optimization_results(results):
|
| 1176 |
"""Import and display optimization results"""
|
| 1177 |
+
from ui.pages.optimization_results import display_optimization_results as display_results
|
| 1178 |
display_results(results)
|
optimization_results.py β ui/pages/optimization_results.py
RENAMED
|
File without changes
|