ProfessorLeVesseur
commited on
Commit
•
da9b757
1
Parent(s):
4eb7186
Update app.py
Browse files
app.py
CHANGED
@@ -130,19 +130,6 @@ 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_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:
|
143 |
-
# print(f"Error converting series to time: {e}")
|
144 |
-
# return series
|
145 |
-
|
146 |
def safe_convert_to_time(series, format_str='%I:%M %p'):
|
147 |
try:
|
148 |
converted = pd.to_datetime(series, format='%H:%M:%S', errors='coerce')
|
@@ -382,17 +369,29 @@ def compute_student_metrics(df):
|
|
382 |
'Engagement (%)': engagement_pct
|
383 |
}
|
384 |
|
385 |
-
# # Store metrics with percentage sign
|
386 |
-
# student_metrics[student_name] = {
|
387 |
-
# 'Attendance (%)': f"{attendance_pct}%", # Add percentage sign
|
388 |
-
# 'Engagement (%)': f"{engagement_pct}%" # Add percentage sign
|
389 |
-
# }
|
390 |
-
|
391 |
# Create a DataFrame from student_metrics
|
392 |
student_metrics_df = pd.DataFrame.from_dict(student_metrics, orient='index').reset_index()
|
393 |
student_metrics_df.rename(columns={'index': 'Student'}, inplace=True)
|
394 |
return student_metrics_df
|
395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
def plot_student_metrics(student_metrics_df):
|
397 |
# Create the figure and axis
|
398 |
fig, ax = plt.subplots(figsize=(10, 6)) # Increased figure size for better readability
|
@@ -432,7 +431,8 @@ def plot_student_metrics(student_metrics_df):
|
|
432 |
|
433 |
# Display the plot
|
434 |
plt.tight_layout() # Adjust layout to fit elements
|
435 |
-
plt.show() # Show the plot in a script environment (use st.pyplot(fig) in Streamlit)
|
|
|
436 |
|
437 |
return fig
|
438 |
|
|
|
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='%I:%M %p'):
|
134 |
try:
|
135 |
converted = pd.to_datetime(series, format='%H:%M:%S', errors='coerce')
|
|
|
369 |
'Engagement (%)': engagement_pct
|
370 |
}
|
371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
# Create a DataFrame from student_metrics
|
373 |
student_metrics_df = pd.DataFrame.from_dict(student_metrics, orient='index').reset_index()
|
374 |
student_metrics_df.rename(columns={'index': 'Student'}, inplace=True)
|
375 |
return student_metrics_df
|
376 |
|
377 |
+
def plot_student_metrics(student_metrics_df):
|
378 |
+
# Create a line graph for attendance and engagement
|
379 |
+
fig, ax = plt.subplots()
|
380 |
+
|
381 |
+
# Plotting Attendance and Engagement with specific colors
|
382 |
+
ax.plot(student_metrics_df['Student'], student_metrics_df['Attendance (%)'], marker='o', color='#005288', label='Attendance (%)')
|
383 |
+
ax.plot(student_metrics_df['Student'], student_metrics_df['Engagement (%)'], marker='o', color='#3AB0FF', label='Engagement (%)')
|
384 |
+
|
385 |
+
ax.set_xlabel('Student')
|
386 |
+
ax.set_ylabel('Percentage (%)')
|
387 |
+
ax.set_title('Student Attendance and Engagement Metrics')
|
388 |
+
ax.legend()
|
389 |
+
plt.xticks(rotation=45)
|
390 |
+
|
391 |
+
st.pyplot(fig)
|
392 |
+
|
393 |
+
return fig
|
394 |
+
|
395 |
def plot_student_metrics(student_metrics_df):
|
396 |
# Create the figure and axis
|
397 |
fig, ax = plt.subplots(figsize=(10, 6)) # Increased figure size for better readability
|
|
|
431 |
|
432 |
# Display the plot
|
433 |
plt.tight_layout() # Adjust layout to fit elements
|
434 |
+
# plt.show() # Show the plot in a script environment (use st.pyplot(fig) in Streamlit)
|
435 |
+
st.pyplot(fig) # This line displays the plot
|
436 |
|
437 |
return fig
|
438 |
|