@@ -68,6 +68,13 @@ export interface OfferingList {
6868 offerings : Offering [ ] ;
6969}
7070
71+ export interface CategorizedOfferingList {
72+ course_id : number ;
73+ category : 'LEC' | 'TUT' | 'PRA'
74+ offerings : Offering [ ] ;
75+ }
76+
77+
7178// Function to fetch offerings from the database for a given course and semester
7279export async function getOfferings ( course_id : number , semester : string ) {
7380 let { data : offeringData , error : offeringError } =
@@ -107,6 +114,19 @@ export const filterValidOfferings = (
107114 return offerings . filter ( f ) ;
108115} ;
109116
117+ // Function to get the maximum number of days allowed based on restrictions
118+ export async function getMaxDays ( restrictions : Restriction [ ] ) {
119+ for ( const restriction of restrictions ) {
120+ if ( restriction . disabled ) continue ;
121+ if ( restriction . type == RestrictionType . RestrictDaysOff ) {
122+ return 5 -
123+ restriction
124+ . numDays ; // Subtract the restricted days from the total days
125+ }
126+ }
127+ return 5 ; // Default to 5 days if no restrictions
128+ }
129+
110130// Function to check if an offering satisfies the restrictions
111131export function isValidOffering (
112132 offering : Offering ,
@@ -147,19 +167,6 @@ export function isValidOffering(
147167 return true ;
148168}
149169
150- // Function to get the maximum number of days allowed based on restrictions
151- export async function getMaxDays ( restrictions : Restriction [ ] ) {
152- for ( const restriction of restrictions ) {
153- if ( restriction . disabled ) continue ;
154- if ( restriction . type == RestrictionType . RestrictDaysOff ) {
155- return 5 -
156- restriction
157- . numDays ; // Subtract the restricted days from the total days
158- }
159- }
160- return 5 ; // Default to 5 days if no restrictions
161- }
162-
163170// Function to get valid offerings by filtering them based on the restrictions
164171export async function getValidOfferings (
165172 offerings : Offering [ ] ,
@@ -171,6 +178,46 @@ export async function getValidOfferings(
171178 ) ;
172179}
173180
181+ export async function categorizeValidOfferings ( offerings : OfferingList [ ] ) {
182+ const lst : CategorizedOfferingList [ ] = [ ] ;
183+
184+ for ( const offering of offerings ) {
185+ const lectures : CategorizedOfferingList = {
186+ course_id : offering . course_id ,
187+ category : 'LEC' ,
188+ offerings : [ ]
189+ } ;
190+ const tutorials : CategorizedOfferingList = {
191+ course_id : offering . course_id ,
192+ category : 'TUT' ,
193+ offerings : [ ]
194+ } ;
195+ const practicals : CategorizedOfferingList = {
196+ course_id : offering . course_id ,
197+ category : 'PRA' ,
198+ offerings : [ ]
199+ }
200+
201+ for ( const entry of offering . offerings ) {
202+ const meeting_section = entry . meeting_section ;
203+ if ( meeting_section . startsWith ( 'PRA' ) ) {
204+ practicals . offerings . push ( entry ) ;
205+ } else if ( meeting_section . startsWith ( 'TUT' ) ) {
206+ tutorials . offerings . push ( entry ) ;
207+ } else {
208+ lectures . offerings . push ( entry ) ;
209+ }
210+ }
211+
212+ for ( const x of [ lectures , practicals , tutorials ] ) {
213+ if ( x . offerings . length > 0 ) {
214+ lst . push ( x ) ;
215+ }
216+ }
217+ }
218+ return lst ;
219+ }
220+
174221// Function to check if an offering can be inserted into the current list of
175222// offerings without conflicts
176223export async function canInsert ( toInsert : Offering , curList : Offering [ ] ) {
@@ -199,7 +246,7 @@ export function getFrequencyTable(arr: Offering[]): Map<string, number> {
199246// Function to generate all valid schedules based on offerings and restrictions
200247export async function getValidSchedules (
201248 validSchedules : Offering [ ] [ ] ,
202- courseOfferingsList : OfferingList [ ] ,
249+ courseOfferingsList : CategorizedOfferingList [ ] ,
203250 curList : Offering [ ] ,
204251 cur : number ,
205252 len : number ,
@@ -269,20 +316,25 @@ export default {
269316 }
270317
271318 // Log course offerings (for debugging purposes)
272- validCourseOfferingsList . forEach (
319+ /* validCourseOfferingsList.forEach(
273320 (course) => console.log(JSON.stringify(course, null, 2)),
274- ) ;
321+ );*/
322+
323+ const categorizedOfferings =
324+ await categorizeValidOfferings ( validCourseOfferingsList ) ;
325+ // console.log(typeof categorizedOfferings);
326+ // console.log(JSON.stringify(categorizedOfferings, null, 2));
275327
276328
277329 const validSchedules : Offering [ ] [ ] = [ ] ;
278330
279331 // Generate valid schedules for the given courses and restrictions
280332 await getValidSchedules (
281333 validSchedules ,
282- validCourseOfferingsList ,
334+ categorizedOfferings ,
283335 [ ] ,
284336 0 ,
285- validCourseOfferingsList . length ,
337+ categorizedOfferings . length ,
286338 maxdays ,
287339 ) ;
288340
0 commit comments