Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions website/api/optimiser/_modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,50 +151,22 @@ func mergeAndFilterModuleSlots(timetable []models.ModuleSlot, venues map[string]
}
}

/*
Now merge all slots of the same lessonType, slot, startTime, weeks and building
We are doing this to avoid unnecessary calculations & reduce search space
*/

mergedTimetable := make(map[string]map[string][]models.ModuleSlot) // Lesson Type -> Class No -> []ModuleSlot
seenCombinations := make(map[string]bool)

lessonsMap := make(map[string]map[string][]models.ModuleSlot) // Lesson Type -> Class No -> []ModuleSlot
for _, slots := range validClassGroups {
for _, slot := range slots {

if !constants.E_Venues[slot.Venue] {
buildingName := extractBuildingName(slot.Venue)

combinationKey := slot.LessonType + "|" + slot.Day + "|" + slot.StartTime + "|" + buildingName + "|" + slot.WeeksString

if seenCombinations[combinationKey] {
continue
}
seenCombinations[combinationKey] = true
}

if mergedTimetable[slot.LessonType] == nil {
mergedTimetable[slot.LessonType] = make(map[string][]models.ModuleSlot)
if lessonsMap[slot.LessonType] == nil {
lessonsMap[slot.LessonType] = make(map[string][]models.ModuleSlot)
}

mergedTimetable[slot.LessonType][slot.ClassNo] = append(mergedTimetable[slot.LessonType][slot.ClassNo], slot)
lessonsMap[slot.LessonType][slot.ClassNo] = append(lessonsMap[slot.LessonType][slot.ClassNo], slot)
}
}

return mergedTimetable
return lessonsMap
}

// Helper functions

/*
Extract the building name from the venue name.
Returns the part before '-' or the whole key if '-' is absent
*/
func extractBuildingName(key string) string {
parts := strings.SplitN(key, "-", 2)
return parts[0]
}

/*
Check if the slot's timing falls outside the specified earliest and latest times
*/
Expand Down