more chnages
This commit is contained in:
@@ -21,17 +21,26 @@ def generate_batch_wise_templates(sessions, data, output_dir):
|
||||
batch_code = batch["batch_code"]
|
||||
batch_sessions = _sessions_for_batch(sessions, batch_code)
|
||||
|
||||
# A batch-wise view can legitimately show more than one lecture in
|
||||
# the same slot (e.g. sections of the batch split across rooms), so
|
||||
# every session landing on a cell is kept and rendered — none are
|
||||
# dropped or overwritten.
|
||||
by_day_slot = {}
|
||||
for s in batch_sessions:
|
||||
for slot_index in s["slot_indices"]:
|
||||
by_day_slot[(s["day"], slot_index)] = s
|
||||
by_day_slot.setdefault((s["day"], slot_index), []).append(s)
|
||||
|
||||
def cell_text(day, slot_index, by_day_slot=by_day_slot):
|
||||
s = by_day_slot.get((day, slot_index))
|
||||
if not s:
|
||||
entries = by_day_slot.get((day, slot_index))
|
||||
if not entries:
|
||||
return ""
|
||||
tag = " (Lab)" if s["course_type"] == "lab" else (" (General)" if s["is_general"] else "")
|
||||
return f'{s["course_name"]}{tag}\n{s["instructor_name"]}\n{s["room_id"]}'
|
||||
lines = []
|
||||
for s in entries:
|
||||
tag = " (Lab)" if s["course_type"] == "lab" else (" (General)" if s["is_general"] else "")
|
||||
lines.append(f'{s["course_name"]}{tag}\n{s["instructor_name"]}\n{s["room_id"]}')
|
||||
return "\n---\n".join(lines)
|
||||
|
||||
first_by_day_slot = {k: v[0] for k, v in by_day_slot.items()}
|
||||
|
||||
wb = new_workbook()
|
||||
ws = wb.active
|
||||
@@ -41,7 +50,7 @@ def generate_batch_wise_templates(sessions, data, output_dir):
|
||||
title=f"Batch {batch_code}",
|
||||
subtitle=subtitle,
|
||||
time_slots=GRID_TIME_SLOTS,
|
||||
sessions_by_day_slot=by_day_slot,
|
||||
sessions_by_day_slot=first_by_day_slot,
|
||||
cell_text_fn=cell_text,
|
||||
)
|
||||
path = save_workbook(wb, output_dir, f"{batch_code}.xlsx")
|
||||
|
||||
@@ -17,18 +17,26 @@ def generate_room_wise_templates(sessions, data, output_dir):
|
||||
room_id = room["room_id"]
|
||||
room_sessions = [s for s in sessions if s["room_id"] == room_id]
|
||||
|
||||
# A room-wise view can legitimately show more than one lecture in
|
||||
# the same slot (e.g. a large room split/shared), so every session
|
||||
# landing on a cell is kept and rendered — none are dropped.
|
||||
by_day_slot = {}
|
||||
for s in room_sessions:
|
||||
for slot_index in s["slot_indices"]:
|
||||
by_day_slot[(s["day"], slot_index)] = s
|
||||
by_day_slot.setdefault((s["day"], slot_index), []).append(s)
|
||||
|
||||
def cell_text(day, slot_index, by_day_slot=by_day_slot):
|
||||
s = by_day_slot.get((day, slot_index))
|
||||
if not s:
|
||||
entries = by_day_slot.get((day, slot_index))
|
||||
if not entries:
|
||||
return ""
|
||||
tag = " (Lab)" if s["course_type"] == "lab" else (" (General)" if s["is_general"] else "")
|
||||
batches = "+".join(s["batch_codes"])
|
||||
return f'{s["course_name"]}{tag}\n{batches}\n{s["instructor_name"]}'
|
||||
lines = []
|
||||
for s in entries:
|
||||
tag = " (Lab)" if s["course_type"] == "lab" else (" (General)" if s["is_general"] else "")
|
||||
batches = "+".join(s["batch_codes"])
|
||||
lines.append(f'{s["course_name"]}{tag}\n{batches}\n{s["instructor_name"]}')
|
||||
return "\n---\n".join(lines)
|
||||
|
||||
first_by_day_slot = {k: v[0] for k, v in by_day_slot.items()}
|
||||
|
||||
wb = new_workbook()
|
||||
ws = wb.active
|
||||
@@ -37,7 +45,7 @@ def generate_room_wise_templates(sessions, data, output_dir):
|
||||
title=f'{room["room_name"]} ({room_id})',
|
||||
subtitle=f'Block {room["block_id"]} - {room["room_type"].title()} - Capacity {room["capacity"]}',
|
||||
time_slots=GRID_TIME_SLOTS,
|
||||
sessions_by_day_slot=by_day_slot,
|
||||
sessions_by_day_slot=first_by_day_slot,
|
||||
cell_text_fn=cell_text,
|
||||
)
|
||||
path = save_workbook(wb, output_dir, f"{room_id}.xlsx")
|
||||
|
||||
@@ -9,6 +9,7 @@ sys.path.insert(0, os.path.join(_ROOT, "controller"))
|
||||
|
||||
from xlsx_grid_helper import build_grid_sheet, new_workbook, save_workbook # noqa: E402
|
||||
from template_controller import TIME_SLOTS as GRID_TIME_SLOTS # noqa: E402
|
||||
from template_logger import log_error # noqa: E402
|
||||
|
||||
|
||||
def _sessions_for_batch(sessions, batch_code):
|
||||
@@ -23,17 +24,38 @@ def generate_student_wise_templates(sessions, data, output_dir):
|
||||
batch = data["batches_by_code"].get(batch_code)
|
||||
student_sessions = _sessions_for_batch(sessions, batch_code)
|
||||
|
||||
by_day_slot = {}
|
||||
# A student can only be in one place at a time: each (day, slot)
|
||||
# must resolve to exactly one session. If the schedule places more
|
||||
# than one, that's a real scheduling error - log it instead of
|
||||
# silently picking/overwriting one.
|
||||
raw_by_day_slot = {}
|
||||
for s in student_sessions:
|
||||
for slot_index in s["slot_indices"]:
|
||||
by_day_slot[(s["day"], slot_index)] = s
|
||||
raw_by_day_slot.setdefault((s["day"], slot_index), []).append(s)
|
||||
|
||||
def cell_text(day, slot_index, by_day_slot=by_day_slot):
|
||||
s = by_day_slot.get((day, slot_index))
|
||||
if not s:
|
||||
by_day_slot = {}
|
||||
for (day, slot_index), entries in raw_by_day_slot.items():
|
||||
if len(entries) > 1:
|
||||
course_list = ", ".join(
|
||||
f'{e["course_id"]} ({e["course_type"]}) with {e["instructor_name"]} in {e["room_id"]}'
|
||||
for e in entries
|
||||
)
|
||||
log_error(
|
||||
f"Student conflict: roll {roll_no} (batch {batch_code}) has "
|
||||
f"{len(entries)} overlapping courses on {day} slot {slot_index}: {course_list}"
|
||||
)
|
||||
by_day_slot[(day, slot_index)] = entries[0]
|
||||
|
||||
def cell_text(day, slot_index, raw_by_day_slot=raw_by_day_slot):
|
||||
entries = raw_by_day_slot.get((day, slot_index))
|
||||
if not entries:
|
||||
return ""
|
||||
s = entries[0]
|
||||
tag = " (Lab)" if s["course_type"] == "lab" else (" (General)" if s["is_general"] else "")
|
||||
return f'{s["course_name"]}{tag}\n{s["instructor_name"]}\n{s["room_id"]}'
|
||||
text = f'{s["course_name"]}{tag}\n{s["instructor_name"]}\n{s["room_id"]}'
|
||||
if len(entries) > 1:
|
||||
text = "CONFLICT!\n" + text
|
||||
return text
|
||||
|
||||
subtitle = f'{student["student_name"]} - Batch {batch_code}'
|
||||
if batch:
|
||||
|
||||
@@ -9,6 +9,7 @@ sys.path.insert(0, os.path.join(_ROOT, "controller"))
|
||||
|
||||
from xlsx_grid_helper import build_grid_sheet, new_workbook, save_workbook # noqa: E402
|
||||
from template_controller import TIME_SLOTS as GRID_TIME_SLOTS # noqa: E402
|
||||
from template_logger import log_error # noqa: E402
|
||||
|
||||
|
||||
def generate_teacher_wise_templates(sessions, data, output_dir):
|
||||
@@ -17,18 +18,39 @@ def generate_teacher_wise_templates(sessions, data, output_dir):
|
||||
code = instructor["instructor_code"]
|
||||
instr_sessions = [s for s in sessions if s["instructor_code"] == code]
|
||||
|
||||
by_day_slot = {}
|
||||
# A teacher can only be in one place at a time: each (day, slot)
|
||||
# must resolve to exactly one session. If the schedule places more
|
||||
# than one, that's a real scheduling error - log it instead of
|
||||
# silently picking/overwriting one.
|
||||
raw_by_day_slot = {}
|
||||
for s in instr_sessions:
|
||||
for slot_index in s["slot_indices"]:
|
||||
by_day_slot[(s["day"], slot_index)] = s
|
||||
raw_by_day_slot.setdefault((s["day"], slot_index), []).append(s)
|
||||
|
||||
def cell_text(day, slot_index, by_day_slot=by_day_slot):
|
||||
s = by_day_slot.get((day, slot_index))
|
||||
if not s:
|
||||
by_day_slot = {}
|
||||
for (day, slot_index), entries in raw_by_day_slot.items():
|
||||
if len(entries) > 1:
|
||||
course_list = ", ".join(
|
||||
f'{e["course_id"]} ({e["course_type"]}) for batch(es) {"+".join(e["batch_codes"])} in {e["room_id"]}'
|
||||
for e in entries
|
||||
)
|
||||
log_error(
|
||||
f"Teacher conflict: {instructor['instructor_name']} ({code}) is double-booked on "
|
||||
f"{day} slot {slot_index}: {course_list}"
|
||||
)
|
||||
by_day_slot[(day, slot_index)] = entries[0]
|
||||
|
||||
def cell_text(day, slot_index, raw_by_day_slot=raw_by_day_slot):
|
||||
entries = raw_by_day_slot.get((day, slot_index))
|
||||
if not entries:
|
||||
return ""
|
||||
s = entries[0]
|
||||
tag = " (Lab)" if s["course_type"] == "lab" else (" (General)" if s["is_general"] else "")
|
||||
batches = "+".join(s["batch_codes"])
|
||||
return f'{s["course_name"]}{tag}\n{batches}\n{s["room_id"]}'
|
||||
text = f'{s["course_name"]}{tag}\n{batches}\n{s["room_id"]}'
|
||||
if len(entries) > 1:
|
||||
text = "CONFLICT!\n" + text
|
||||
return text
|
||||
|
||||
wb = new_workbook()
|
||||
ws = wb.active
|
||||
|
||||
Reference in New Issue
Block a user