Skip to content

Commit 8a27676

Browse files
fix(web): degree report course title parsing (#96)
Co-authored-by: Chenxin Yan <[email protected]>
1 parent f6936d1 commit 8a27676

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

apps/web/src/modules/report-parsing/components/degree-progress-upload.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ export default function DegreeProgreeUpload({
8888
// Extract and parse course history
8989
try {
9090
const historyText = await extractCourseHistory(file);
91+
9192
const courses = parseCourseHistory(historyText);
93+
9294
const userCourses = transformToUserCourses(courses);
9395

9496
// Store parsed courses and open confirmation modal

apps/web/src/modules/report-parsing/utils/transform-to-user-courses.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,28 @@ export function transformToUserCourses(
7777
const { year, term } = normalizeTerm(course.term);
7878
const courseCode = `${course.subject} ${course.catalogNumber}`;
7979

80+
let title = course.title.trim();
81+
82+
if (title.endsWith(":")) {
83+
title = title.slice(0, -1).trim();
84+
}
85+
86+
if (course.meta?.CourseTopic) {
87+
let topic = course.meta.CourseTopic.trim();
88+
topic = topic.replace(/^\s*\d+\s*-\s*/, "").trim();
89+
90+
if (topic) {
91+
if (title.includes(":")) {
92+
title = `${title} - ${topic}`;
93+
} else {
94+
title = `${title}: ${topic}`;
95+
}
96+
}
97+
}
98+
8099
const userCourse: UserCourse = {
81100
courseCode,
82-
title: course.title,
101+
title: title,
83102
year,
84103
term,
85104
};

0 commit comments

Comments
 (0)