From 4f81c53894f1be1612b3e2afd4a70b82a9b1da5a Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Tue, 12 Mar 2024 00:10:42 -0500 Subject: [PATCH 1/2] feat: added scrapedAt property --- .github/workflows/check-types.yml | 24 +++++++++++++++++++ package.json | 3 ++- src/shared/types/Course.ts | 5 ++++ .../ConflictsWithWarning.stories.tsx | 2 ++ src/stories/components/List.stories.tsx | 1 + .../components/PopupCourseBlock.stories.tsx | 1 + .../calendar/CalendarBottomBar.stories.tsx | 2 ++ .../calendar/CalendarCourse.stories.tsx | 1 + .../calendar/CalendarSchedules.stories.tsx | 3 +++ src/stories/injected/mocked.ts | 3 +++ src/views/lib/CourseCatalogScraper.ts | 1 + 11 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-types.yml diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml new file mode 100644 index 000000000..7911973a8 --- /dev/null +++ b/.github/workflows/check-types.yml @@ -0,0 +1,24 @@ +name: Type Check + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: 8 + + - name: Install dependencies + run: pnpm install + + - name: Run tests + run: pnpm run check-types diff --git a/package.json b/package.json index f4a46c74f..262de02ef 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "prettier:fix": "prettier src --write", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives", "lint:fix": "eslint src --ext ts,tsx --report-unused-disable-directives --fix", + "check-types": "tsc --noEmit", "test": "vitest", "test:ui": "vitest --ui", "coverage": "vitest run --coverage", @@ -116,4 +117,4 @@ "es-module-lexer": "^1.4.1" } } -} +} \ No newline at end of file diff --git a/src/shared/types/Course.ts b/src/shared/types/Course.ts index c13b27336..62b42bfac 100644 --- a/src/shared/types/Course.ts +++ b/src/shared/types/Course.ts @@ -73,11 +73,16 @@ export class Course { instructionMode: InstructionMode; /** Which semester is the course from */ semester: Semester; + /** Unix timestamp of when the course was last scraped */ + scrapedAt: number; constructor(course: Serialized) { Object.assign(this, course); this.schedule = new CourseSchedule(course.schedule); this.instructors = course.instructors.map(i => new Instructor(i)); + if (!course.scrapedAt) { + this.scrapedAt = Date.now(); + } } /** diff --git a/src/stories/components/ConflictsWithWarning.stories.tsx b/src/stories/components/ConflictsWithWarning.stories.tsx index b62c347c4..f7543e1c1 100644 --- a/src/stories/components/ConflictsWithWarning.stories.tsx +++ b/src/stories/components/ConflictsWithWarning.stories.tsx @@ -44,6 +44,7 @@ export const ExampleCourse: Course = new Course({ status: Status.WAITLISTED, uniqueId: 12345, url: 'https://utdirect.utexas.edu/apps/registrar/course_schedule/20242/12345/', + scrapedAt: Date.now(), }); export const ExampleCourse2: Course = new Course({ courseName: 'PRINCIPLES OF COMPUTER SYSTEMS', @@ -90,6 +91,7 @@ export const ExampleCourse2: Course = new Course({ status: Status.WAITLISTED, uniqueId: 67890, url: 'https://utdirect.utexas.edu/apps/registrar/course_schedule/20242/12345/', + scrapedAt: Date.now(), }); const meta = { diff --git a/src/stories/components/List.stories.tsx b/src/stories/components/List.stories.tsx index 3e8646f99..8666e5df2 100644 --- a/src/stories/components/List.stories.tsx +++ b/src/stories/components/List.stories.tsx @@ -25,6 +25,7 @@ const generateCourses = (count: number): Course[] => { courseName: 'ELEMS OF COMPTRS/PROGRAMMNG-WB', creditHours: 3, department: 'C S', + scrapedAt: Date.now(), description: [ 'Problem solving and fundamental algorithms for various applications in science, business, and on the World Wide Web, and introductory programming in a modern object-oriented programming language.', 'Only one of the following may be counted: Computer Science 303E, 312, 312H. Credit for Computer Science 303E may not be earned after a student has received credit for Computer Science 314, or 314H. May not be counted toward a degree in computer science.', diff --git a/src/stories/components/PopupCourseBlock.stories.tsx b/src/stories/components/PopupCourseBlock.stories.tsx index 60b848fe8..8b9a9733f 100644 --- a/src/stories/components/PopupCourseBlock.stories.tsx +++ b/src/stories/components/PopupCourseBlock.stories.tsx @@ -17,6 +17,7 @@ export const ExampleCourse: Course = new Course({ courseName: 'ELEMS OF COMPTRS/PROGRAMMNG-WB', creditHours: 3, department: 'C S', + scrapedAt: Date.now(), description: [ 'Problem solving and fundamental algorithms for various applications in science, business, and on the World Wide Web, and introductory programming in a modern object-oriented programming language.', 'Only one of the following may be counted: Computer Science 303E, 312, 312H. Credit for Computer Science 303E may not be earned after a student has received credit for Computer Science 314, or 314H. May not be counted toward a degree in computer science.', diff --git a/src/stories/components/calendar/CalendarBottomBar.stories.tsx b/src/stories/components/calendar/CalendarBottomBar.stories.tsx index f0a895443..81d754acf 100644 --- a/src/stories/components/calendar/CalendarBottomBar.stories.tsx +++ b/src/stories/components/calendar/CalendarBottomBar.stories.tsx @@ -25,6 +25,7 @@ const exampleGovCourse: Course = new Course({ schedule: { meetings: [], }, + scrapedAt: Date.now(), semester: { code: '12345', season: 'Spring', @@ -43,6 +44,7 @@ const examplePsyCourse: Course = new Course({ flags: ['no flag for you >:)'], fullName: 'PSY 317L Yada yada', instructionMode: 'Online', + scrapedAt: Date.now(), instructors: [ new Instructor({ firstName: 'Bevo', diff --git a/src/stories/components/calendar/CalendarCourse.stories.tsx b/src/stories/components/calendar/CalendarCourse.stories.tsx index b5688ef94..519b76aed 100644 --- a/src/stories/components/calendar/CalendarCourse.stories.tsx +++ b/src/stories/components/calendar/CalendarCourse.stories.tsx @@ -55,6 +55,7 @@ export const Default: Story = { year: 2024, season: 'Spring', }, + scrapedAt: Date.now(), }), meetingIdx: 0, color: 'red', diff --git a/src/stories/components/calendar/CalendarSchedules.stories.tsx b/src/stories/components/calendar/CalendarSchedules.stories.tsx index ae635977f..72ffe43d1 100644 --- a/src/stories/components/calendar/CalendarSchedules.stories.tsx +++ b/src/stories/components/calendar/CalendarSchedules.stories.tsx @@ -61,6 +61,7 @@ const schedules = [ year: 2024, season: 'Fall', }, + scrapedAt: Date.now(), }), ], name: 'Main Schedule', @@ -98,6 +99,7 @@ const schedules = [ year: 2024, season: 'Spring', }, + scrapedAt: Date.now(), }), new Course({ uniqueId: 123, @@ -129,6 +131,7 @@ const schedules = [ year: 2024, season: 'Fall', }, + scrapedAt: Date.now(), }), ], name: 'Backup #3', diff --git a/src/stories/injected/mocked.ts b/src/stories/injected/mocked.ts index f59d00806..3b6a31b06 100644 --- a/src/stories/injected/mocked.ts +++ b/src/stories/injected/mocked.ts @@ -17,6 +17,7 @@ export const exampleCourse: Course = new Course({ flags: ['Quantitative Reasoning'], fullName: 'C S 303E ELEMS OF COMPTRS/PROGRAMMNG-WB', instructionMode: 'Online', + scrapedAt: Date.now(), instructors: [ new Instructor({ firstName: 'William', @@ -100,6 +101,7 @@ export const bevoCourse: Course = new Course({ year: 2024, season: 'Spring', }, + scrapedAt: Date.now(), }); export const bevoScheule: UserSchedule = new UserSchedule({ @@ -151,6 +153,7 @@ export const MikeScottCS314Course: Course = new Course({ year: 2024, season: 'Spring', }, + scrapedAt: Date.now(), }); export const MikeScottCS314Schedule: UserSchedule = new UserSchedule({ diff --git a/src/views/lib/CourseCatalogScraper.ts b/src/views/lib/CourseCatalogScraper.ts index fce12ad20..6965dab5b 100644 --- a/src/views/lib/CourseCatalogScraper.ts +++ b/src/views/lib/CourseCatalogScraper.ts @@ -92,6 +92,7 @@ export class CourseCatalogScraper { instructors: this.getInstructors(row) as Instructor[], description: this.getDescription(document), semester: this.getSemester(), + scrapedAt: Date.now(), }); courses.push({ element: row, From 738e5b5ae0b10180831a54c3169b74bbea7473e9 Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Tue, 12 Mar 2024 00:24:06 -0500 Subject: [PATCH 2/2] fix: type-check --- .github/workflows/check-types.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml index 7911973a8..3ebfe4887 100644 --- a/.github/workflows/check-types.yml +++ b/.github/workflows/check-types.yml @@ -3,7 +3,7 @@ name: Type Check on: [push, pull_request] jobs: - test: + type-check: runs-on: ubuntu-latest steps: