Timetable & Scheduling Engine
Slot matrix systems, pg_advisory_xact_lock concurrency, holiday overrides, and extra class reconciliation.
Timetable & Scheduling Engine
The Attendrix Scheduling Engine transforms institutional curricula, departmental batch assignments, and room capacities into a deterministic calendar of lecture slots.
Slot occurrences cannot collide within the same physical building room for overlapping temporal windows, enforced via exclusion constraints and advisory transaction locks.
1. Matrix Slot System & Academic Hierarchy
The scheduling system models academic schedules through a hierarchy of relational entities:
flowchart TD
Sem["Semesters (Active Semester)"] --> Dept["Departments (CSE, ECE, ME)"]
Dept --> Batch["Batches (e.g. CSE_2023)"]
Batch --> BatchCourses["Batch Courses (Mandatory Core)"]
Batch --> Electives["Elective Offering Semesters (Elective Pool)"]
Slot["Slot Occurrences (Day-of-Week + Time Slot)"] --> Meetings["Course Meetings (Slot to Room Mapping)"]
BatchCourses --> Meetings
Electives --> Meetings
Meetings --> Classes["Classes (Concrete Dated Instances)"]
Overrides["Academic Calendar Overrides (Holidays, Day Shifts)"] --> ClassesSlot Identifiers
- Theory Lecture Slots:
L1,L2,L3,L4,L5(typically 50–60 minutes each). - Practical Lab Slots:
P1,P2,P3(typically 110–120 minutes continuous blocks). - Plus Slots: Dedicated supplemental slots for tutorial discussions or advanced problem-solving sessions (
is_plus_slot = true).
2. Timetable Generation & Concurrency Locking
Batch schedule generation is performed by the database procedure generate_batch_schedule. Because regenerating a timetable touches thousands of slot occurrences across multiple tables, concurrent executions could introduce severe deadlocks or slot collisions.
Advisory Transaction Locks (pg_advisory_xact_lock)
To guarantee strict serializability without table locks:
-- Compute deterministic 64-bit lock key from batch_id and semester_id
SELECT pg_advisory_xact_lock(hashtext(p_batch_id || p_semester_id::text));- Scope: The lock is scoped strictly to the current database transaction (
xact). - Zero Overhead: If a second administrator or process attempts to regenerate the schedule for the same batch simultaneously, it blocks cleanly until the active transaction commits or aborts.
- Granular Isolation: Different batches (e.g.
CSE_2023vsECE_2024) generate schedules concurrently without contention.
3. Academic Calendar Overrides & Day Shifts
Universities regularly alter schedules to compensate for national holidays or academic festivals (e.g. "Wednesday follows Monday's timetable").
Attendrix handles timetable adjustments via public.academic_calendar_events and public.academic_calendar_overrides:
| Override Type | Behavior in generate_batch_schedule |
|---|---|
HOLIDAY | Suppresses class generation for all batches across that calendar date. |
FOLLOWS_DAY | Replaces the day's slot schedule with the schedule of follows_day (e.g. 1 = Monday). |
VENUE_CHANGE | Replaces room venue for specific course meetings on that date. |
TIMING_SHIFT | Modifies start/end timestamps for specific meetings. |
4. Extra Classes & Plus Slots
Faculty often schedule additional makeup lectures outside the regular weekly timetable.
- The
schedule_classRPC allows instructors or student representatives to create ad-hoc occurrences. - Flags:
is_extra_class = trueand optionallyis_plus_slot = true. - Conflict Detection: Checks existing active classes in the same batch and room for overlapping time ranges before inserting.
Was this page helpful?
Your feedback directly guides the engineering documentation roadmap.