initial project
This commit is contained in:
45
templates/room-wise/room_wise_template.py
Normal file
45
templates/room-wise/room_wise_template.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""Renders one timetable grid per room."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")
|
||||
sys.path.insert(0, os.path.join(_ROOT, "app"))
|
||||
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
|
||||
|
||||
|
||||
def generate_room_wise_templates(sessions, data, output_dir):
|
||||
written = []
|
||||
for room in data["rooms"]:
|
||||
room_id = room["room_id"]
|
||||
room_sessions = [s for s in sessions if s["room_id"] == room_id]
|
||||
|
||||
by_day_slot = {}
|
||||
for s in room_sessions:
|
||||
for slot_index in s["slot_indices"]:
|
||||
by_day_slot[(s["day"], slot_index)] = s
|
||||
|
||||
def cell_text(day, slot_index, by_day_slot=by_day_slot):
|
||||
s = by_day_slot.get((day, slot_index))
|
||||
if not s:
|
||||
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"]}'
|
||||
|
||||
wb = new_workbook()
|
||||
ws = wb.active
|
||||
build_grid_sheet(
|
||||
ws,
|
||||
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,
|
||||
cell_text_fn=cell_text,
|
||||
)
|
||||
path = save_workbook(wb, output_dir, f"{room_id}.xlsx")
|
||||
written.append(path)
|
||||
return written
|
||||
Reference in New Issue
Block a user