Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merged slot for lab while fetching timetable #36

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
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
63 changes: 42 additions & 21 deletions vitty-backend-api/internal/models/timetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ func (t Timetable) GetDaySlots(day time.Weekday) map[string][]Slot {
resp := make(map[string][]Slot)
var data []Slot
daySlots := DailySlots[day.String()]
labSlot := ""

var err error
// Theory slots
for _, slot := range t.Slots {

if slot.Type == "Theory" && slices.Contains(daySlots["Theory"], slot.Slot) {
index := slices.Index(daySlots["Theory"], slot.Slot)
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].StartTime, time.Local)
Expand All @@ -51,19 +53,27 @@ func (t Timetable) GetDaySlots(day time.Weekday) map[string][]Slot {
data = append(data, slot)
} else if slot.Type == "Lab" && slices.Contains(daySlots["Lab"], slot.Slot) {
index := slices.Index(daySlots["Lab"], slot.Slot)
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}

slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)
if labSlot == "" {
labSlot += slot.Slot + "+"
continue
} else {
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index-1].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}

if err != nil {
log.Println("Error parsing time: ", err)
return nil
slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
slot.Slot = labSlot + slot.Slot
labSlot = ""
data = append(data, slot)
}
data = append(data, slot)

}
}
resp[day.String()] = data
Expand All @@ -72,9 +82,11 @@ func (t Timetable) GetDaySlots(day time.Weekday) map[string][]Slot {

func (t Timetable) GetDaywiseTimetable() map[string][]Slot {
resp := make(map[string][]Slot)
labSlot := ""

for _, slot := range t.Slots {
for day, value := range DailySlots {

if slices.Contains(value["Theory"], slot.Slot) {
index := slices.Index(value["Theory"], slot.Slot)
var err error
Expand All @@ -91,18 +103,27 @@ func (t Timetable) GetDaywiseTimetable() map[string][]Slot {
resp[day] = append(resp[day], slot)
} else if slices.Contains(value["Lab"], slot.Slot) {
index := slices.Index(value["Lab"], slot.Slot)
var err error
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil

if labSlot == "" {
labSlot += slot.Slot + "+"
continue
} else {
var err error
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index-1].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}

slot.Slot = labSlot + slot.Slot
labSlot = ""
resp[day] = append(resp[day], slot)
}
resp[day] = append(resp[day], slot)
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions vitty-backend-api/internal/utils/timetableDetection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ func DetectTimetable(text string) ([]TimetableSlotV1, error) {
}

if len(Slots) == 0 {
return Slots, nil
}

var err error

if err != nil {
return Slots, errors.New("error in detecting timetable")
}

Expand Down
Loading