ProfessorLeVesseur
commited on
Commit
•
67c294a
1
Parent(s):
d234974
Update app.py
Browse files
app.py
CHANGED
@@ -132,10 +132,11 @@ NOT_ENGAGED_STR = 'Not Engaged (less than 50%)'
|
|
132 |
|
133 |
def safe_convert_to_time(series, format_str='%I:%M %p'):
|
134 |
try:
|
135 |
-
# Attempt to
|
136 |
-
converted = pd.to_datetime(series, errors='coerce').dt.time
|
|
|
137 |
if format_str:
|
138 |
-
# Format
|
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:
|
@@ -384,13 +385,13 @@ def plot_student_metrics(student_metrics_df):
|
|
384 |
bar_width = 0.4
|
385 |
index = range(len(student_metrics_df))
|
386 |
|
387 |
-
# Plot Attendance and Engagement bars
|
388 |
-
attendance_bars = ax.bar(index, student_metrics_df['Attendance (%)'],
|
389 |
width=bar_width, label='Attendance (%)', color='#005288', alpha=0.7)
|
390 |
-
engagement_bars = ax.bar(index, student_metrics_df['Engagement (%)'],
|
391 |
-
width=bar_width
|
392 |
|
393 |
-
# Add
|
394 |
for bar in attendance_bars:
|
395 |
height = bar.get_height()
|
396 |
ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
|
@@ -414,6 +415,44 @@ def plot_student_metrics(student_metrics_df):
|
|
414 |
|
415 |
return fig
|
416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
def download_chart(fig, filename):
|
418 |
# Create a buffer to hold the image data
|
419 |
buffer = io.BytesIO()
|
|
|
132 |
|
133 |
def safe_convert_to_time(series, format_str='%I:%M %p'):
|
134 |
try:
|
135 |
+
# Attempt to parse the time in 24-hour format
|
136 |
+
converted = pd.to_datetime(series, format='%H:%M:%S', errors='coerce').dt.time
|
137 |
+
|
138 |
if format_str:
|
139 |
+
# Format the time to the specified format (hours and minutes only, with AM/PM)
|
140 |
return pd.Series([time.strftime(format_str) if time is not None else None for time in converted])
|
141 |
return converted
|
142 |
except Exception as e:
|
|
|
385 |
bar_width = 0.4
|
386 |
index = range(len(student_metrics_df))
|
387 |
|
388 |
+
# Plot Attendance and Engagement bars side by side with transparency
|
389 |
+
attendance_bars = ax.bar([i - bar_width/2 for i in index], student_metrics_df['Attendance (%)'],
|
390 |
width=bar_width, label='Attendance (%)', color='#005288', alpha=0.7)
|
391 |
+
engagement_bars = ax.bar([i + bar_width/2 for i in index], student_metrics_df['Engagement (%)'],
|
392 |
+
width=bar_width, label='Engagement (%)', color='#3AB0FF', alpha=0.7)
|
393 |
|
394 |
+
# Add labels to each bar
|
395 |
for bar in attendance_bars:
|
396 |
height = bar.get_height()
|
397 |
ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
|
|
|
415 |
|
416 |
return fig
|
417 |
|
418 |
+
# def plot_student_metrics(student_metrics_df):
|
419 |
+
# # Create the figure and axis
|
420 |
+
# fig, ax = plt.subplots()
|
421 |
+
|
422 |
+
# # Width for the bars and offset for overlapping effect
|
423 |
+
# bar_width = 0.4
|
424 |
+
# index = range(len(student_metrics_df))
|
425 |
+
|
426 |
+
# # Plot Attendance and Engagement bars with different widths for overlapping
|
427 |
+
# attendance_bars = ax.bar(index, student_metrics_df['Attendance (%)'],
|
428 |
+
# width=bar_width, label='Attendance (%)', color='#005288', alpha=0.7)
|
429 |
+
# engagement_bars = ax.bar(index, student_metrics_df['Engagement (%)'],
|
430 |
+
# width=bar_width / 2, label='Engagement (%)', color='#3AB0FF', alpha=0.7)
|
431 |
+
|
432 |
+
# # Add values to each bar
|
433 |
+
# for bar in attendance_bars:
|
434 |
+
# height = bar.get_height()
|
435 |
+
# ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
|
436 |
+
# ha='center', va='bottom', color='black')
|
437 |
+
|
438 |
+
# for bar in engagement_bars:
|
439 |
+
# height = bar.get_height()
|
440 |
+
# ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
|
441 |
+
# ha='center', va='bottom', color='black')
|
442 |
+
|
443 |
+
# # Set labels, title, and legend
|
444 |
+
# ax.set_xlabel('Student')
|
445 |
+
# ax.set_ylabel('Percentage (%)')
|
446 |
+
# ax.set_title('Student Attendance and Engagement Metrics')
|
447 |
+
# ax.legend()
|
448 |
+
# ax.set_xticks(index)
|
449 |
+
# ax.set_xticklabels(student_metrics_df['Student'], rotation=45)
|
450 |
+
|
451 |
+
# # Display the plot
|
452 |
+
# st.pyplot(fig)
|
453 |
+
|
454 |
+
# return fig
|
455 |
+
|
456 |
def download_chart(fig, filename):
|
457 |
# Create a buffer to hold the image data
|
458 |
buffer = io.BytesIO()
|