175 lines
6.0 KiB
Python
175 lines
6.0 KiB
Python
"""
|
|
Generates small illustrative dummy CSV datasets under data/dummy/ so the
|
|
timetable template generator has something to schedule and render.
|
|
|
|
Run once:
|
|
python data/dummy/generate_dummy_data.py
|
|
"""
|
|
|
|
import csv
|
|
import os
|
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def write_csv(relative_path, header, rows):
|
|
path = os.path.join(BASE_DIR, relative_path)
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
with open(path, "w", newline="", encoding="utf-8") as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(header)
|
|
writer.writerows(rows)
|
|
print(f"wrote {len(rows)} rows -> {path}")
|
|
|
|
|
|
def main():
|
|
# ---- blocks & rooms (Building/Block A only) ----
|
|
write_csv(
|
|
"blocks/blocks.csv",
|
|
["block_id", "block_name"],
|
|
[["A", "Block A"]],
|
|
)
|
|
|
|
write_csv(
|
|
"blocks/rooms.csv",
|
|
["room_id", "room_name", "block_id", "room_type", "capacity"],
|
|
[
|
|
["A-101", "Room 101", "A", "classroom", 60],
|
|
["A-102", "Room 102", "A", "classroom", 60],
|
|
["A-103", "Room 103", "A", "classroom", 50],
|
|
["A-201", "Room 201", "A", "classroom", 60],
|
|
["A-L01", "Computer Lab 1", "A", "lab", 35],
|
|
["A-L02", "Computer Lab 2", "A", "lab", 35],
|
|
],
|
|
)
|
|
|
|
# ---- departments / programs / batches ----
|
|
# batch_code = session(2) + program_id(6) e.g. 25021519
|
|
batches_25 = [
|
|
["25021519", "CS", "BSCS", "25"],
|
|
["25021520", "CS", "BSSE", "25"],
|
|
["25031519", "EE", "BSEE", "25"],
|
|
]
|
|
batches_26 = [
|
|
["26021519", "CS", "BSCS", "26"],
|
|
["26021520", "CS", "BSSE", "26"],
|
|
["26031519", "EE", "BSEE", "26"],
|
|
]
|
|
|
|
write_csv(
|
|
"batch_codes/25/batches.csv",
|
|
["batch_code", "department", "program", "session"],
|
|
batches_25,
|
|
)
|
|
write_csv(
|
|
"batch_codes/26/batches.csv",
|
|
["batch_code", "department", "program", "session"],
|
|
batches_26,
|
|
)
|
|
|
|
all_batches = batches_25 + batches_26
|
|
|
|
# ---- courses ----
|
|
# One row per subject: lectures/labs per week are counted separately so
|
|
# a single course can carry both, and each course names its preferred
|
|
# lecture/lab room (the scheduler falls back to another same-type room
|
|
# only if the preferred one is busy).
|
|
# is_general courses are shared across every batch of the same session
|
|
# (so they can be scheduled together on Tuesday first, with no clash).
|
|
courses = [
|
|
# course_id, course_name, credit_hours, lectures_per_week, labs_per_week, is_general, lecture_room_id, lab_room_id
|
|
["CS101", "Programming Fundamentals", 4, 2, 1, "no", "A-101", "A-L01"],
|
|
["CS201", "Data Structures", 4, 2, 1, "no", "A-102", "A-L01"],
|
|
["EE101", "Basic Electronics", 4, 2, 1, "no", "A-201", "A-L02"],
|
|
["GEN101", "Functional English", 3, 2, 0, "yes", "A-103", ""],
|
|
["GEN102", "Islamic Studies", 2, 1, 0, "yes", "A-103", ""],
|
|
]
|
|
write_csv(
|
|
"courses/courses.csv",
|
|
[
|
|
"course_id", "course_name", "credit_hours", "lectures_per_week",
|
|
"labs_per_week", "is_general", "lecture_room_id", "lab_room_id",
|
|
],
|
|
courses,
|
|
)
|
|
|
|
# ---- course offerings: course + section (a section groups the batches
|
|
# taking that section together) + who teaches it ----
|
|
# A course can have many sections; here each CS/EE batch of a session is
|
|
# its own section (Section A/B/...), while general courses have a single
|
|
# section "ALL" grouping every batch of that session.
|
|
offerings = []
|
|
|
|
dept_course = {"CS": ["CS101", "CS201"], "EE": ["EE101"]}
|
|
dept_instructors = {
|
|
"CS": ["1001", "1002", "1003", "1006"],
|
|
"EE": ["1004", "1005"],
|
|
}
|
|
|
|
section_letters = ["A", "B", "C", "D"]
|
|
dept_section_counter = {"CS": 0, "EE": 0}
|
|
|
|
for batch_code, department, program, session in all_batches:
|
|
section_id = section_letters[dept_section_counter[department] % len(section_letters)]
|
|
dept_section_counter[department] += 1
|
|
|
|
for i, course_id in enumerate(dept_course[department]):
|
|
instr_pool = dept_instructors[department]
|
|
instr = instr_pool[i % len(instr_pool)]
|
|
offerings.append([course_id, section_id, batch_code, instr])
|
|
|
|
# general courses: one offering per (course, session), section "ALL"
|
|
# grouping every batch code sharing that session, separated by "|"
|
|
for session, batch_group in (
|
|
("25", [b[0] for b in batches_25]),
|
|
("26", [b[0] for b in batches_26]),
|
|
):
|
|
offerings.append(["GEN101", "ALL", "|".join(batch_group), "1002"])
|
|
offerings.append(["GEN102", "ALL", "|".join(batch_group), "1006"])
|
|
|
|
write_csv(
|
|
"courses/course_offering.csv",
|
|
["course_id", "section_id", "batch_codes", "instructor_code"],
|
|
offerings,
|
|
)
|
|
|
|
# ---- instructors (4-digit employee codes) ----
|
|
# Derived from the offerings above so it can never drift: one row per
|
|
# unique (instructor, course, section) teaching assignment.
|
|
instructor_names = {
|
|
"1001": "Dr. Ahsan Raza",
|
|
"1002": "Ms. Sana Tariq",
|
|
"1003": "Mr. Bilal Khan",
|
|
"1004": "Dr. Farah Iqbal",
|
|
"1005": "Mr. Usman Ali",
|
|
"1006": "Ms. Hira Shah",
|
|
}
|
|
instructors = []
|
|
for course_id, section_id, batch_codes, instr_code in offerings:
|
|
instructors.append([instr_code, instructor_names[instr_code], course_id, section_id])
|
|
|
|
write_csv(
|
|
"instructor/instructors.csv",
|
|
["instructor_code", "instructor_name", "course_id", "section_id"],
|
|
instructors,
|
|
)
|
|
|
|
# ---- students (roll_no = batch_code-seq) ----
|
|
students = []
|
|
for batch_code, department, program, session in all_batches:
|
|
for seq in range(1, 6): # 5 sample students per batch
|
|
roll_no = f"{batch_code}-{seq:03d}"
|
|
students.append([roll_no, batch_code, f"Student {roll_no}"])
|
|
|
|
write_csv(
|
|
"roll_no/students.csv",
|
|
["roll_no", "batch_code", "student_name"],
|
|
students,
|
|
)
|
|
|
|
print("\nDummy data generation complete.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|