Update app.py
Browse files
app.py
CHANGED
@@ -376,27 +376,26 @@ def compute_student_metrics(df):
|
|
376 |
engagement_pct = (sum_engagement_values / number_sessions_attended) * 100 if number_sessions_attended > 0 else 0
|
377 |
engagement_pct = round(engagement_pct) # Round to whole number
|
378 |
|
379 |
-
#
|
380 |
-
# student_metrics[student_name] = {
|
381 |
-
# 'Attendance (%)': attendance_pct,
|
382 |
-
# 'Engagement (%)': engagement_pct
|
383 |
-
# }
|
384 |
-
|
385 |
-
# Store metrics with percentage sign
|
386 |
student_metrics[student_name] = {
|
387 |
-
'Attendance (%)':
|
388 |
-
'Engagement (%)':
|
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 |
-
|
397 |
def plot_student_metrics(student_metrics_df):
|
398 |
# Create the figure and axis
|
399 |
-
fig, ax = plt.subplots(figsize=(10, 6)) #
|
400 |
|
401 |
# Width for the bars
|
402 |
bar_width = 0.35 # Width of the bars
|
@@ -416,12 +415,12 @@ def plot_student_metrics(student_metrics_df):
|
|
416 |
for bar in attendance_bars:
|
417 |
height = bar.get_height()
|
418 |
ax.text(bar.get_x() + bar.get_width() / 2, height,
|
419 |
-
f'{height:.
|
420 |
|
421 |
for bar in engagement_bars:
|
422 |
height = bar.get_height()
|
423 |
ax.text(bar.get_x() + bar.get_width() / 2, height,
|
424 |
-
f'{height:.
|
425 |
|
426 |
# Set labels, title, and legend
|
427 |
ax.set_xlabel('Student')
|
|
|
376 |
engagement_pct = (sum_engagement_values / number_sessions_attended) * 100 if number_sessions_attended > 0 else 0
|
377 |
engagement_pct = round(engagement_pct) # Round to whole number
|
378 |
|
379 |
+
# Store metrics
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
student_metrics[student_name] = {
|
381 |
+
'Attendance (%)': attendance_pct,
|
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
|
399 |
|
400 |
# Width for the bars
|
401 |
bar_width = 0.35 # Width of the bars
|
|
|
415 |
for bar in attendance_bars:
|
416 |
height = bar.get_height()
|
417 |
ax.text(bar.get_x() + bar.get_width() / 2, height,
|
418 |
+
f'{height:.0f}%', ha='center', va='bottom', color='black') # No decimal for integer percentage
|
419 |
|
420 |
for bar in engagement_bars:
|
421 |
height = bar.get_height()
|
422 |
ax.text(bar.get_x() + bar.get_width() / 2, height,
|
423 |
+
f'{height:.0f}%', ha='center', va='bottom', color='black') # No decimal for integer percentage
|
424 |
|
425 |
# Set labels, title, and legend
|
426 |
ax.set_xlabel('Student')
|