Skip to content

Commit bf73a7d

Browse files
committed
refactor: 🔥 Remove avg. cycle time from dahsboard
1 parent c2a7b47 commit bf73a7d

1 file changed

Lines changed: 9 additions & 40 deletions

File tree

popupsim/frontend/dashboard.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,22 @@ def _render_comparison_view(base_path: Path, selected_scenarios: list[str]) -> N
161161
metrics = data.get('metrics', {})
162162
wagon_journey = data.get('wagon_journey')
163163

164-
# Calculate cycle time
165-
avg_cycle_time = 0
164+
# Get total wagon count
165+
total_wagons = 0
166166
if wagon_journey is not None and not wagon_journey.empty:
167-
completed = wagon_journey[wagon_journey['status'] == 'COMPLETED']
168-
if not completed.empty:
169-
cycle_times = completed.groupby('wagon_id')['timestamp'].agg(['min', 'max'])
170-
cycle_times['duration'] = cycle_times['max'] - cycle_times['min']
171-
avg_cycle_time = cycle_times['duration'].mean()
167+
total_wagons = wagon_journey['wagon_id'].nunique()
168+
169+
# Calculate rejection percentage based on total wagons
170+
rejection_pct = (metrics.get('wagons_rejected', 0) / total_wagons * 100) if total_wagons > 0 else 0
172171

173172
comparison_data.append(
174173
{
175174
'Scenario': scenario_name,
176175
'Trains': metrics.get('trains_arrived', 0),
177-
'Wagons': metrics.get('wagons_arrived', 0),
176+
'Wagons': total_wagons,
178177
'Rejected': metrics.get('wagons_rejected', 0),
179-
'Rejection %': f'{(metrics.get("wagons_rejected", 0) / metrics.get("wagons_arrived", 1) * 100):.1f}',
178+
'Rejection %': f'{rejection_pct:.1f}',
180179
'Retrofits': metrics.get('retrofits_completed', 0),
181-
'Avg Cycle Time (min)': f'{avg_cycle_time:.1f}',
182180
}
183181
)
184182

@@ -190,7 +188,7 @@ def _render_comparison_view(base_path: Path, selected_scenarios: list[str]) -> N
190188
baseline = comparison_df.iloc[0]
191189
compare = comparison_df.iloc[1]
192190

193-
col1, col2, col3, col4 = st.columns(4)
191+
col1, col2, col3 = st.columns(3)
194192
with col1:
195193
delta_retrofits = compare['Retrofits'] - baseline['Retrofits']
196194
delta_pct = (delta_retrofits / baseline['Retrofits'] * 100) if baseline['Retrofits'] > 0 else 0
@@ -206,12 +204,6 @@ def _render_comparison_view(base_path: Path, selected_scenarios: list[str]) -> N
206204
delta_rej_rate = compare_rej_rate - baseline_rej_rate
207205
st.metric('Rejection Rate', f'{compare_rej_rate:.1f}%', f'{delta_rej_rate:+.1f}%', delta_color='inverse')
208206

209-
with col4:
210-
baseline_cycle = float(baseline['Avg Cycle Time (min)'])
211-
compare_cycle = float(compare['Avg Cycle Time (min)'])
212-
delta_cycle = compare_cycle - baseline_cycle
213-
st.metric('Avg Cycle Time', f'{compare_cycle:.1f} min', f'{delta_cycle:+.1f} min', delta_color='inverse')
214-
215207
st.dataframe(comparison_df, use_container_width=True, hide_index=True)
216208

217209
if st.button('📥 Export KPI Comparison CSV'):
@@ -295,29 +287,6 @@ def _render_comparison_view(base_path: Path, selected_scenarios: list[str]) -> N
295287
},
296288
)
297289

298-
with col2:
299-
cycle_times = [float(x) for x in comparison_df['Avg Cycle Time (min)']]
300-
fig = go.Figure(
301-
data=[
302-
go.Bar(
303-
x=comparison_df['Scenario'],
304-
y=cycle_times,
305-
marker_color='#9b59b6',
306-
text=[f'{x:.1f}' for x in cycle_times],
307-
textposition='auto',
308-
)
309-
]
310-
)
311-
fig.update_layout(title='Average Cycle Time', xaxis_title='Scenario', yaxis_title='Minutes', height=300)
312-
st.plotly_chart(
313-
fig,
314-
use_container_width=True,
315-
config={
316-
'displayModeBar': True,
317-
'toImageButtonOptions': {'format': 'png', 'filename': 'comparison_cycle_time'},
318-
},
319-
)
320-
321290
st.markdown('---')
322291

323292
# Workshop comparison

0 commit comments

Comments
 (0)