Skip to content

Commit f283997

Browse files
authored
[Feature:System] Withdrawn Column In Add/Drop Reports (#36)
Add a new column to "Add/Drop Reports" for student count with registration type "withdrawn".
1 parent 68db79d commit f283997

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

Diff for: student_auto_feed/add_drop_report.php

+33-7
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ public function go() {
8080
$enrollments = db::count_enrollments($this->term, $courses, $mapped_courses);
8181
$course_enrollments = $enrollments[0];
8282
$manual_flags = $enrollments[1];
83+
$withdrawn = $enrollments[2];
8384
// -----------------------------------------------------------------
8485
$prev_course_enrollments = reports::read_temp_csv();
85-
$report = reports::compile_report($prev_course_enrollments, $course_enrollments, $manual_flags);
86+
$report = reports::compile_report($prev_course_enrollments, $course_enrollments, $manual_flags, $withdrawn);
8687
reports::send_report($this->term, $report);
8788
return null;
8889
default:
@@ -204,6 +205,7 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
204205

205206
$course_enrollments = [];
206207
$manual_flags = [];
208+
$withdrawn = [];
207209

208210
foreach ($course_list as $course) {
209211
$grad_course = array_search($course, $mapped_courses);
@@ -222,6 +224,13 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
222224
if ($res === false)
223225
die("Failed to lookup counts with manual flag set for {$course}\n");
224226
$manual_flags[$course] = (int) pg_fetch_result($res, 0);
227+
228+
// Get withdrawn enrollments count
229+
$sql = "SELECT COUNT(registration_type) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section IS NOT NULL AND registration_type='withdrawn'";
230+
$res = pg_query_params(self::$db, $sql, $params);
231+
if ($res === false)
232+
die("Failed to lookup counts with manual flag set for {$course}\n");
233+
$withdrawn[$course] = (int) pg_fetch_result($res, 0);
225234
} else {
226235
// UNDERGRADUATE SECTION
227236
$sql = "SELECT COUNT(*) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='1'";
@@ -238,6 +247,13 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
238247
die("Failed to lookup counts with manual flag set for {$course} (undergrads)\n");
239248
$manual_flags[$course] = (int) pg_fetch_result($res, 0);
240249

250+
// Get withdrawn enrollments count
251+
$sql = "SELECT COUNT(registration_type) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='1' AND registration_type='withdrawn'";
252+
$res = pg_query_params(self::$db, $sql, $params);
253+
if ($res === false)
254+
die("Failed to lookup counts with manual flag set for {$course}\n");
255+
$withdrawn[$course] = (int) pg_fetch_result($res, 0);
256+
241257
// GRADUATE SECTION
242258
$sql = "SELECT COUNT(*) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='2'";
243259
$res = pg_query_params(self::$db, $sql, $params);
@@ -251,13 +267,21 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
251267
if ($res === false)
252268
die("Failed to lookup counts with manual flag set for {$course} (grads)\n");
253269
$manual_flags[$grad_course] = (int) pg_fetch_result($res, 0);
270+
271+
// Get withdrawn enrollments count
272+
$sql = "SELECT COUNT(registration_type) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='2' AND registration_type='withdrawn'";
273+
$res = pg_query_params(self::$db, $sql, $params);
274+
if ($res === false)
275+
die("Failed to lookup counts with manual flag set for {$course}\n");
276+
$withdrawn[$grad_course] = (int) pg_fetch_result($res, 0);
254277
}
255278
}
256279

257280
// Courses make up array keys. Sort by courses.
258281
ksort($course_enrollments);
259282
ksort($manual_flags);
260-
return [$course_enrollments, $manual_flags];
283+
ksort($withdrawn);
284+
return [$course_enrollments, $manual_flags, $withdrawn];
261285
}
262286
}
263287

@@ -320,20 +344,21 @@ public static function read_temp_csv() {
320344
* @param $manual_flags
321345
* @return string $report
322346
*/
323-
public static function compile_report($prev_course_enrollments, $course_enrollments, $manual_flags) {
347+
public static function compile_report($prev_course_enrollments, $course_enrollments, $manual_flags, $withdrawn) {
324348
// Compile stats
325349
$date = date("F j, Y");
326350
$time = date("g:i A");
327351
$report = <<<HEADING
328352
Student autofeed counts report for {$date} at {$time}
329353
NOTE: Difference and ratio do not account for the manual flag.
330-
COURSE YESTERDAY TODAY MANUAL DIFFERENCE RATIO\n
354+
COURSE YESTERDAY TODAY MANUAL DIFFERENCE RATIO WITHDRAWN\n
331355
HEADING;
332356

333357
foreach ($course_enrollments as $course=>$course_enrollment) {
334358
// Calculate data
335-
$prev_course_enrollment = array_key_exists($course, $prev_course_enrollments) ? $prev_course_enrollments[$course] : 0;
336-
$manual_flag = array_key_exists($course, $manual_flags) ? $manual_flags[$course] : 0;
359+
$prev_course_enrollment = $prev_course_enrollments[$course] ?? 0;
360+
$manual_flag = $manual_flags[$course] ?? 0;
361+
$withdrew = $withdrawn[$course] ?? 0;
337362
$diff = $course_enrollment - $prev_course_enrollment;
338363
$ratio = $prev_course_enrollment != 0 ? abs(round(($diff / $prev_course_enrollment), 3)) : "N/A";
339364

@@ -343,9 +368,10 @@ public static function compile_report($prev_course_enrollments, $course_enrollme
343368
$course_enrollment = str_pad($course_enrollment, 5, " ", STR_PAD_LEFT);
344369
$manual_flag = str_pad($manual_flag, 6, " ", STR_PAD_LEFT);
345370
$diff = str_pad($diff, 10, " ", STR_PAD_LEFT);
371+
$ratio = str_pad($ratio, 5, " ", STR_PAD_RIGHT);
346372

347373
// Add row to report.
348-
$report .= "{$course}{$prev_course_enrollment} {$course_enrollment} {$manual_flag} {$diff} {$ratio}\n";
374+
$report .= "{$course}{$prev_course_enrollment} {$course_enrollment} {$manual_flag} {$diff} {$ratio} {$withdrew}\n";
349375
}
350376

351377
return $report;

0 commit comments

Comments
 (0)