Skip to content

Commit

Permalink
feature: added faculty to the courseInfo scraped (#152)
Browse files Browse the repository at this point in the history
* feature: added faculty to the courseInfo scraped

* fix: updated api endpoint to send faculty data and fixed scraper logic for extracting faculty data

* fix: updated chunk-scraper to send faculty data

* fix imports to be sorted in alphabetical order

---------

Co-authored-by: Chanel <z5416986@ad.unsw.edu.au>
Co-authored-by: Shaam <shaamjevan.sj@gmail.com>
  • Loading branch information
3 people committed Jun 3, 2024
1 parent 99a6bb4 commit c31be22
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/src/notangles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const getCourseList = (req: express.Request, res: express.Response) => {
career: termCourses[i].career,
online: false,
inPerson: false,
faculty: termCourses[i].faculty,
};

const classes = termCourses[i].classes;
Expand Down
2 changes: 1 addition & 1 deletion data/data.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions scraper/src/page-scraper/chunk-scraper/CourseInfo.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Chunk, CourseInfo } from "../../scraper-helpers/interfaces";

import { isCensusDate } from "./chunk-helpers/IsCensusDate";
import { isTerm } from "./chunk-helpers/IsTerm";
import { getSchool } from "./chunk-helpers/GetSchool";
import { getCampusLocation } from "./chunk-helpers/GetCampusLocation";
import { getCareer } from "./chunk-helpers/GetCareer";
import { getFaculty } from "./chunk-helpers/GetFaculty";
import { getSchool } from "./chunk-helpers/GetSchool";
import { isCensusDate } from "./chunk-helpers/IsCensusDate";
import { isTerm } from "./chunk-helpers/IsTerm";

/**
* @interface: Indices of all the data that can be extracted from the courseInfo chunk
*/
interface CourseInfoIndices {
facultyIndex?: number;
facultyIndex: number;
schoolIndex: number;
onlineHandbookRecordIndex?: number;
campusIndex: number;
Expand All @@ -20,9 +20,9 @@ interface CourseInfoIndices {

/**
* @constant { CourseInfoIndices }: Default indices which represent which index to grab data from.
* The schoolIndex is not 0 because there is a column for an &nbsp in the table
*/
const defaultParseIndices: CourseInfoIndices = {
facultyIndex: 0,
schoolIndex: 1,
campusIndex: 3,
careerIndex: 4,
Expand Down Expand Up @@ -53,6 +53,7 @@ const parseCourseInfoChunk = ({
const school = getSchool(data[parseIndices.schoolIndex]);
const campus = getCampusLocation(data[parseIndices.campusIndex]);
const career = getCareer(data[parseIndices.careerIndex]);
const faculty = getFaculty(data[parseIndices.facultyIndex]);

let index = parseIndices.nextParseIndex;
const termsOffered: string[] = [];
Expand All @@ -73,6 +74,7 @@ const parseCourseInfoChunk = ({

const courseInfo: CourseInfo = {
school,
faculty,
campus,
career,
termsOffered,
Expand Down
15 changes: 15 additions & 0 deletions scraper/src/page-scraper/chunk-scraper/chunk-helpers/GetFaculty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Extracts the name of the faculty that offers the course that is being parsed
* @param faculty: Line that contains data about the faculty field
* @returns { string }: The faculty that offers the current course
*/
const getFaculty = (faculty: string): string => {
// Faculty is a string
if (!faculty || faculty === " ") {
console.error(new Error(`Invalid Faculty: ${faculty}`));
}

return faculty;
};

export { getFaculty };
1 change: 1 addition & 0 deletions scraper/src/scraper-helpers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ interface CourseHead {
*/
interface CourseInfo {
school: string;
faculty: string;
campus: string;
career: string;
censusDates: string[];
Expand Down

0 comments on commit c31be22

Please sign in to comment.