From 28b3641e612349abd2cd67d9f44f94ca72fe9de5 Mon Sep 17 00:00:00 2001 From: jpahm <20374744+jpahm@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:49:42 -0500 Subject: [PATCH] Grade data keying fixes --- parser/gradeLoader.go | 4 +++- parser/parser.go | 2 +- parser/sectionParser.go | 6 ++++-- utils/regexes.go | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/parser/gradeLoader.go b/parser/gradeLoader.go index ec63150..aad3004 100644 --- a/parser/gradeLoader.go +++ b/parser/gradeLoader.go @@ -138,7 +138,9 @@ func csvToMap(csvFile *os.File, logFile *os.File) map[string][]int { } // add new grade distribution to map, keyed by SUBJECT + NUMBER + SECTION - distroKey := record[subjectCol] + record[catalogNumberCol] + record[sectionCol] + // Be sure to trim left padding on section number + trimmedSectionNumber := strings.TrimLeft(record[sectionCol], "0") + distroKey := record[subjectCol] + record[catalogNumberCol] + trimmedSectionNumber distroMap[distroKey] = intSlice[:] } return distroMap diff --git a/parser/parser.go b/parser/parser.go index 1c371ae..606e5b2 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -153,7 +153,7 @@ func parse(path string) { courseNum := utils.TrimWhitespace(classAndCourseNum[1]) // Figure out the academic session associated with this specific course/Section - session := getAcademicSession(rowInfo, classInfo) + session := getAcademicSession(rowInfo) // Try to create the course and section based on collected info courseRef := parseCourse(courseNum, session, rowInfo, classInfo) diff --git a/parser/sectionParser.go b/parser/sectionParser.go index 12566d1..0a4b768 100644 --- a/parser/sectionParser.go +++ b/parser/sectionParser.go @@ -64,7 +64,9 @@ func parseSection(courseRef *schema.Course, classNum string, syllabusURI string, if exists { // We have to trim leading zeroes from the section number in order to match properly, since the grade data does not use leading zeroes trimmedSectionNumber := strings.TrimLeft(section.Section_number, "0") - sectionGrades, exists := semesterGrades[courseRef.Subject_prefix+courseRef.Course_number+trimmedSectionNumber] + // Key into grademap should be uppercased like the grade data + gradeKey := strings.ToUpper(courseRef.Subject_prefix + courseRef.Course_number + trimmedSectionNumber) + sectionGrades, exists := semesterGrades[gradeKey] if exists { section.Grade_distribution = sectionGrades } @@ -80,7 +82,7 @@ func parseSection(courseRef *schema.Course, classNum string, syllabusURI string, var termRegexp *regexp.Regexp = utils.Regexpf(`(?i)Term: (%s)`, utils.R_TERM_CODE) var datesRegexp *regexp.Regexp = utils.Regexpf(`(?:Start|End)s: (%s)`, utils.R_DATE_MDY) -func getAcademicSession(rowInfo map[string]string, classInfo map[string]string) schema.AcademicSession { +func getAcademicSession(rowInfo map[string]string) schema.AcademicSession { session := schema.AcademicSession{} scheduleText := rowInfo["Schedule:"] diff --git a/utils/regexes.go b/utils/regexes.go index c939df2..dde039e 100644 --- a/utils/regexes.go +++ b/utils/regexes.go @@ -9,13 +9,13 @@ const R_SUBJECT string = `[A-Z]{2,4}` // Course code, i.e. 2252. // The first digit of a course code is the course level, the second digit is the # of credit hours. -const R_COURSE_CODE string = `[0-9v]{4}` +const R_COURSE_CODE string = `[0-9vV]{4}` // Subject + Course, captured -const R_SUBJ_COURSE_CAP string = `([A-Z]{2,4})\s*([0-9V]{4})` +const R_SUBJ_COURSE_CAP string = `([A-Z]{2,4})\s*([0-9vV]{4})` // Subject + Course, uncaptured -const R_SUBJ_COURSE string = `[A-Z]{2,4}\s*[0-9V]{4}` +const R_SUBJ_COURSE string = `[A-Z]{2,4}\s*[0-9vV]{4}` // Section code, i.e. 101 const R_SECTION_CODE string = `[0-9A-z]+`