This commit is contained in:
Talhadeveloperr
2026-09-09 18:07:19 +05:00
parent 3be641a36b
commit 1eed747639
53 changed files with 1213 additions and 56 deletions

View File

@@ -121,6 +121,39 @@ class Scheduler:
self.sessions = []
def to_state(self):
"""
Serializes this scheduler's accumulated sessions and busy-maps to a
JSON-able dict, so a later process can resume exactly where this
one left off (used to run each phase as a separate CLI command).
"""
def _dump_busy(busy_map):
return {f"{day}|{slot_index}": sorted(values) for (day, slot_index), values in busy_map.items()}
return {
"sessions": self.sessions,
"room_busy": _dump_busy(self.room_busy),
"instructor_busy": _dump_busy(self.instructor_busy),
"batch_busy": _dump_busy(self.batch_busy),
}
@classmethod
def from_state(cls, data, state):
"""Rebuilds a Scheduler from a dict previously produced by to_state()."""
def _load_busy(dumped):
busy = {}
for key, values in dumped.items():
day, slot_index = key.rsplit("|", 1)
busy[(day, int(slot_index))] = set(values)
return busy
scheduler = cls(data)
scheduler.sessions = list(state["sessions"])
scheduler.room_busy = _load_busy(state["room_busy"])
scheduler.instructor_busy = _load_busy(state["instructor_busy"])
scheduler.batch_busy = _load_busy(state["batch_busy"])
return scheduler
def _is_free(self, day, slot_index, room_id, instructor_code, batch_codes):
key = (day, slot_index)
if room_id in self.room_busy.get(key, set()):