From 6982d3257f07e4e2f2737d42756a815d7c68b643 Mon Sep 17 00:00:00 2001 From: Minh Nguyen <64875104+MinhxNguyen7@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:23:07 +0000 Subject: [PATCH] Less random class times --- .../src/lib/tourExampleGeneration.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/antalmanac/src/lib/tourExampleGeneration.ts b/apps/antalmanac/src/lib/tourExampleGeneration.ts index a18f1b92d..941e68c92 100644 --- a/apps/antalmanac/src/lib/tourExampleGeneration.ts +++ b/apps/antalmanac/src/lib/tourExampleGeneration.ts @@ -14,7 +14,7 @@ let sampleClassesSectionCodes: Array = []; export function addSampleClasses() { if (AppStore.getAddedCourses().length > 0) return; - const sampleClasses: Array = [ + const sampleClassesOptions: sampleClassOptions[] = [ { courseTitle: 'Nice', deptCode: 'GEN&SEX', @@ -53,7 +53,9 @@ export function addSampleClasses() { }, ], }, - ].map(sampleClassFactory); + ]; + + const sampleClasses: Array = sampleClassesOptions.map(sampleClassFactory); sampleClasses.forEach((sampleClass) => { AppStore.addCourse(sampleClass); @@ -81,6 +83,15 @@ function randomClasstime(): HourMinute { }; } +function randomStartEndTime(duration: number): [HourMinute, HourMinute] { + const start = randomClasstime(); + const end = { + hour: start.hour + duration / 60, + minute: start.minute + (duration % 60), + }; + return [start, end]; +} + export function sampleMeetingsFactory({ bldg = ['DBH 1200'], days = 'MWF', @@ -93,7 +104,7 @@ export function sampleMeetingsFactory({ minute: 50, }, timeIsTBA = false, -}: Partial) { +}: Partial): WebsocSectionMeeting[] { return [ { bldg, @@ -131,13 +142,17 @@ export function sampleFinalExamFactory({ bldg, }; + const [randomStartTime, randomEndTime] = randomStartEndTime(120); + startTime = startTime ?? randomStartTime; + endTime = endTime ?? randomEndTime; + return { examStatus, dayOfWeek: dayOfWeek ?? randomWeekday(), month, day, - startTime: startTime ?? randomClasstime(), - endTime: endTime ?? randomClasstime(), + startTime: startTime, + endTime: endTime, bldg, }; }