Skip to content

[Enhancement] Autofeed -- Student Registration Types #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions student_auto_feed/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions student_auto_feed/ssaf_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);

Expand Down
24 changes: 18 additions & 6 deletions student_auto_feed/ssaf_sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "withdrawn";

// SELECT queries
public const GET_COURSES = <<<SQL
SELECT course
Expand Down Expand Up @@ -72,15 +77,22 @@ class sql {
user_id,
user_group,
registration_section,
registration_type,
manual_registration
) VALUES ($1, $2, $3, $4, $5, $6)
) 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
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
Expand Down
24 changes: 12 additions & 12 deletions student_auto_feed/submitty_student_auto_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ private function get_csv_data() {
$course = strtolower($row[COLUMN_COURSE_PREFIX] . $row[COLUMN_COURSE_NUMBER]);

// Does $row have a valid registration code?
if (array_search($row[COLUMN_REGISTRATION], STUDENT_REGISTERED_CODES) !== false) {
$graded_codes = STUDENT_REGISTERED_CODES;
$audit_codes = is_null(STUDENT_AUDIT_CODES) ? array() : STUDENT_AUDIT_CODES;
$latedrop_codes = is_null(STUDENT_LATEDROP_CODES) ? array() : STUDENT_LATEDROP_CODES;
$all_valid_codes = array_merge($graded_codes, $audit_codes, $latedrop_codes);
if (array_search($row[COLUMN_REGISTRATION], $all_valid_codes) !== false) {
// Check that $row is associated with the course list
if (array_search($course, $this->course_list) !== false) {
if (validate::validate_row($row, $row_num)) {
Expand All @@ -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);
Expand Down Expand Up @@ -335,20 +343,12 @@ 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;
}

return true;
}

/** Close CSV file */
Expand Down