RoyAalekh commited on
Commit
db7ca89
·
1 Parent(s): cecefdc

feat: Add interactive setup controls to dashboard UI

Browse files

Users can now run prerequisite commands directly from the dashboard:
- Run EDA pipeline button (interactive subprocess execution)
- Generate test cases button with configurable count
- Real-time status refresh button
- Spinner and progress indicators during execution
- Error handling with expandable details
- Success messages with automatic page refresh
- Fallback manual command instructions

Benefits:
- No need to switch to terminal for setup
- Better UX with guided setup workflow
- Clear status indicators show what's ready
- All setup can be done from one place

Files changed (1) hide show
  1. scheduler/dashboard/app.py +101 -7
scheduler/dashboard/app.py CHANGED
@@ -7,6 +7,8 @@ Or directly: streamlit run scheduler/dashboard/app.py
7
 
8
  from __future__ import annotations
9
 
 
 
10
  import streamlit as st
11
 
12
  from scheduler.dashboard.utils import get_data_status
@@ -39,7 +41,12 @@ Navigate using the sidebar to access different sections.
39
  """)
40
 
41
  # System status
42
- st.markdown("### System Status")
 
 
 
 
 
43
 
44
  data_status = get_data_status()
45
 
@@ -65,6 +72,88 @@ with col4:
65
  color = "green" if data_status["eda_figures"] else "red"
66
  st.markdown(f":{color}[{status}] **EDA Figures**")
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  st.markdown("---")
69
 
70
  # Quick start guide
@@ -90,15 +179,20 @@ with st.expander("How to use this dashboard"):
90
  - Visualize Q-table and action distributions
91
  """)
92
 
93
- with st.expander("Prerequisites"):
94
  st.markdown("""
95
- Before using the dashboard, ensure you have:
 
 
 
96
 
97
- 1. **Run EDA pipeline**: `uv run court-scheduler eda`
98
- 2. **Generate test cases** (optional): `uv run court-scheduler generate`
99
- 3. **Parameters extracted**: Check that `configs/parameters/` exists
 
 
100
 
101
- If any system status shows above, run the corresponding command first.
102
  """)
103
 
104
  # Footer
 
7
 
8
  from __future__ import annotations
9
 
10
+ from pathlib import Path
11
+
12
  import streamlit as st
13
 
14
  from scheduler.dashboard.utils import get_data_status
 
41
  """)
42
 
43
  # System status
44
+ status_header_col1, status_header_col2 = st.columns([3, 1])
45
+ with status_header_col1:
46
+ st.markdown("### System Status")
47
+ with status_header_col2:
48
+ if st.button("🔄 Refresh Status", use_container_width=True):
49
+ st.rerun()
50
 
51
  data_status = get_data_status()
52
 
 
72
  color = "green" if data_status["eda_figures"] else "red"
73
  st.markdown(f":{color}[{status}] **EDA Figures**")
74
 
75
+ # Setup Controls
76
+ if not all(data_status.values()):
77
+ st.markdown("---")
78
+ st.markdown("### Setup Required")
79
+ st.info("Some prerequisites are missing. Use the controls below to set up the system.")
80
+
81
+ setup_col1, setup_col2 = st.columns(2)
82
+
83
+ with setup_col1:
84
+ st.markdown("#### EDA Pipeline")
85
+ if not data_status["cleaned_data"] or not data_status["parameters"]:
86
+ st.warning("EDA pipeline needs to be run to generate cleaned data and parameters")
87
+
88
+ if st.button("Run EDA Pipeline", type="primary", use_container_width=True):
89
+ import subprocess
90
+ import sys
91
+
92
+ with st.spinner("Running EDA pipeline... This may take a few minutes."):
93
+ try:
94
+ result = subprocess.run(
95
+ [sys.executable, "-m", "uv", "run", "court-scheduler", "eda"],
96
+ capture_output=True,
97
+ text=True,
98
+ cwd=str(Path.cwd()),
99
+ )
100
+
101
+ if result.returncode == 0:
102
+ st.success("EDA pipeline completed successfully!")
103
+ st.rerun()
104
+ else:
105
+ st.error(f"EDA pipeline failed with error code {result.returncode}")
106
+ with st.expander("Show error details"):
107
+ st.code(result.stderr, language="text")
108
+ except Exception as e:
109
+ st.error(f"Error running EDA pipeline: {e}")
110
+ else:
111
+ st.success("EDA pipeline already complete")
112
+
113
+ with setup_col2:
114
+ st.markdown("#### Test Case Generation")
115
+ if not data_status["generated_cases"]:
116
+ st.info("Optional: Generate synthetic test cases for classifier testing")
117
+
118
+ n_cases = st.number_input("Number of cases to generate", min_value=100, max_value=50000, value=1000, step=100)
119
+
120
+ if st.button("Generate Test Cases", use_container_width=True):
121
+ import subprocess
122
+ import sys
123
+
124
+ with st.spinner(f"Generating {n_cases} test cases..."):
125
+ try:
126
+ result = subprocess.run(
127
+ [sys.executable, "-m", "uv", "run", "court-scheduler", "generate", "--cases", str(n_cases)],
128
+ capture_output=True,
129
+ text=True,
130
+ cwd=str(Path.cwd()),
131
+ )
132
+
133
+ if result.returncode == 0:
134
+ st.success(f"Generated {n_cases} test cases successfully!")
135
+ st.rerun()
136
+ else:
137
+ st.error(f"Generation failed with error code {result.returncode}")
138
+ with st.expander("Show error details"):
139
+ st.code(result.stderr, language="text")
140
+ except Exception as e:
141
+ st.error(f"Error generating test cases: {e}")
142
+ else:
143
+ st.success("Test cases already generated")
144
+
145
+ st.markdown("#### Manual Setup")
146
+ with st.expander("Run commands manually (if buttons don't work)"):
147
+ st.code("""
148
+ # Run EDA pipeline
149
+ uv run court-scheduler eda
150
+
151
+ # Generate test cases (optional)
152
+ uv run court-scheduler generate --cases 1000
153
+ """, language="bash")
154
+ else:
155
+ st.success("All prerequisites are ready! You can use all dashboard features.")
156
+
157
  st.markdown("---")
158
 
159
  # Quick start guide
 
179
  - Visualize Q-table and action distributions
180
  """)
181
 
182
+ with st.expander("Prerequisites & Setup"):
183
  st.markdown("""
184
+ The dashboard requires some initial setup:
185
+
186
+ 1. **EDA Pipeline**: Processes raw data and extracts parameters
187
+ 2. **Test Cases** (optional): Generates synthetic cases for testing
188
 
189
+ **How to set up**:
190
+ - Use the interactive buttons in the "Setup Required" section above (if shown)
191
+ - Or run commands manually:
192
+ - `uv run court-scheduler eda`
193
+ - `uv run court-scheduler generate` (optional)
194
 
195
+ The system status indicators at the top show what's ready.
196
  """)
197
 
198
  # Footer