Skip to content

Commit

Permalink
Grade data keying fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpahm committed Oct 9, 2024
1 parent a8cd16c commit 28b3641
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion parser/gradeLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions parser/sectionParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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:"]

Expand Down
6 changes: 3 additions & 3 deletions utils/regexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]+`
Expand Down

0 comments on commit 28b3641

Please sign in to comment.