James McCool commited on
Commit
02a9379
·
1 Parent(s): 33f8e62

Refactor game rotation timeline plot using horizontal bars with dynamic coloring

Browse files
Files changed (1) hide show
  1. app.py +28 -17
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
- fig = px.timeline(data_frame=check_rotation,
701
- x_start='Start', # Column containing start times
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
- fig.layout.xaxis.type = 'linear'
708
- fig.update_yaxes(autorange="reversed") # Reverse y-axis to show tasks top-to-bottom
709
-
710
- # Create a color map for each unique player
711
- player_colors = px.colors.qualitative.Plotly[:len(check_rotation['PLAYER_NAME'].unique())]
712
- color_map = dict(zip(check_rotation['PLAYER_NAME'].unique(), player_colors))
713
-
714
- # Update the figure to use the color map
715
- fig.update_traces(marker=dict(color=[color_map[player] for player in check_rotation['PLAYER_NAME']]))
716
-
717
- # Add vertical lines for quarter marks
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")