Skip to content
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
277 changes: 0 additions & 277 deletions Constants/Teacher's chromo.json

This file was deleted.

28 changes: 19 additions & 9 deletions Constants/Teachers_tt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ def __init__(self):
def generate_teacher_timetable(self, chromosome):
"""
Populate the teacher's timetable based on the provided chromosome schedule.
Now includes the course (Week 1, Week 2, etc.) information.
Create a dictionary to store all data for the timetable and return it.
"""
# Dictionary to hold the full timetable
timetable_dict = {
teacher: {day: [] for day in WorkingDays.days}
for teachers in SubjectTeacherMap.subject_teacher_map.values()
for teacher in teachers
}

for week, days in chromosome.items():
for day, sections in days.items():
for section, classes in sections.items():
Expand All @@ -30,7 +37,7 @@ def generate_teacher_timetable(self, chromosome):
continue # Skip this assignment if there's a conflict

# Add the class to the teacher's timetable
self.teacher_timetable[teacher_id][day].append({
timetable_dict[teacher_id][day].append({
"course": week, # Include course information (Week 1, Week 2)
"section": section,
"subject_id": subject_id,
Expand All @@ -49,9 +56,9 @@ def generate_teacher_timetable(self, chromosome):
"day": day
}

# Debug: Ensure each teacher is assigned a class
if teacher_id not in self.teacher_timetable:
print(f"Teacher {teacher_id} has no classes assigned.")
# Update the class-level timetable
self.teacher_timetable = timetable_dict
return timetable_dict

def save_timetable_to_json(self, file_path="Constants/teacher_timetable.json"):
"""
Expand All @@ -63,7 +70,6 @@ def save_timetable_to_json(self, file_path="Constants/teacher_timetable.json"):
except Exception as e:
print(f"Error saving timetable to '{file_path}': {e}")


if __name__ == "__main__":
teacher_timetable = TeacherTimetable()

Expand All @@ -73,7 +79,11 @@ def save_timetable_to_json(self, file_path="Constants/teacher_timetable.json"):
"Week 1": SampleChromosome.schedule1
}

teacher_timetable.generate_teacher_timetable(w)
# Generate the timetable and get it as a dictionary
timetable_dict = teacher_timetable.generate_teacher_timetable(w)

# Save the timetable to a JSON file
teacher_timetable.save_timetable_to_json()

# Save timetable to a JSON file
teacher_timetable.save_timetable_to_json()
# Return the timetable dictionary (optional, for further use)
timetable_dict
Loading