From 37e2aa62812fb41baf14db01c6abac645fc09abe Mon Sep 17 00:00:00 2001 From: pbailie Date: Thu, 8 Sep 2022 15:32:39 -0400 Subject: [PATCH 1/5] Upsert for student's registration type New feature for upserting a student's registration type. Registration type can be "graded", "audit", or "late drop / withdrawn". --- student_auto_feed/config.php | 36 ++++++++++++++----- student_auto_feed/ssaf_db.php | 15 ++++++++ student_auto_feed/ssaf_sql.php | 14 +++++++- .../submitty_student_auto_feed.php | 10 +++++- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/student_auto_feed/config.php b/student_auto_feed/config.php index 5595e2e..2aa4e60 100644 --- a/student_auto_feed/config.php +++ b/student_auto_feed/config.php @@ -52,17 +52,35 @@ // accessed locally or remotely. define('CSV_FILE', '/path/to/datafile.csv'); -// Student registration status is important, as data dumps can contain students -// who have dropped a course either before the semester starts or during the -// semester. This array will contain all valid registered-student codes can be -// expected in the data dump. -// -// IMPORTANT: Consult with your University's IT administrator and/or registrar -// to add all pertinant student-is-registered codes that can be found -// in your CSV data dump. EXAMPLE: 'RA' may mean "registered by -// advisor" and 'RW' may mean "registered via web" +/* STUDENT REGISTRATION CODES -------------------------------------------------- + * + * Student registration status is important, as data dumps can contain students + * who have dropped a course either before the semester starts or during the + * semester. Be sure that all codes are set as an array, even when only one + * code is found in the CSV data. Set to NULL when there are no codes for + * either student auditing a course or students late-withdrawn from a course. + * + * IMPORTANT: Consult with your University's IT administrator and/or registrar + * for the pertinant student registration codes that can be found in + * your CSV data dump. + * + * -------------------------------------------------------------------------- */ + +// These codes are for students who are registered to take a course for a grade. +// EXAMPLE: 'RA' may mean "registered by advisor" and 'RW' may mean +// "registered via web". Do not set to NULL. define('STUDENT_REGISTERED_CODES', array('RA', 'RW')); +// These codes are for students auditing a course. These students will not be +// given a grade. +// Set this to NULL if your CSV data does not provide this information. +define('STUDENT_AUDIT_CODES', array('AU')); + +// These codes are for students who have dropped their course after the drop +// deadline and are given a late-drop or withdrawn code on their transcript. +// Set this to NULL if your CSV data does not provide this information. +define('STUDENT_LATEDROP_CODES', array('W')); + //An exceptionally small file size can indicate a problem with the feed, and //therefore the feed should not be processed to preserve data integrity of the //users table. Value is in bytes. You should pick a reasonable minimum diff --git a/student_auto_feed/ssaf_db.php b/student_auto_feed/ssaf_db.php index 9804054..19fec1a 100644 --- a/student_auto_feed/ssaf_db.php +++ b/student_auto_feed/ssaf_db.php @@ -175,12 +175,27 @@ public static function upsert($semester, $course, $rows) : bool { $row[COLUMN_EMAIL] ); + // Determine registration type for courses_users table + // Registration type code has already been validated by now. + switch(true) { + case in_array($row[COLUMN_REGISTRATION], STUDENT_REGISTERED_CODES): + $registration_type = sql::RT_GRADED; + break; + case in_array($row[COLUMN_REGISTRATION], STUDENT_AUDIT_CODES): + $registration_type = sql::RT_AUDIT; + break; + default: + $registration_type = sql::RT_LATEDROP; + break; + } + $courses_users_params = array( $semester, $course, $row[COLUMN_USER_ID], 4, $row[COLUMN_SECTION], + $registration_type, "FALSE" ); diff --git a/student_auto_feed/ssaf_sql.php b/student_auto_feed/ssaf_sql.php index 34f103b..aa9c2cd 100644 --- a/student_auto_feed/ssaf_sql.php +++ b/student_auto_feed/ssaf_sql.php @@ -12,6 +12,11 @@ class sql { public const COMMIT = "COMMIT"; public const ROLLBACK = "ROLLBACK"; + // Registration type constants + public const RT_GRADED = "graded"; + public const RT_AUDIT = "audit"; + public const RT_LATEDROP = "late drop / withdrawn"; + // SELECT queries public const GET_COURSES = <<course_list) !== false) { if (validate::validate_row($row, $row_num)) { @@ -192,6 +196,10 @@ private function get_csv_data() { if (validate::validate_row($row, $row_num)) { $row[COLUMN_SECTION] = $this->mapped_courses[$course][$section]['mapped_section']; $this->data[$m_course][] = $row; + // Rows with blank emails are allowed, but they are being logged. + if ($row[COLUMN_EMAIL] === "") { + $this->log_it("Blank email found for user {$row[COLUMN_USER_ID]}, row {$row_num}."); + } } else { $this->invalid_courses[$m_course] = true; $this->log_it(validate::$error); From 038b19c01f5e1d7f3a659d1397120b1b2dbcad44 Mon Sep 17 00:00:00 2001 From: pbailie Date: Tue, 13 Sep 2022 10:32:53 -0400 Subject: [PATCH 2/5] Update ssaf_sql.php --- student_auto_feed/ssaf_sql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/student_auto_feed/ssaf_sql.php b/student_auto_feed/ssaf_sql.php index aa9c2cd..ec858cf 100644 --- a/student_auto_feed/ssaf_sql.php +++ b/student_auto_feed/ssaf_sql.php @@ -15,7 +15,7 @@ class sql { // Registration type constants public const RT_GRADED = "graded"; public const RT_AUDIT = "audit"; - public const RT_LATEDROP = "late drop / withdrawn"; + public const RT_LATEDROP = "withdrawn"; // SELECT queries public const GET_COURSES = << Date: Tue, 13 Sep 2022 17:06:45 -0400 Subject: [PATCH 3/5] Update ssaf_sql.php --- student_auto_feed/ssaf_sql.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/student_auto_feed/ssaf_sql.php b/student_auto_feed/ssaf_sql.php index ec858cf..298e512 100644 --- a/student_auto_feed/ssaf_sql.php +++ b/student_auto_feed/ssaf_sql.php @@ -82,17 +82,17 @@ class sql { ) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (semester, course, user_id) DO UPDATE SET registration_section= - CASE WHEN courses_users.user_group=4 - AND courses_users.manual_registration=FALSE - THEN EXCLUDED.registration_section - ELSE courses_users.registration_section - END, -SET registration_type= - CASE WHEN courses_users.user_group=4 - AND courses_users.manual_registration=FALSE - THEN EXCLUDED.registration_type - ELSE courses_users.registration_type - END + CASE WHEN courses_users.user_group=4 + AND courses_users.manual_registration=FALSE + THEN EXCLUDED.registration_section + ELSE courses_users.registration_section + END, + registration_type= + CASE WHEN courses_users.user_group=4 + AND courses_users.manual_registration=FALSE + THEN EXCLUDED.registration_type + ELSE courses_users.registration_type + END SQL; // INSERT courses_registration_sections table From bd312a462a00e2a12f17f526f958a6020a07f471 Mon Sep 17 00:00:00 2001 From: pbailie Date: Wed, 12 Oct 2022 12:38:07 -0400 Subject: [PATCH 4/5] Update submitty_student_auto_feed.php File locking can cause the autofeed to hang when run on a shared file system under certain conditions. So file locking the CSV has been removed. --- student_auto_feed/submitty_student_auto_feed.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/student_auto_feed/submitty_student_auto_feed.php b/student_auto_feed/submitty_student_auto_feed.php index 73ba76a..574cefc 100755 --- a/student_auto_feed/submitty_student_auto_feed.php +++ b/student_auto_feed/submitty_student_auto_feed.php @@ -343,17 +343,7 @@ private function invalidate_courses() { */ private function open_csv() { $this->fh = fopen(CSV_FILE, "r"); - if ($this->fh !== false) { - if (flock($this->fh, LOCK_SH, $wouldblock)) { - return true; - } else if ($wouldblock === 1) { - $this->logit("Another process has locked the CSV."); - return false; - } else { - $this->logit("CSV not blocked, but still could not attain lock for reading."); - return false; - } - } else { + if ($this->fh === false) { $this->log_it("Could not open CSV file."); return false; } From 78bc1c64172d273329f302a116a039ee127dccb8 Mon Sep 17 00:00:00 2001 From: pbailie Date: Wed, 12 Oct 2022 16:55:55 -0400 Subject: [PATCH 5/5] Update submitty_student_auto_feed.php --- student_auto_feed/submitty_student_auto_feed.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/student_auto_feed/submitty_student_auto_feed.php b/student_auto_feed/submitty_student_auto_feed.php index 574cefc..2604984 100755 --- a/student_auto_feed/submitty_student_auto_feed.php +++ b/student_auto_feed/submitty_student_auto_feed.php @@ -347,6 +347,8 @@ private function open_csv() { $this->log_it("Could not open CSV file."); return false; } + + return true; } /** Close CSV file */