""" Regenerates data/dummy/roll_no/students.csv to match the real batches in data/dummy/batch_codes/25|26/batches.csv. Rule: one student {batch_code}-001 per batch. Batches listed in data/dummy/fixed two sections.txt (batches with two registered sections) additionally get {batch_code}-002. Run: python data/dummy/generate_student_roster.py """ import csv import os BASE_DIR = os.path.dirname(os.path.abspath(__file__)) TWO_SECTION_BATCHES_FILE = os.path.join(BASE_DIR, "fixed two sections.txt") STUDENTS_FILE = os.path.join(BASE_DIR, "roll_no", "students.csv") def _read_csv(relative_path): path = os.path.join(BASE_DIR, relative_path) with open(path, newline="", encoding="utf-8") as f: return list(csv.DictReader(f)) def _read_two_section_batches(): with open(TWO_SECTION_BATCHES_FILE, encoding="utf-8") as f: return {line.strip() for line in f if line.strip()} def main(): batches_25 = _read_csv(os.path.join("batch_codes", "25", "batches.csv")) batches_26 = _read_csv(os.path.join("batch_codes", "26", "batches.csv")) batches = batches_25 + batches_26 two_section_batches = _read_two_section_batches() students = [] for batch in batches: batch_code = batch["batch_code"] seqs = [1, 2] if batch_code in two_section_batches else [1] for seq in seqs: roll_no = f"{batch_code}-{seq:03d}" students.append([roll_no, batch_code, f"Student {roll_no}"]) os.makedirs(os.path.dirname(STUDENTS_FILE), exist_ok=True) with open(STUDENTS_FILE, "w", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerow(["roll_no", "batch_code", "student_name"]) writer.writerows(students) print(f"wrote {len(students)} rows -> {STUDENTS_FILE}") if __name__ == "__main__": main()