ProfessorLeVesseur commited on
Commit
6808b16
1 Parent(s): 0918e3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -130,6 +130,18 @@ ENGAGED_STR = 'Engaged (Respect, Responsibility, Effort)'
130
  PARTIALLY_ENGAGED_STR = 'Partially Engaged (about 50%)'
131
  NOT_ENGAGED_STR = 'Not Engaged (less than 50%)'
132
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  def safe_convert_to_datetime(series, format_str=None):
134
  try:
135
  # Attempt to convert to datetime, ignoring errors
@@ -146,8 +158,8 @@ def format_session_data(df):
146
  # Format "Date of Session" and "Timestamp" columns with safe conversion
147
  df['Date of Session'] = safe_convert_to_datetime(df['Date of Session'], '%m/%d/%Y')
148
  df['Timestamp'] = safe_convert_to_datetime(df['Timestamp'], '%I:%M %p')
149
- df['Session Start Time'] = safe_convert_to_datetime(df['Session Start Time'], '%I:%M %p')
150
- df['Session End Time'] = safe_convert_to_datetime(df['Session End Time'], '%I:%M %p')
151
 
152
  # Reorder columns
153
  df = df[['Date of Session', 'Timestamp'] + [col for col in df.columns if col not in ['Date of Session', 'Timestamp']]]
@@ -365,21 +377,28 @@ def compute_student_metrics(df):
365
  return student_metrics_df
366
 
367
  def plot_student_metrics(student_metrics_df):
368
- # Create a stacked bar chart for attendance and engagement
369
  fig, ax = plt.subplots()
370
 
371
- # Plotting the Attendance and Engagement as stacked bars
372
- ax.bar(student_metrics_df['Student'], student_metrics_df['Attendance (%)'], label='Attendance (%)', color='#005288')
373
- ax.bar(student_metrics_df['Student'], student_metrics_df['Engagement (%)'],
374
- bottom=student_metrics_df['Attendance (%)'], label='Engagement (%)', color='#3AB0FF')
 
 
 
 
 
375
 
376
- # Setting the labels, title, and legend
377
  ax.set_xlabel('Student')
378
  ax.set_ylabel('Percentage (%)')
379
  ax.set_title('Student Attendance and Engagement Metrics')
380
  ax.legend()
381
- plt.xticks(rotation=45)
 
382
 
 
383
  st.pyplot(fig)
384
 
385
  return fig
 
130
  PARTIALLY_ENGAGED_STR = 'Partially Engaged (about 50%)'
131
  NOT_ENGAGED_STR = 'Not Engaged (less than 50%)'
132
 
133
+ def safe_convert_to_time(series, format_str=None):
134
+ try:
135
+ # Attempt to convert to time, ignoring errors
136
+ converted = pd.to_datetime(series, errors='coerce').dt.time
137
+ if format_str:
138
+ # Format if a format string is provided
139
+ return pd.Series([time.strftime(format_str) if time is not None else None for time in converted])
140
+ return converted
141
+ except Exception as e:
142
+ print(f"Error converting series to time: {e}")
143
+ return series
144
+
145
  def safe_convert_to_datetime(series, format_str=None):
146
  try:
147
  # Attempt to convert to datetime, ignoring errors
 
158
  # Format "Date of Session" and "Timestamp" columns with safe conversion
159
  df['Date of Session'] = safe_convert_to_datetime(df['Date of Session'], '%m/%d/%Y')
160
  df['Timestamp'] = safe_convert_to_datetime(df['Timestamp'], '%I:%M %p')
161
+ df['Session Start Time'] = safe_convert_to_time(df['Session Start Time'], '%I:%M %p')
162
+ df['Session End Time'] = safe_convert_to_time(df['Session End Time'], '%I:%M %p')
163
 
164
  # Reorder columns
165
  df = df[['Date of Session', 'Timestamp'] + [col for col in df.columns if col not in ['Date of Session', 'Timestamp']]]
 
377
  return student_metrics_df
378
 
379
  def plot_student_metrics(student_metrics_df):
380
+ # Create the figure and axis
381
  fig, ax = plt.subplots()
382
 
383
+ # Width for the bars and offset for overlapping effect
384
+ bar_width = 0.4
385
+ index = range(len(student_metrics_df))
386
+
387
+ # Plot Attendance and Engagement bars side by side with transparency
388
+ ax.bar([i - bar_width/2 for i in index], student_metrics_df['Attendance (%)'],
389
+ width=bar_width, label='Attendance (%)', color='#005288', alpha=0.7)
390
+ ax.bar([i + bar_width/2 for i in index], student_metrics_df['Engagement (%)'],
391
+ width=bar_width, label='Engagement (%)', color='#3AB0FF', alpha=0.7)
392
 
393
+ # Set labels, title, and legend
394
  ax.set_xlabel('Student')
395
  ax.set_ylabel('Percentage (%)')
396
  ax.set_title('Student Attendance and Engagement Metrics')
397
  ax.legend()
398
+ ax.set_xticks(index)
399
+ ax.set_xticklabels(student_metrics_df['Student'], rotation=45)
400
 
401
+ # Display the plot
402
  st.pyplot(fig)
403
 
404
  return fig