Skip to content

Commit f5b5af3

Browse files
authored
[PDP] Address transcript parser edge cases (#755)
Addresses the following edge cases: - correctly counting pre-college summer courses - ignoring all failed/withdrawn courses - handling courses that can be taken multiple times (temporary workaround - we only consider the most recent semester in which the course was taken) Also, refactored the parseTranscript function in parseUtils for readability
1 parent f858d5b commit f5b5af3

File tree

4 files changed

+219
-116
lines changed

4 files changed

+219
-116
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ pcr-backup*
2424
./Pipfile.lock
2525
./package.json
2626
./yarn.lock
27-
.tool-versions
27+
.tool-versions

frontend/degree-plan/components/OnboardingPanels/CreateWithTranscriptPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default function CreateWithTranscriptPanel({
204204
const graduationYearOptions = getYearOptions()?.gradYears;
205205

206206
const majorOptionsCallback = useCallback(() => {
207-
const majorOptions = getMajorOptions(degrees, schools, startingYear);
207+
const majorOptions = getMajorOptions(degrees, schools, startingYear?.value ?? null);
208208
return majorOptions;
209209
}, [schools, startingYear]);
210210

frontend/degree-plan/pages/OnboardingPage.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { polyfillPromiseWithResolvers } from "./polyfilsResolver";
99

1010
import "core-js/full/promise/with-resolvers.js";
1111

12-
import { parseItems, parseTranscript } from "../utils/parseUtils";
12+
import { parseItems, parseTranscript, ParsedText, flattenParsedText } from "../utils/parseUtils";
1313
import WelcomeLayout from "@/components/OnboardingPanels/WelcomePanel";
1414
import CreateWithTranscriptPanel from "@/components/OnboardingPanels/CreateWithTranscriptPanel";
15+
1516
polyfillPromiseWithResolvers();
1617

1718
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`;
@@ -44,24 +45,26 @@ const OnboardingPage = ({
4445
>(`/api/degree/degrees`);
4546

4647
// TRANSCRIPT PARSING
47-
const total = useRef<any>({});
48+
const total = useRef<Record<number, ParsedText[]>>({});
4849
const addText = (items: any[], index: number) => {
49-
const allText: any = parseItems(items, index);
50-
let textResult = [];
51-
for (let col in allText) {
52-
let poses = Object.keys(allText[col]).reverse();
53-
for (let i in poses) {
54-
textResult.push(allText[col][poses[i]].join("").toLowerCase());
55-
}
56-
total.current[index] = textResult;
57-
}
50+
const parsed = parseItems(items);
51+
total.current[index] = total.current[index] ?? [];
52+
total.current[index].push(parsed);
5853

5954
// If all pages have been read, begin to parse text from transcript
6055
if (Object.keys(total.current).length === numPages) {
61-
let all: any = [];
62-
for (let key in Object.keys(total.current).sort()) {
63-
all = all.concat(total.current[key]);
64-
}
56+
let all: string[] = [];
57+
const sortedPageIndexes = Object.keys(total.current)
58+
.map((key) => Number(key))
59+
.sort((a, b) => a - b);
60+
61+
sortedPageIndexes.forEach((pageIndex) => {
62+
const pageEntries = total.current[pageIndex];
63+
if (!pageEntries) return;
64+
pageEntries.forEach((pageText) => {
65+
all = all.concat(flattenParsedText(pageText));
66+
});
67+
});
6568

6669
const {
6770
scrapedCourses,

0 commit comments

Comments
 (0)