Build next week's staff schedule.
Done by an agent. Checked twice.
A full week's rota where every shift is covered and every coverage rule is tested and passes.
Real files in
- availability.csv
99 availability rows for the week, with one row sent twice, blank cells, a name typed another way and a person who has left. 100 lines, 3 KB. - coverage_rules.md
The nine coverage rules the schedule must keep. 13 lines, 837 bytes. - shifts.csv
The 14 shifts of the week and how many people each needs, 42 places in all. 15 lines, 377 bytes. - staff.csv
The 14 people on the dispatch floor: who is a lead, who holds a forklift ticket and their minimum and maximum weekly hours. 15 lines, 499 bytes. - time_off.csv
Six time off requests: four approved, one pending and one denied. 7 lines, 324 bytes.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read who can work and when
- 2.Fill every shift without breaking a rule
- 3.Write the schedule, hours and notes
Claude Sonnet 5.5, 1 min 18 s. No web. It never saw the check.
Checked twice
- Passed: 42 of 42 places are filled and 13 of 13 open shifts have exactly the number of people they need
- Passed: 42 of 42 assignments are staff on file under the name on file who marked that shift yes and have no approved time off that day
- Passed: 13 of 13 open shifts have a lead and someone with a forklift ticket
- Passed: 14 of 14 people have no double shift and no late shift followed by an early one
- Passed: 14 of 14 people are inside their minimum and maximum hours for the week
- Passed: hours.csv has one row per person on file and agrees with the schedule for 14 of 14 people, 336 hours in all
- Passed: notes.md names 2 of 2 people set aside: not on the staff list, or no availability sent
- Passed: 72 of 72 numbers in notes.md are right: staff numbers match their names, figures beside a person are that person's hours, shifts or limits and the rest are counts from the files
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 9 ways on purpose. The check caught 9.
| # | Rule | Result | |---|------|--------| | 1 | Every shift has exactly the people it needs; closed shift stays empty | PASS. All 13 open shifts match staff_needed. Sun late has nobody. | | 2 | Each open shift has at least one lead and one forklift ticket | PASS on all 13 open shifts. | | 3 | Nobody works two shifts on one day | PASS. No one has two rows on the same day. | | 4 | No late shift followed by the next morning's early shift | PASS. No such pair exists. | | 5 | 8-hour shifts, nobody over max_hours | PASS. The highest total is 40 hours (S-02, S-06 and S-13), and all three have a max of 40 or more. | | 6 | Everyone who sent availability gets at least min_hours | PASS. See the lowest-margin cases below. | | 7 | Only shifts marked yes (blank = no) | PASS. Every assigned shift is marked yes in the availability file. | | 8 | Approved time off blocks the whole day; pending and denied do not | PASS. Nobody is scheduled on a day of approved time off. | | 9 | Only people in staff.csv | PASS. Everyone scheduled is in staff.csv, with the name written as in staff.csv. |
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 2 of 2 on 1 December 2026. The agent took 1 min 18 s. Run 1 passed both checks and the job was run again later. Each run starts clean. Between runs the written flow was made clearer, or a check was corrected or made stricter. Nobody edits the output.
What the second review verified
- All 13 open shifts have exactly staff_needed (42 rows = 5×(4+3)+3+2+2); Sun late is empty; each open shift has a lead and a forklift holder (e.g. Sun early: S-04 Dalia Novak, a lead, and S-10 Ivo Castellan, who has a forklift ticket)
- Every assignment is marked 'yes' in availability.csv. Nobody works on an approved day off (Hana Thu, Milos Mon, Ana Fri, Chidi Sun). The pending request (Junia Wed) and the denied one (Leila Tue) were correctly not treated as blocks
- No one works two shifts in a day and no late shift is followed by the next day's early shift (checked every day pair Mon→Sun, e.g. Sat late {S-03,S-06} vs Sun early {S-04,S-10})
- hours.csv recomputed: S-01 32, S-02 40, S-03 24, S-04 16, S-05 32, S-06 40, S-07 32, S-08 16, S-10 8, S-11 24, S-12 16, S-13 40, S-14 16, S-15 0. Total 336. All between min and max, with names spelled as in staff.csv
What this run does not show
- Between the two runs the flow was made clearer and the sample week moved to a later date, because the first notes named a missing script and flagged the week as past.
- Small counts and rule numbers in the notes pass if they match any true figure from the files, so a swapped one would pass.
- The check proves no rule is broken for 14 people but cannot say whether the rota is fair.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 9 of 9. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Build next week's staff schedule function: operations for: the person who writes the weekly rota goal: Every shift next week is fully staffed by people who can work it, with no coverage rule broken. ## 1. Read who can work and when Read input/staff.csv, input/availability.csv, input/time_off.csv, input/shifts.csv and input/coverage_rules.md. The rules file is the law for this job. Match people by staff_id and write names as they are in staff.csv. If the same availability row appears twice, count it once. Work out for every person the shifts they can really work after time off is applied. Set aside anyone the rules say cannot be scheduled and note why. ## 2. Fill every shift without breaking a rule Assign people to shifts so that every numbered rule in coverage_rules.md holds at the same time. Fill the shifts with the fewest people able to work them first. Then test the whole schedule against each rule, one rule at a time, with a script. If any rule fails, change the schedule and test again. Do not stop until every rule passes. If no schedule can satisfy every rule, say so and name the rule and the shift that cannot be met. Never write a schedule that breaks a rule without saying so. ## 3. Write the schedule, hours and notes Write output/schedule.csv with columns day,shift,staff_id,name. One row for each person on each shift, with day and shift written as in shifts.csv. Write output/hours.csv with columns staff_id,name,shifts,hours. One row for every person in staff.csv, including people with no shifts. Write output/notes.md for the manager: the result of the test for each numbered rule, every person who was set aside and why, every time off request and how it was treated. End with anything in the files that needs fixing, such as a name typed two ways or a row sent twice. Name only files that are in output/, never a working file or script the manager will not receive. Refer to people by name or staff_id. The files do not say whether a person is he or she, so do not write either. ## Done looks like - Every shift has exactly the number of people it needs. - Nobody is on a shift they cannot work. - Every numbered rule passes when tested against the written schedule.
input/availability.csv · 100 lines, 3 KB
staff_id,name,day,early,late S-01,Ana Petrovic,Mon,yes,no S-01,Ana Petrovic,Tue,yes,no S-01,Ana Petrovic,Wed,yes,no S-01,Ana Petrovic,Thu,yes,no S-01,Ana Petrovic,Fri,yes,no S-01,Ana Petrovic,Sat,no,no S-01,Ana Petrovic,Sun,no,no S-02,Bram Oduya,Mon,no,yes S-02,Bram Oduya,Tue,no,yes S-02,Bram Oduya,Wed,no,yes S-02,Bram Oduya,Thu,no,yes S-02,Bram Oduya,Fri,no,yes S-02,Bram Oduya,Sat,yes,yes S-02,Bram Oduya,Sun,no,no S-03,Chidi Laurent,Mon,no,no S-03,Chidi Laurent,Tue,no,no S-03,Chidi Laurent,Wed,yes,yes S-03,Chidi Laurent,Thu,yes,yes S-03,Chidi Laurent,Fri,yes,yes S-03,Chidi Laurent,Sat,yes,yes S-03,Chidi Laurent,Sun,yes,no S-04,Dalia Novak,Mon,yes,yes S-04,Dalia Novak,Tue,yes,yes S-04,Dalia Novak,Wed,no,no S-04,Dalia Novak,Thu,no,no S-04,Dalia Novak,Fri,no,no S-04,Dalia Novak,Sat,yes,yes S-04,Dalia Novak,Sun,yes,no S-05,Matteo Alvarez,Mon,yes,yes S-05,Matteo Alvarez,Tue,yes,yes S-05,Matteo Alvarez,Wed,yes,yes S-05,Matteo Alvarez,Thu,yes,yes S-05,Matteo Alvarez,Fri,yes,yes S-05,Matteo Alvarez,Sat,no,no S-05,Matteo Alvarez,Sun,no,no S-06,Farah Lindqvist,Mon,no,yes S-06,Farah Lindqvist,Tue,no,yes S-06,Farah Lindqvist,Wed,no,yes S-06,Farah Lindqvist,Thu,no,yes S-06,Farah Lindqvist,Fri,no,yes S-06,Farah Lindqvist,Sat,no,yes S-06,Farah Lindqvist,Sun,no,no S-07,Goran Mistry,Mon,yes,no S-07,Goran Mistry,Tue,yes,no S-07,Goran Mistry,Wed,yes,no S-07,Goran Mistry,Thu,yes,no S-07,Goran Mistry,Thu,yes,no S-07,Goran Mistry,Fri,yes,no S-07,Goran Mistry,Sat,yes,no S-07,Goran Mistry,Sun,no,no S-08,Hana Whitlock,Mon,,no S-08,Hana Whitlock,Tue,yes,yes S-08,Hana Whitlock,Wed,yes,yes S-08,Hana Whitlock,Thu,yes,yes S-08,Hana Whitlock,Fri,yes,yes S-08,Hana Whitlock,Sat,yes,yes S-08,Hana Whitlock,Sun,no,no S-09,Petra Vance,Mon,yes,yes S-09,Petra Vance,Tue,yes,yes S-09,Petra Vance,Wed,yes,yes S-09,Petra Vance,Thu,yes,yes S-09,Petra Vance,Fri,yes,yes S-09,Petra Vance,Sat,yes,no S-09,Petra Vance,Sun,yes,no S-10,Ivo Castellan,Mon,no,no S-10,Ivo Castellan,Tue,no,no S-10,Ivo Castellan,Wed,no,no S-10,Ivo Castellan,Thu,no,no S-10,Ivo Castellan,Fri,no,yes S-10,Ivo Castellan,Sat,yes,yes S-10,Ivo Castellan,Sun,yes,no S-11,Junia Okoro,Mon,yes,yes S-11,Junia Okoro,Tue,yes,yes S-11,Junia Okoro,Wed,yes,yes S-11,Junia Okoro,Thu,yes,yes S-11,Junia Okoro,Fri,yes,yes S-11,Junia Okoro,Sat,yes,yes S-11,Junia Okoro,Sun,yes,no S-12,Kasper Thorne,Mon,yes,no S-12,Kasper Thorne,Tue,yes,no S-12,Kasper Thorne,Wed,yes,no S-12,Kasper Thorne,Thu,no,yes S-12,Kasper Thorne,Fri,no,yes S-12,Kasper Thorne,Sat,no,no S-12,Kasper Thorne,Sun,, S-13,Leila Brannigan,Mon,yes,no S-13,Leila Brannigan,Tue,yes,no S-13,Leila Brannigan,Wed,yes,no S-13,Leila Brannigan,Thu,yes,no S-13,Leila Brannigan,Fri,yes,no S-13,Leila Brannigan,Sat,yes,yes S-13,Leila Brannigan,Sun,no,no S-14,Milos Ferreira,Mon,no,yes S-14,Milos Ferreira,Tue,no,yes S-14,Milos Ferreira,Wed,no,yes S-14,Milos Ferreira,Thu,no,yes S-14,Milos Ferreira,Fri,no,yes S-14,Milos Ferreira,Sat,no,no S-14,Milos Ferreira,Sun,no,no
input/coverage_rules.md · 13 lines, 837 bytes
# Coverage rules for the dispatch floor Week to schedule: Monday 2026-12-07 to Sunday 2026-12-13. 1. Every shift gets exactly the number of people in shifts.csv. A shift that needs 0 people is closed. 2. Every open shift has at least one lead and at least one person with a forklift ticket. One person who is both counts for both. 3. Nobody works two shifts on the same day. 4. Nobody works a late shift and then the early shift the next morning. 5. Every shift is 8 hours. Nobody goes over their max_hours for the week. 6. Everyone who sent in availability gets at least their min_hours for the week. 7. People only work shifts they marked yes. A blank is a no. 8. Approved time off beats availability: the person is off that whole day. Pending or denied time off does not block a shift. 9. Only people in staff.csv can be scheduled.
input/shifts.csv · 15 lines, 377 bytes
day,shift,start,end,staff_needed Mon,early,06:00,14:00,4 Mon,late,14:00,22:00,3 Tue,early,06:00,14:00,4 Tue,late,14:00,22:00,3 Wed,early,06:00,14:00,4 Wed,late,14:00,22:00,3 Thu,early,06:00,14:00,4 Thu,late,14:00,22:00,3 Fri,early,06:00,14:00,4 Fri,late,14:00,22:00,3 Sat,early,06:00,14:00,3 Sat,late,14:00,22:00,2 Sun,early,06:00,14:00,2 Sun,late,14:00,22:00,0
input/staff.csv · 15 lines, 499 bytes
staff_id,name,lead,forklift,min_hours,max_hours S-01,Ana Petrovic,yes,yes,32,40 S-02,Bram Oduya,yes,no,32,40 S-03,Chidi Laurent,yes,yes,24,32 S-04,Dalia Novak,yes,no,16,24 S-05,Mateo Alvarez,no,yes,32,40 S-06,Farah Lindqvist,no,yes,24,40 S-07,Goran Mistry,no,no,32,40 S-08,Hana Whitlock,no,no,16,32 S-10,Ivo Castellan,no,yes,0,20 S-11,Junia Okoro,no,no,24,40 S-12,Kasper Thorne,no,no,16,24 S-13,Leila Brannigan,no,yes,32,40 S-14,Milos Ferreira,no,no,16,32 S-15,Noor Haddad,no,no,0,40
input/time_off.csv · 7 lines, 324 bytes
staff_id,name,day,status,note S-08,Hana Whitlock,Thu,approved,dentist S-14,Milos Ferreira,Mon,approved,family S-11,Junia Okoro,Wed,pending,"asked on Friday, not yet signed off" S-01,Ana Petrovic,Fri,approved,training course S-13,Leila Brannigan,Tue,denied,too many off already S-03,Chidi Laurent,Sun,approved,wedding
output/hours.csv · written by the agent, 15 lines
staff_id,name,shifts,hours S-01,Ana Petrovic,4,32 S-02,Bram Oduya,5,40 S-03,Chidi Laurent,3,24 S-04,Dalia Novak,2,16 S-05,Mateo Alvarez,4,32 S-06,Farah Lindqvist,5,40 S-07,Goran Mistry,4,32 S-08,Hana Whitlock,2,16 S-10,Ivo Castellan,1,8 S-11,Junia Okoro,3,24 S-12,Kasper Thorne,2,16 S-13,Leila Brannigan,5,40 S-14,Milos Ferreira,2,16 S-15,Noor Haddad,0,0
output/notes.md · written by the agent, 45 lines
# Staff schedule notes: Monday 2026-12-07 to Sunday 2026-12-13
The schedule is in `schedule.csv` and each person's totals are in `hours.csv`. All 13 open shifts are filled with exactly the number of people `shifts.csv` asks for (42 places, 336 hours in total). Sun late needs 0 people, so it is closed. A script tested the written schedule against each rule, and every rule passed.
## Result of the test for each rule
| # | Rule | Result |
|---|------|--------|
| 1 | Every shift has exactly the people it needs; closed shift stays empty | PASS. All 13 open shifts match staff_needed. Sun late has nobody. |
| 2 | Each open shift has at least one lead and one forklift ticket | PASS on all 13 open shifts. |
| 3 | Nobody works two shifts on one day | PASS. No one has two rows on the same day. |
| 4 | No late shift followed by the next morning's early shift | PASS. No such pair exists. |
| 5 | 8-hour shifts, nobody over max_hours | PASS. The highest total is 40 hours (S-02, S-06 and S-13), and all three have a max of 40 or more. |
| 6 | Everyone who sent availability gets at least min_hours | PASS. See the lowest-margin cases below. |
| 7 | Only shifts marked yes (blank = no) | PASS. Every assigned shift is marked yes in the availability file. |
| 8 | Approved time off blocks the whole day; pending and denied do not | PASS. Nobody is scheduled on a day of approved time off. |
| 9 | Only people in staff.csv | PASS. Everyone scheduled is in staff.csv, with the name written as in staff.csv. |
Minimum hours met exactly: S-04 Dalia Novak (16), S-12 Kasper Thorne (16), S-14 Milos Ferreira (16), S-08 Hana Whitlock (16), S-03 Chidi Laurent (24), S-11 Junia Okoro (24), S-01 Ana Petrovic (32), S-05 Mateo Alvarez (32), S-07 Goran Mistry (32). S-10 Ivo Castellan has 8 hours against a min of 0 and a max of 20, which is fine. S-15 Noor Haddad has 0 hours (see below).
## People set aside
- **S-09 Petra Vance.** Not in staff.csv, so rule 9 means they cannot be scheduled. They sent a full week of availability, mostly yes. They were not scheduled and are not in `hours.csv`, which lists only people in staff.csv. If Petra Vance should be on the team, staff.csv needs a row with lead, forklift, min_hours and max_hours. Those facts are not in the files, so I did not guess them.
- **S-15 Noor Haddad.** In staff.csv, but there are no availability rows at all. With no shift marked yes, rule 7 means they cannot be placed. They have 0 shifts. Their min_hours is 0, so no rule is broken. Rule 6 applies only to people who sent availability.
## Time off requests and how each was treated
| Person | Day | Status | Treatment |
|---|---|---|---|
| S-08 Hana Whitlock | Thu | approved (dentist) | Off all of Thursday. Hana Whitlock is not on Thu early or Thu late. |
| S-14 Milos Ferreira | Mon | approved (family) | Off all of Monday. Milos Ferreira had marked Mon late as yes, but is not on it. |
| S-01 Ana Petrovic | Fri | approved (training course) | Off all of Friday. Ana Petrovic had marked Fri early as yes, but is not on it. |
| S-03 Chidi Laurent | Sun | approved (wedding) | Off all of Sunday. Chidi Laurent had marked Sun early as yes, but is not on it. |
| S-11 Junia Okoro | Wed | pending ("asked on Friday, not yet signed off") | Does not block. Junia Okoro is scheduled on Wed early. If you approve this request, Wed early needs one more person, and the schedule must be rebuilt and tested again. |
| S-13 Leila Brannigan | Tue | denied (too many off already) | Does not block. Leila Brannigan is scheduled on Tue early. |
## Things in the files that need fixing
1. **Name typed two ways for S-05.** staff.csv says "Mateo Alvarez" but availability.csv says "Matteo Alvarez" on every row. I matched by staff_id and used the staff.csv spelling. Please correct whichever is wrong.
2. **Row sent twice.** availability.csv has the S-07 Goran Mistry Thu row twice (Thu, early yes, late no). I counted it once. Please delete the extra row.
3. **S-09 Petra Vance is in availability.csv but not in staff.csv.** The staff_id sequence also skips from S-08 to S-10. Please add the person to staff.csv or remove their rows.
4. **S-15 Noor Haddad has no availability rows.** Please ask them for availability, or confirm that they are not working this week.
5. **Blank availability cells, treated as no under rule 7.** S-08 Hana Whitlock on Mon early is blank. S-12 Kasper Thorne is blank for both Sun early and Sun late. Please confirm these are meant to be no.
6. **Pending time off for S-11 Junia Okoro on Wed** needs a decision (see above).
7. **Tight cover.** Only a few people can work some shifts, so a small change such as an approved request or a sick day may mean rebuilding the schedule. Sun early can only be worked by S-04 Dalia Novak, S-10 Ivo Castellan and S-11 Junia Okoro, because S-03 Chidi Laurent is off. Only Dalia Novak is a lead and only Ivo Castellan has a forklift ticket, so both must be on it.
output/schedule.csv · written by the agent, 43 lines
day,shift,staff_id,name Mon,early,S-01,Ana Petrovic Mon,early,S-12,Kasper Thorne Mon,early,S-07,Goran Mistry Mon,early,S-13,Leila Brannigan Mon,late,S-05,Mateo Alvarez Mon,late,S-02,Bram Oduya Mon,late,S-11,Junia Okoro Tue,early,S-08,Hana Whitlock Tue,early,S-01,Ana Petrovic Tue,early,S-13,Leila Brannigan Tue,early,S-07,Goran Mistry Tue,late,S-06,Farah Lindqvist Tue,late,S-02,Bram Oduya Tue,late,S-05,Mateo Alvarez Wed,early,S-11,Junia Okoro Wed,early,S-01,Ana Petrovic Wed,early,S-08,Hana Whitlock Wed,early,S-12,Kasper Thorne Wed,late,S-06,Farah Lindqvist Wed,late,S-02,Bram Oduya Wed,late,S-05,Mateo Alvarez Thu,early,S-01,Ana Petrovic Thu,early,S-13,Leila Brannigan Thu,early,S-07,Goran Mistry Thu,early,S-03,Chidi Laurent Thu,late,S-14,Milos Ferreira Thu,late,S-06,Farah Lindqvist Thu,late,S-02,Bram Oduya Fri,early,S-13,Leila Brannigan Fri,early,S-07,Goran Mistry Fri,early,S-05,Mateo Alvarez Fri,early,S-03,Chidi Laurent Fri,late,S-14,Milos Ferreira Fri,late,S-02,Bram Oduya Fri,late,S-06,Farah Lindqvist Sat,early,S-11,Junia Okoro Sat,early,S-04,Dalia Novak Sat,early,S-13,Leila Brannigan Sat,late,S-03,Chidi Laurent Sat,late,S-06,Farah Lindqvist Sun,early,S-04,Dalia Novak Sun,early,S-10,Ivo Castellan
check.py · the check, written before the run
"""Tests the written schedule against every coverage rule, using only the input files to decide who can work when."""
import csv, re, sys
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def load(p): return list(csv.DictReader(p.open()))
def yes(v): return (v or "").strip().lower() == "yes"
staff = {r["staff_id"].strip(): r for r in load(root/"input/staff.csv")}
shifts = load(root/"input/shifts.csv")
days = list(dict.fromkeys(r["day"] for r in shifts))
need = {(r["day"], r["shift"]): int(r["staff_needed"]) for r in shifts}
off = {(r["staff_id"].strip(), r["day"].strip()) for r in load(root/"input/time_off.csv") if r["status"].strip().lower() == "approved"}
avail = load(root/"input/availability.csv")
can = {(r["staff_id"].strip(), r["day"].strip(), sh) for r in avail for sh in ("early", "late")
if yes(r[sh]) and r["staff_id"].strip() in staff and (r["staff_id"].strip(), r["day"].strip()) not in off}
sent = {r["staff_id"].strip() for r in avail}
path = root/"output/schedule.csv"
if not path.exists():
say(False, "output/schedule.csv was not written"); sys.exit(1)
rows = [(r.get("day", "").strip(), r.get("shift", "").strip().lower(), r.get("staff_id", "").strip()) for r in load(path)]
on = {}
for d, sh, s in rows: on.setdefault((d, sh), []).append(s)
open_shifts = [k for k, n in need.items() if n > 0]
exact = sum(1 for k in open_shifts if len(on.get(k, [])) == need[k])
stray = sum(len(v) for k, v in on.items() if need.get(k, 0) == 0)
places = sum(min(len(on.get(k, [])), need[k]) for k in open_shifts)
say(exact == len(open_shifts) and stray == 0, f"{places} of {sum(need.values())} places are filled and {exact} of {len(open_shifts)} open shifts have exactly the number of people they need")
named = {(r.get("staff_id", "").strip(), (r.get("name") or "").strip()) for r in load(path)}
valid = sum(1 for d, sh, s in rows if (s, d, sh) in can and all(n == staff[s]["name"].strip() for i, n in named if i == s))
say(bool(rows) and valid == len(rows), f"{valid} of {len(rows)} assignments are staff on file under the name on file who marked that shift yes and have no approved time off that day")
led = sum(1 for k in open_shifts if any(yes(staff.get(s, {}).get("lead")) for s in on.get(k, [])) and any(yes(staff.get(s, {}).get("forklift")) for s in on.get(k, [])))
say(led == len(open_shifts), f"{led} of {len(open_shifts)} open shifts have a lead and someone with a forklift ticket")
def rested(s):
mine = [(days.index(d), sh) for d, sh, p in rows if p == s and d in days]
if len(mine) != len(set(i for i, _ in mine)): return False # two shifts in one day, or the same row twice
return not any((i, "late") in mine and (i + 1, "early") in mine for i in range(len(days)))
calm = sum(1 for s in staff if rested(s))
say(bool(rows) and calm == len(staff), f"{calm} of {len(staff)} people have no double shift and no late shift followed by an early one")
hours = {s: 8 * sum(1 for _, _, p in rows if p == s) for s in staff}
inside = sum(1 for s, r in staff.items() if hours[s] <= int(r["max_hours"]) and (s not in sent or hours[s] >= int(r["min_hours"])))
say(bool(rows) and inside == len(staff), f"{inside} of {len(staff)} people are inside their minimum and maximum hours for the week")
hpath = root/"output/hours.csv"
hrows = load(hpath) if hpath.exists() else []
hgot = {r.get("staff_id", "").strip(): r for r in hrows}
def n(v):
try: return int(float(v))
except (TypeError, ValueError): return None
match = sum(1 for s in staff if n(hgot.get(s, {}).get("hours")) == hours[s] and n(hgot.get(s, {}).get("shifts")) == hours[s] // 8 and (hgot[s].get("name") or "").strip() == staff[s]["name"].strip())
say(match == len(staff) == len(hrows), f"hours.csv has one row per person on file and agrees with the schedule for {match} of {len(staff)} people, {sum(hours.values())} hours in all")
notes = (root/"output/notes.md").read_text() if (root/"output/notes.md").exists() else ""
aside = sorted((sent - set(staff)) | (set(staff) - sent))
told = sum(1 for s in aside if s in notes)
say(told == len(aside), f"notes.md names {told} of {len(aside)} people set aside: not on the staff list, or no availability sent")
# Numbers in the notes: beside one person they must be that person's own figures, elsewhere a count from the files.
law = (root/"input/coverage_rules.md").read_text()
world = {len(open_shifts), sum(need.values()), sum(hours.values()), len(staff), sum(1 for h in hours.values() if h), 8, 0, len(days), len(shifts)} | set(need.values())
world |= {int(x) for x in re.findall(r"(?m)^(\d+)\.", law)} | {int(r[c]) for r in staff.values() for c in ("min_hours", "max_hours")} | set(hours.values())
world |= {sum(1 for s in staff if (s, d, sh) in can) for d, sh in need}
def own(s): return {hours[s], hours[s] // 8, int(staff[s]["min_hours"]), int(staff[s]["max_hours"])}
seen = wrong = 0; odd = []
for d in re.findall(r"\d{4}-\d{2}-\d{2}", notes):
seen += 1
if d not in law: wrong += 1; odd.append(d)
folk = {r["staff_id"].strip(): r["name"].strip() for r in avail} | {s: r["name"].strip() for s, r in staff.items()}
for i, nm in re.findall(r"\b(S-\d+)\b\W{0,3}([A-Z][a-z]+ [A-Z][a-z]+)?", notes): # a staff number must be real and sit beside its own name
seen += 1
if i not in folk or (nm in folk.values() and nm != folk[i]): wrong += 1; odd.append(i + " " + nm)
for ln in notes.splitlines():
for part in re.split(r"[.,;:]\s|\|", re.sub(r"^\s*\d+\.\s|\d{4}-\d{2}-\d{2}", " ", ln)):
here = [s for s, r in staff.items() if re.search(rf"{s}(?!\d)", part) or r["name"].strip().lower() in part.lower()]
allowed = set().union(*(own(s) for s in here)) if here else world
for x in re.findall(r"(?<![\w.])\d+(?![\w.]|-hour)", re.sub(r"\bS-\d+", " ", part)):
seen += 1
if int(x) not in allowed: wrong += 1; odd.append(x + (" beside " + here[0] if here else ""))
say(seen > 0 and wrong == 0, f"{seen - wrong} of {seen} numbers in notes.md are right: staff numbers match their names, figures beside a person are that person's hours, shifts or limits and the rest are counts from the files" + (": not " + ", ".join(odd[:3]) if odd else ""))
sys.exit(0 if ok else 1)
availability.csv: sample data written by Atris. Fingerprint f0fcbd39c73f.
coverage_rules.md: sample data written by Atris. Fingerprint 0a4d0f919376.
shifts.csv: sample data written by Atris. Fingerprint 1cdd2254fea6.
staff.csv: sample data written by Atris. Fingerprint e0c493ce0ab5.
time_off.csv: sample data written by Atris. Fingerprint a96b1e861daa.
hours.csv: written by the agent. Fingerprint 96280615643d.
notes.md: written by the agent. Fingerprint c331fa2f0a22.
schedule.csv: written by the agent. Fingerprint ad3abbb50784.