#!/usr/bin/env python3
"""Presenter topic-assignment order for CS 886 (Fall 2026), University of Waterloo.

Policy (see syllabus.html, "Presentation sign-up policy"):
    - Round 1: the class roster, sorted by (last name, first name), is randomly
      shuffled with seed 42; topic 1 of each student is assigned greedily in
      that order.
    - Round 2: topic 2 is assigned greedily in the reverse of that order.

Usage:
    python3 shuffle_presenters.py roster.csv

roster.csv must have a header row with columns "last,first", e.g.

    last,first
    Curie,Marie
    Lovelace,Ada
    Hopper,Grace

Both rounds are printed; test dispatching/greedy assignment is done manually
or in a separate script once students' topic rankings are collected.
"""

import csv
import random
import sys

SEED = 42


def main() -> None:
    if len(sys.argv) != 2:
        sys.exit(f"usage: {sys.argv[0]} roster.csv   # header row: last,first")
    with open(sys.argv[1], newline="", encoding="utf-8-sig") as f:
        roster = [(row["last"].strip(), row["first"].strip()) for row in csv.DictReader(f)]
    if not roster:
        sys.exit("error: roster is empty")

    order = sorted(roster, key=lambda name: (name[0].lower(), name[1].lower()))
    random.Random(SEED).shuffle(order)

    def show(names, title):
        print(title)
        for rank, (last, first) in enumerate(names, 1):
            print(f"  {rank:2d}. {first} {last}")

    show(order, f"Round 1 (roster sorted by (last, first), shuffled with seed {SEED}):")
    print()
    show(order[::-1], "Round 2 (reverse of round 1):")


if __name__ == "__main__":
    main()
