initial project

This commit is contained in:
Talhadeveloperr
2026-09-09 17:00:54 +05:00
commit a7bb2f3dae
72 changed files with 1051 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
"""Renders one timetable grid per batch."""
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 _sessions_for_batch(sessions, batch_code):
return [s for s in sessions if batch_code in s["batch_codes"]]
def generate_batch_wise_templates(sessions, data, output_dir):
written = []
for batch in data["batches"]:
batch_code = batch["batch_code"]
batch_sessions = _sessions_for_batch(sessions, batch_code)
by_day_slot = {}
for s in batch_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 "")
return f'{s["course_name"]}{tag}\n{s["instructor_name"]}\n{s["room_id"]}'
wb = new_workbook()
ws = wb.active
subtitle = f'{batch["department"]} - {batch["program"]} - Session {batch["session"]}'
build_grid_sheet(
ws,
title=f"Batch {batch_code}",
subtitle=subtitle,
time_slots=GRID_TIME_SLOTS,
sessions_by_day_slot=by_day_slot,
cell_text_fn=cell_text,
)
path = save_workbook(wb, output_dir, f"{batch_code}.xlsx")
written.append(path)
return written

View File

@@ -0,0 +1,54 @@
"""Renders one timetable grid per department, aggregating all its batches."""
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_department_wise_templates(sessions, data, output_dir):
departments = sorted({b["department"] for b in data["batches"]})
written = []
for department in departments:
dept_batch_codes = {b["batch_code"] for b in data["batches"] if b["department"] == department}
dept_sessions = [s for s in sessions if any(bc in dept_batch_codes for bc in s["batch_codes"])]
by_day_slot = {}
for s in dept_sessions:
for slot_index in s["slot_indices"]:
by_day_slot.setdefault((s["day"], slot_index), []).append(s)
def cell_text(day, slot_index, by_day_slot=by_day_slot):
entries = by_day_slot.get((day, slot_index))
if not entries:
return ""
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} [{batches}]\n{s["instructor_name"]} @ {s["room_id"]}')
return "\n---\n".join(lines)
# for fill-color purposes just use the first session in each cell
first_by_day_slot = {k: v[0] for k, v in by_day_slot.items()}
wb = new_workbook()
ws = wb.active
build_grid_sheet(
ws,
title=f"Department: {department}",
subtitle="All batches / programs",
time_slots=GRID_TIME_SLOTS,
sessions_by_day_slot=first_by_day_slot,
cell_text_fn=cell_text,
)
path = save_workbook(wb, output_dir, f"{department}.xlsx")
written.append(path)
return written

View 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

View File

@@ -0,0 +1,54 @@
"""Renders one timetable grid per student (same grid as their batch, labeled per student)."""
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 _sessions_for_batch(sessions, batch_code):
return [s for s in sessions if batch_code in s["batch_codes"]]
def generate_student_wise_templates(sessions, data, output_dir):
written = []
for student in data["students"]:
roll_no = student["roll_no"]
batch_code = student["batch_code"]
batch = data["batches_by_code"].get(batch_code)
student_sessions = _sessions_for_batch(sessions, batch_code)
by_day_slot = {}
for s in student_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 "")
return f'{s["course_name"]}{tag}\n{s["instructor_name"]}\n{s["room_id"]}'
subtitle = f'{student["student_name"]} - Batch {batch_code}'
if batch:
subtitle += f' ({batch["department"]} - {batch["program"]})'
wb = new_workbook()
ws = wb.active
build_grid_sheet(
ws,
title=f"Roll No: {roll_no}",
subtitle=subtitle,
time_slots=GRID_TIME_SLOTS,
sessions_by_day_slot=by_day_slot,
cell_text_fn=cell_text,
)
path = save_workbook(wb, output_dir, f"{roll_no}.xlsx")
written.append(path)
return written

View File

@@ -0,0 +1,45 @@
"""Renders one timetable grid per instructor."""
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_teacher_wise_templates(sessions, data, output_dir):
written = []
for instructor in data["instructors"]:
code = instructor["instructor_code"]
instr_sessions = [s for s in sessions if s["instructor_code"] == code]
by_day_slot = {}
for s in instr_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["room_id"]}'
wb = new_workbook()
ws = wb.active
build_grid_sheet(
ws,
title=f'{instructor["instructor_name"]} ({code})',
subtitle=f'Department: {instructor["department"]}',
time_slots=GRID_TIME_SLOTS,
sessions_by_day_slot=by_day_slot,
cell_text_fn=cell_text,
)
path = save_workbook(wb, output_dir, f"{code}.xlsx")
written.append(path)
return written