Spaces:
Runtime error
Runtime error
James McCool
commited on
Commit
·
02a9379
1
Parent(s):
33f8e62
Refactor game rotation timeline plot using horizontal bars with dynamic coloring
Browse files
app.py
CHANGED
@@ -697,24 +697,35 @@ with tab5:
|
|
697 |
check_rotation['Finish'] = pd.to_numeric(check_rotation['Finish'], errors='coerce')
|
698 |
check_rotation['delta'] = pd.to_numeric(check_rotation['delta'], errors='coerce')
|
699 |
|
700 |
-
|
701 |
-
|
702 |
-
x_end='Finish', # Column containing end times
|
703 |
-
y='Task', # Column containing player/shift labels
|
704 |
-
range_x=[0, check_rotation["Finish"].max()],
|
705 |
-
text='delta') # Show the duration as text
|
706 |
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
718 |
fig.add_vline(x=12, line_width=3, line_dash="dash", line_color="green")
|
719 |
fig.add_vline(x=24, line_width=3, line_dash="dash", line_color="green")
|
720 |
fig.add_vline(x=36, line_width=3, line_dash="dash", line_color="green")
|
|
|
697 |
check_rotation['Finish'] = pd.to_numeric(check_rotation['Finish'], errors='coerce')
|
698 |
check_rotation['delta'] = pd.to_numeric(check_rotation['delta'], errors='coerce')
|
699 |
|
700 |
+
# Create figure
|
701 |
+
fig = go.Figure()
|
|
|
|
|
|
|
|
|
702 |
|
703 |
+
# Add bars for each shift
|
704 |
+
for idx, row in check_rotation.iterrows():
|
705 |
+
fig.add_trace(go.Bar(
|
706 |
+
x=[row['delta']], # Width of bar
|
707 |
+
y=[row['Task']],
|
708 |
+
base=row['Start'], # Start position of bar
|
709 |
+
orientation='h',
|
710 |
+
text=f"{row['delta']:.1f}",
|
711 |
+
textposition='inside',
|
712 |
+
showlegend=False,
|
713 |
+
marker_color=px.colors.qualitative.Plotly[hash(row['PLAYER_NAME']) % len(px.colors.qualitative.Plotly)]
|
714 |
+
))
|
715 |
+
|
716 |
+
# Update layout
|
717 |
+
fig.update_layout(
|
718 |
+
barmode='overlay',
|
719 |
+
xaxis=dict(
|
720 |
+
range=[0, 48],
|
721 |
+
title='Game Time (minutes)'
|
722 |
+
),
|
723 |
+
yaxis=dict(
|
724 |
+
autorange='reversed'
|
725 |
+
)
|
726 |
+
)
|
727 |
+
|
728 |
+
# Add quarter lines
|
729 |
fig.add_vline(x=12, line_width=3, line_dash="dash", line_color="green")
|
730 |
fig.add_vline(x=24, line_width=3, line_dash="dash", line_color="green")
|
731 |
fig.add_vline(x=36, line_width=3, line_dash="dash", line_color="green")
|