"""Who did what. Used to write CREDITS.md.
Authors per file are taken from the commit history of 863.26/EECS (forge.cba.mit.edu),
branch main, commit a32cc4e771 (17 Nov 2026, 21:52). Written by Claude for Andrin.
"""

REPO = "https://forge.cba.mit.edu/863.26/EECS (machine-week/src), commit a32cc4e771 (17 Nov 2026, 21:52)"

# (path inside this folder, authors, what it does)
FILES = [
    # ---- software team
    ("team/software/scripts/svg_input.py", "Aaron Zeng", "SVG -> polylines in mm (svgelements)"),
    ("team/software/scripts/geometry.py", "Aaron Zeng", "polylines, simplify, place design on the bed"),
    ("team/software/scripts/colors.py", "Aaron Zeng", "SVG colour -> nearest nozzle colour"),
    ("team/software/scripts/toolpath.py", "Aaron Zeng; Tudor Mocioi", "polylines -> print events, path order"),
    ("team/software/scripts/pipeline.py", "Aaron Zeng", "SVG -> job (events + stats)"),
    ("team/software/scripts/preview.py", "Aaron Zeng", "toolpath preview and stats (the GUI draws with trace())"),
    ("team/software/scripts/config.py", "Aaron Zeng; Tudor Mocioi", "config loader and checks; x / y box (stage_limits)"),
    ("team/software/scripts/motion.py", "Aaron Zeng; Tudor Mocioi", "events -> XY moves, prime / extrude / retract"),
    ("team/software/scripts/ufp_driver.py", "Aaron Zeng; Tudor Mocioi", "runs the steps on the wrappers, simulated machine"),
    ("team/software/scripts/print_ufp.py", "Aaron Zeng; Tudor Mocioi", "command line printer (still works next to the GUI)"),
    ("team/software/scripts/firmware_link.py", "Tudor Mocioi", "puts the firmware folder on the path"),
    ("team/software/config/machine.example.yaml", "Aaron Zeng; Tudor Mocioi", "example config (app config is based on it)"),
    ("team/software/documentations/interface_spec.md", "Aaron Zeng; Tudor Mocioi", "software <-> firmware contract"),
    ("team/software/README.md", "Aaron Zeng; Tudor Mocioi", "software notes"),
    ("team/software/tests/test_pipeline.py", "Aaron Zeng", "tests"),
    ("team/software/tests/test_motion.py", "Aaron Zeng; Tudor Mocioi", "tests"),
    ("team/software/tests/test_multicolor.py", "Aaron Zeng; Tudor Mocioi", "tests"),
    ("team/software/data/svg/*.svg", "Aaron Zeng", "example designs"),
    ("team/software/requirements.txt, pytest.ini", "Aaron Zeng", "setup"),
    # ---- firmware team
    ("team/firmware/scripts/xy_stage_wrapper.py", "Tudor Mocioi", "CoreXY stage in mm: x / y box, homing (+X to the switch, "
                                                                  "back, -Y to the switch; used by the app), moves, stop"),
    ("team/firmware/scripts/single_stepper_wrapper.py", "Tudor Mocioi", "one motor in mm: homing, checks, MOTOR_ID check"),
    ("team/firmware/scripts/syringe_wrapper.py", "Tudor Mocioi; Hector Astrom", "syringe cycle: prime, extrude, retract; "
                                                                             "limit switch stop (Tudor) and one turn back off (Hector)"),
    ("team/firmware/scripts/xy_geometry.py", "Tudor Mocioi", "CoreXY math, x / y box, motor ranges"),
    ("team/firmware/scripts/motion_profile.py", "Tudor Mocioi", "trapezoid timing, flow profile"),
    ("team/firmware/scripts/simulated_stepper.py, simulated_xy_stage.py", "Tudor Mocioi", "simulated boards with limit switches (dry run)"),
    ("team/firmware/scripts/*_selftest.py", "Tudor Mocioi", "self tests against the simulators"),
    ("team/firmware/scripts/find_devices.py", "Hector Astrom", "find boards by MOTOR_ID (macOS port names)"),
    ("team/firmware/extrusion/utils.py, extrude.py", "Hector Astrom", "syringe measurements (8 mm/turn, 15.81 cm3/cm), extrusion tests, "
                                                                       "whole step rounding"),
    ("team/firmware/arduino/ufp_stepper/", "Quentin Bolsee (copied into the repo by Hector Astrom)",
     "board firmware, identical to third_party/ufp/arduino/UFP/examples/ufp_stepper"),
    ("team/firmware/extrusion/multi-device*.py", "Hector Astrom", "multi syringe control tests"),
    ("team/firmware/examples/stepper_motor.py", "Hector Astrom; Tudor Mocioi", "first stepper example"),
    ("team/firmware/README.md", "Tudor Mocioi; Hector Astrom", "how to flash and drive the boards"),
    # ---- outside the team
    ("third_party/ufp/", "Quentin Bolsee (MIT license)", "UFP protocol, Python host library, Arduino library and the "
                                                         "ufp_stepper firmware running on the boards"),
    ("stepper board hardware", "modular-things project (stepper-hbridge-xiao)", "board design; pinout in the Wiring tab"),
    ("batter recipe and tests", "Extrusion team: Hector Astrom, Jeannie, Eunice, Stella",
     "batter 2 : 1.25 water, griddle 225 F (Dancakes guide)"),
    # ---- this app
    ("app/simple_gui.py", "Claude (AI) for Andrin Schmid", "the simple window (run_gui.bat): find boards, connect, "
                                                            "Tudor's homing, move, syringes, picture or SVG, dry run, print"),
    ("app/backend.py", "Claude (AI) for Andrin Schmid", "glue to the team code: board search, currents, Tudor's homing, jog, syringes, print here, stop"),
    ("app/image_to_pancake.py", "Claude (AI) for Andrin Schmid", "photo -> 3 colour SVG (background removal: rembg)"),
    ("app/estimates.py", "Claude (AI) for Andrin Schmid", "syringe and machine estimates, from Hector's measurements"),
    ("app/make_wiring_diagram.py, wiring.png", "Claude (AI) for Andrin Schmid", "wiring picture"),
    ("app/pancake_config.yaml", "Claude (AI) for Andrin Schmid", "config: team example + estimates (marked # EST)"),
    ("app/credits.py, README.md, CREDITS.md, *.bat", "Claude (AI) for Andrin Schmid", "this list, docs, setup"),
]

AI_NOTE = (
    "Everything in app/ and the .bat files was written by Claude (Anthropic, model Claude Opus 5.5) "
    "at Andrin Schmid's request on 17 Nov 2026. Andrin set the requirements (local copy, GUI, adjustable "
    "values, wiring tab, credits, estimates from the syringe). The files in team/ and third_party/ are "
    "unchanged copies of the authors' work; the app only imports them. Not yet reviewed line by line, "
    "and not yet tested on the real machine: only on Tudor's simulated boards."
)


def write_markdown(path):
    lines = ["# Credits", "", f"Team code: {REPO}. The files in `team/` and `third_party/` are unchanged.",
             "", "| File | Author(s) | What it does |", "|---|---|---|"]
    lines += [f"| `{f}` | {a} | {w} |" for f, a, w in FILES]
    lines += ["", "## AI use", "", AI_NOTE, ""]
    from pathlib import Path
    Path(path).write_text("\n".join(lines), encoding="utf-8")


if __name__ == "__main__":
    from pathlib import Path
    write_markdown(Path(__file__).resolve().parent.parent / "CREDITS.md")
