ProfessorLeVesseur commited on
Commit
b7e5770
1 Parent(s): d96c1a5

Update data_processor.py

Browse files
Files changed (1) hide show
  1. data_processor.py +39 -10
data_processor.py CHANGED
@@ -117,21 +117,50 @@ class DataProcessor:
117
  elif x == self.NOT_ENGAGED_STR:
118
  engagement_counts['Not Engaged'] += 1
119
  else:
120
- engagement_counts['Absent'] += 1
121
 
 
122
  total_sessions = sum(engagement_counts.values())
 
 
123
  engagement_pct = (engagement_counts['Engaged'] / total_sessions * 100) if total_sessions > 0 else 0
124
  engagement_pct = round(engagement_pct)
125
-
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  student_metrics[student_name] = {
127
  'Attendance (%)': attendance_pct,
128
- 'Attendance #': sessions_attended,
129
- 'Engagement (%)': engagement_pct
 
 
 
 
130
  }
131
 
132
- return pd.DataFrame.from_dict(student_metrics, orient='index').reset_index().rename(columns={'index': 'Student'})
133
-
134
- def compute_average_metrics(self, student_metrics_df):
135
- attendance_avg_stats = student_metrics_df['Attendance (%)'].mean()
136
- engagement_avg_stats = student_metrics_df['Engagement (%)'].mean()
137
- return round(attendance_avg_stats), round(engagement_avg_stats)
 
 
 
 
 
 
 
 
 
 
117
  elif x == self.NOT_ENGAGED_STR:
118
  engagement_counts['Not Engaged'] += 1
119
  else:
120
+ engagement_counts['Absent'] += 1 # Count as Absent if not engaged
121
 
122
+ # Calculate percentages for engagement states
123
  total_sessions = sum(engagement_counts.values())
124
+
125
+ # Engagement (%)
126
  engagement_pct = (engagement_counts['Engaged'] / total_sessions * 100) if total_sessions > 0 else 0
127
  engagement_pct = round(engagement_pct)
128
+
129
+ engaged_pct = (engagement_counts['Engaged'] / total_sessions * 100) if total_sessions > 0 else 0
130
+ engaged_pct = round(engaged_pct)
131
+
132
+ partially_engaged_pct = (engagement_counts['Partially Engaged'] / total_sessions * 100) if total_sessions > 0 else 0
133
+ partially_engaged_pct = round(partially_engaged_pct)
134
+
135
+ not_engaged_pct = (engagement_counts['Not Engaged'] / total_sessions * 100) if total_sessions > 0 else 0
136
+ not_engaged_pct = round(not_engaged_pct)
137
+
138
+ absent_pct = (engagement_counts['Absent'] / total_sessions * 100) if total_sessions > 0 else 0
139
+ absent_pct = round(absent_pct)
140
+
141
+ # Store metrics in the required order
142
  student_metrics[student_name] = {
143
  'Attendance (%)': attendance_pct,
144
+ 'Attendance #': sessions_attended, # Raw number of sessions attended
145
+ 'Engagement (%)': engagement_pct,
146
+ 'Engaged (%)': engaged_pct,
147
+ 'Partially Engaged (%)': partially_engaged_pct,
148
+ 'Not Engaged (%)': not_engaged_pct,
149
+ 'Absent (%)': absent_pct
150
  }
151
 
152
+ # Create a DataFrame from student_metrics
153
+ student_metrics_df = pd.DataFrame.from_dict(student_metrics, orient='index').reset_index()
154
+ student_metrics_df.rename(columns={'index': 'Student'}, inplace=True)
155
+ return student_metrics_df
156
+
157
+ def compute_average_metrics(student_metrics_df):
158
+ # Calculate the attendance and engagement average percentages across students
159
+ attendance_avg_stats = student_metrics_df['Attendance (%)'].mean() # Calculate the average attendance percentage
160
+ engagement_avg_stats = student_metrics_df['Engagement (%)'].mean() # Calculate the average engagement percentage
161
+
162
+ # Round the averages to make them whole numbers
163
+ attendance_avg_stats = round(attendance_avg_stats)
164
+ engagement_avg_stats = round(engagement_avg_stats)
165
+
166
+ return attendance_avg_stats, engagement_avg_stats