ProfessorLeVesseur commited on
Commit
52b9783
1 Parent(s): 8cfb9bd

Update data_processor.py

Browse files
Files changed (1) hide show
  1. data_processor.py +18 -10
data_processor.py CHANGED
@@ -247,30 +247,30 @@ class DataProcessor:
247
  intervention_df = df[df[self.INTERVENTION_COLUMN].str.strip().str.lower() == 'yes']
248
  intervention_sessions_held = len(intervention_df)
249
  student_columns = [col for col in df.columns if col.startswith('Student Attendance')]
250
-
251
  student_metrics = {}
252
  for col in student_columns:
253
  student_name = col.replace('Student Attendance [', '').replace(']', '').strip()
254
  student_data = intervention_df[[col]].copy()
255
  student_data[col] = student_data[col].fillna('Absent')
256
-
257
  attendance_values = student_data[col].apply(lambda x: 1 if x in [
258
  self.ENGAGED_STR,
259
  self.PARTIALLY_ENGAGED_STR,
260
  self.NOT_ENGAGED_STR
261
  ] else 0)
262
-
263
  sessions_attended = attendance_values.sum()
264
  attendance_pct = (sessions_attended / intervention_sessions_held) * 100 if intervention_sessions_held > 0 else 0
265
  attendance_pct = round(attendance_pct)
266
-
267
  engagement_counts = {
268
  'Engaged': 0,
269
  'Partially Engaged': 0,
270
  'Not Engaged': 0,
271
  'Absent': 0
272
  }
273
-
274
  for x in student_data[col]:
275
  if x == self.ENGAGED_STR:
276
  engagement_counts['Engaged'] += 1
@@ -279,8 +279,8 @@ class DataProcessor:
279
  elif x == self.NOT_ENGAGED_STR:
280
  engagement_counts['Not Engaged'] += 1
281
  else:
282
- engagement_counts['Absent'] += 1 # Count as Absent if not engaged
283
-
284
  # Calculate percentages for engagement states
285
  total_sessions = sum(engagement_counts.values())
286
 
@@ -300,17 +300,25 @@ class DataProcessor:
300
  absent_pct = (engagement_counts['Absent'] / total_sessions * 100) if total_sessions > 0 else 0
301
  absent_pct = round(absent_pct)
302
 
 
 
 
 
 
 
303
  # Store metrics in the required order
304
  student_metrics[student_name] = {
305
  'Attendance (%)': attendance_pct,
306
- 'Attendance #': sessions_attended, # Raw number of sessions attended
307
  'Engagement (%)': engagement_pct,
308
  'Engaged (%)': engaged_pct,
309
  'Partially Engaged (%)': partially_engaged_pct,
310
  'Not Engaged (%)': not_engaged_pct,
311
- 'Absent (%)': absent_pct
 
 
312
  }
313
-
314
  # Create a DataFrame from student_metrics
315
  student_metrics_df = pd.DataFrame.from_dict(student_metrics, orient='index').reset_index()
316
  student_metrics_df.rename(columns={'index': 'Student'}, inplace=True)
 
247
  intervention_df = df[df[self.INTERVENTION_COLUMN].str.strip().str.lower() == 'yes']
248
  intervention_sessions_held = len(intervention_df)
249
  student_columns = [col for col in df.columns if col.startswith('Student Attendance')]
250
+
251
  student_metrics = {}
252
  for col in student_columns:
253
  student_name = col.replace('Student Attendance [', '').replace(']', '').strip()
254
  student_data = intervention_df[[col]].copy()
255
  student_data[col] = student_data[col].fillna('Absent')
256
+
257
  attendance_values = student_data[col].apply(lambda x: 1 if x in [
258
  self.ENGAGED_STR,
259
  self.PARTIALLY_ENGAGED_STR,
260
  self.NOT_ENGAGED_STR
261
  ] else 0)
262
+
263
  sessions_attended = attendance_values.sum()
264
  attendance_pct = (sessions_attended / intervention_sessions_held) * 100 if intervention_sessions_held > 0 else 0
265
  attendance_pct = round(attendance_pct)
266
+
267
  engagement_counts = {
268
  'Engaged': 0,
269
  'Partially Engaged': 0,
270
  'Not Engaged': 0,
271
  'Absent': 0
272
  }
273
+
274
  for x in student_data[col]:
275
  if x == self.ENGAGED_STR:
276
  engagement_counts['Engaged'] += 1
 
279
  elif x == self.NOT_ENGAGED_STR:
280
  engagement_counts['Not Engaged'] += 1
281
  else:
282
+ engagement_counts['Absent'] += 1 # Count as Absent if not engaged
283
+
284
  # Calculate percentages for engagement states
285
  total_sessions = sum(engagement_counts.values())
286
 
 
300
  absent_pct = (engagement_counts['Absent'] / total_sessions * 100) if total_sessions > 0 else 0
301
  absent_pct = round(absent_pct)
302
 
303
+ # Determine if the student attended ≥ 90% of sessions
304
+ attended_90 = "Yes" if attendance_pct >= 90 else "No"
305
+
306
+ # Determine if the student was engaged ≥ 80% of the time
307
+ engaged_80 = "Yes" if engaged_pct >= 80 else "No"
308
+
309
  # Store metrics in the required order
310
  student_metrics[student_name] = {
311
  'Attendance (%)': attendance_pct,
312
+ 'Attendance #': sessions_attended,
313
  'Engagement (%)': engagement_pct,
314
  'Engaged (%)': engaged_pct,
315
  'Partially Engaged (%)': partially_engaged_pct,
316
  'Not Engaged (%)': not_engaged_pct,
317
+ 'Absent (%)': absent_pct,
318
+ 'Attended ≥ 90%': attended_90,
319
+ 'Engagement ≥ 80%': engaged_80
320
  }
321
+
322
  # Create a DataFrame from student_metrics
323
  student_metrics_df = pd.DataFrame.from_dict(student_metrics, orient='index').reset_index()
324
  student_metrics_df.rename(columns={'index': 'Student'}, inplace=True)