Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 misc improvements
Browse files Browse the repository at this point in the history
Co-authored-by: Aponia <[email protected]>
  • Loading branch information
ecxyzzy and ap0nia committed Jan 10, 2024
1 parent 7eccbc2 commit 7c510ee
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 55 deletions.
8 changes: 4 additions & 4 deletions apps/api/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export function normalizeCourse(course: PrismaCourse): Course {
...course,
courseLevel,
instructorHistory: course.instructorHistory,
instructors: course.instructors as unknown as InstructorPreview[],
prerequisiteTree: course.prerequisiteTree as unknown as PrerequisiteTree,
instructors: course.instructors as InstructorPreview[],
prerequisiteTree: course.prerequisiteTree as PrerequisiteTree,
prerequisiteList: course.prerequisiteList,
prerequisiteFor: course.prerequisiteFor,
prerequisites: course.prerequisites as unknown as CoursePreview[],
dependencies: course.dependencies as unknown as CoursePreview[],
prerequisites: course.prerequisites as CoursePreview[],
dependencies: course.dependencies as CoursePreview[],
geList,
terms: course.terms,
};
Expand Down
84 changes: 39 additions & 45 deletions tools/registrar-scraper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,51 +56,45 @@ async function main() {
const instructors = Object.fromEntries(
(await prisma.instructor.findMany()).map((x) => [x.ucinetid, x]),
);
const newCourses = [];
for (const course of Object.values(courses)) {
newCourses.push({
...course,
prerequisiteTree: course.prerequisiteTree as object,
instructors: course.instructorHistory
.map((x) => instructors[x])
.filter((x) => x)
.map(({ ucinetid, name, shortenedName }) => ({ ucinetid, name, shortenedName })),
prerequisites: course.prerequisiteList
.map((x) => courses[x.replace(/ /g, "")])
.filter((x) => x)
.map(({ id, title, department, courseNumber }) => ({
id,
title,
department,
courseNumber,
})),
dependencies: course.prerequisiteFor
.map((x) => courses[x.replace(/ /g, "")])
.filter((x) => x)
.map(({ id, title, department, courseNumber }) => ({
id,
title,
department,
courseNumber,
})),
});
}
const newInstructors = [];
for (const instructor of Object.values(instructors)) {
newInstructors.push({
...instructor,
courseHistory: instructor.courseHistory as object,
courses: Object.keys(instructor.courseHistory!)
.map((x) => courses[x.replace(/ /g, "")])
.filter((x) => x)
.map(({ id, title, department, courseNumber }) => ({
id,
title,
department,
courseNumber,
})),
});
}
const newCourses = Object.values(courses).map((course) => ({
...course,
prerequisiteTree: course.prerequisiteTree as object,
instructors: course.instructorHistory
.map((x) => instructors[x])
.filter((x) => x)
.map(({ ucinetid, name, shortenedName }) => ({ ucinetid, name, shortenedName })),
prerequisites: course.prerequisiteList
.map((x) => courses[x.replace(/ /g, "")])
.filter((x) => x)
.map(({ id, title, department, courseNumber }) => ({
id,
title,
department,
courseNumber,
})),
dependencies: course.prerequisiteFor
.map((x) => courses[x.replace(/ /g, "")])
.filter((x) => x)
.map(({ id, title, department, courseNumber }) => ({
id,
title,
department,
courseNumber,
})),
}));
const newInstructors = Object.values(instructors).map((instructor) => ({
...instructor,
courseHistory: instructor.courseHistory as object,
courses: Object.keys(instructor.courseHistory!)
.map((x) => courses[x.replace(/ /g, "")])
.filter((x) => x)
.map(({ id, title, department, courseNumber }) => ({
id,
title,
department,
courseNumber,
})),
}));
await prisma.$transaction([
prisma.course.deleteMany({ where: { id: { in: Object.keys(courses) } } }),
prisma.instructor.deleteMany({ where: { ucinetid: { in: Object.keys(instructors) } } }),
Expand Down
12 changes: 6 additions & 6 deletions tools/registrar-scraper/src/instructor-scraper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type InstructorsData = {
log: InstructorsLog;
};

type InstructorsInfo = {
[ucinetid: string]: Omit<Instructor, "courses">;
};
type ScrapedInstructor = Omit<Instructor, "courses">;

type InstructorsInfo = Record<string, ScrapedInstructor>;

type InstructorsLog = {
[key: string]:
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function getInstructors(
}
});
});
const instructorPromises: Promise<[string, Omit<Instructor, "courses">]>[] = [];
const instructorPromises: Promise<[string, ScrapedInstructor]>[] = [];
Object.keys(instructorsDict).forEach((name) => {
const schools = instructorsDict[name].schools;
const related_departments = Array.from(instructorsDict[name].courses);
Expand Down Expand Up @@ -214,9 +214,9 @@ async function getInstructor(
relatedDepartments: string[],
attempts: number,
year_threshold: number,
): Promise<[string, Omit<Instructor, "courses">]> {
): Promise<[string, ScrapedInstructor]> {
logger.info(`Scraping data for ${instructorName}`);
const instructorObject: Omit<Instructor, "courses"> = {
const instructorObject: ScrapedInstructor = {
name: instructorName,
ucinetid: "",
title: "",
Expand Down

0 comments on commit 7c510ee

Please sign in to comment.