Skip to content

Commit 4c09c33

Browse files
committed
addressed edge cases
1 parent 067acc0 commit 4c09c33

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

frontend/degree-plan/utils/parseUtils.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ export const parseTranscript = (
7878
tempSchools.push({ value: "BSE", label: "Engineering BSE" });
7979
else tempSchools.push({ value: "BAS", label: "Engineering BAS" });
8080
}
81-
82-
// TODO: Ensure these are right!
8381
if (program.includes("wharton"))
8482
tempSchools.push({ value: "BS", label: "Wharton" });
8583
if (program.includes("nursing"))
@@ -117,31 +115,60 @@ export const parseTranscript = (
117115
}
118116

119117
// SCRAPE COURSES (BY SEM)
118+
let firstNonSummerSemReached = false;
119+
120+
let courseToSem: { [key: string]: string } = {};
121+
120122
if (textResult[l].includes("institution credit")) {
121123
let truncatedTranscript = textResult.slice(parseInt(l) + 1);
122124
let currentSem = "";
123125
for (let line of truncatedTranscript) {
124126
if (/(fall|spring|summer)\s\d{4}/i.test(line)) {
125127
currentSem = line;
126-
separatedCourses[currentSem] = [];
128+
if (!firstNonSummerSemReached && !currentSem.includes("summer")) {
129+
firstNonSummerSemReached = true;
130+
}
131+
// Only start creating sems after first non-summer semester is reached
132+
if (firstNonSummerSemReached) {
133+
separatedCourses[currentSem] = [];
134+
}
127135
} else {
128136
let courseMatch = line.match(/\b\w+\s\d{3,4}\b/);
129-
137+
130138
if (courseMatch) {
131-
// Check if course didn't get an F or a W. If current sem's courses are empty, remove sem key from separatedCourses
132-
if (
133-
(line[line.length - 1] == "f" || line[line.length - 1] == "w") &&
134-
separatedCourses[currentSem].length == 0
135-
) {
136-
delete separatedCourses[currentSem];
137-
} else {
138-
separatedCourses[currentSem].push(courseMatch[0]);
139+
// Check if course didn't get an F or a W. If so, add to current sem or _TRAN
140+
if (!(line[line.length - 1] == "f" || line[line.length - 1] == "w")) {
141+
// TODO: We don't yet have a way to track courses that can be taken multiple times,
142+
// so we store a course that appears multiple times only in the most recent semester it appears in.
143+
if (courseMatch[0] in courseToSem) {
144+
const prevSem = courseToSem[courseMatch[0]];
145+
separatedCourses[currentSem].push(courseMatch[0]);
146+
courseToSem[courseMatch[0]] = currentSem;
147+
separatedCourses[prevSem] = separatedCourses[prevSem].filter((c: string) => c !== courseMatch[0]);
148+
} else {
149+
// Add all pre-college courses to _TRAN semester
150+
if (firstNonSummerSemReached) {
151+
separatedCourses[currentSem].push(courseMatch[0]);
152+
courseToSem[courseMatch[0]] = currentSem;
153+
} else {
154+
separatedCourses["_TRAN"].push(courseMatch[0]);
155+
courseToSem[courseMatch[0]] = "_TRAN";
156+
}
157+
}
139158
}
140159
}
141160
}
142161
}
162+
163+
// Remove any empty semesters (handles edge case where user fails/withdraws from all courses in a semester)
164+
for (let sem of Object.keys(separatedCourses)) {
165+
if (separatedCourses[sem].length == 0) {
166+
delete separatedCourses[sem];
167+
}
168+
}
169+
143170
separatedCourses = Object.keys(separatedCourses).map(
144-
(key) => [{ sem: key, courses: separatedCourses[key] }][0]
171+
(key) => ({ sem: key, courses: separatedCourses[key] })
145172
);
146173

147174
// SCRAPE START YEAR AND INFER GRAD YEAR

0 commit comments

Comments
 (0)