School reports
How a monthly or termly school report is planned, written, painted and downloaded, and what its numbers count.
A school report is a set of PDFs about the school and each campus for a month or a term. It is not a learner's report card. Every route needs Feature.SCHOOL_REPORTS and starts with /api/v1/school-report.
Routes
| Route | Operation id | Needs | Notes |
|---|---|---|---|
POST /runs | createSchoolReportRun | create | Starts a monthly or termly run |
POST /runs/:id/retry | retrySchoolReportRun | create | Re-queues failed documents. No failed documents to retry if none |
GET /runs | listSchoolReportRuns | list | With campusId, each run keeps only that campus's documents |
GET /runs/:id | getSchoolReportRun | read | Drops documents for campuses you can't read |
GET /documents/:id/download | downloadSchoolReportDocument | read on that campus | A signed link valid for one hour. This document is not ready yet until it is |
GET /styles | listSchoolReportStyles | read | The painting styles |
Permissions are on school_report. Create and retry publish SCHOOL_REPORT_RUN_UPDATE so screens refresh.
What a run plans
| Monthly | Termly, started by staff | Termly, from the daily tick | |
|---|---|---|---|
| Period | One calendar month | Earliest campus term start to the latest end, or to now with "(to date)" | Same |
| Campus documents | Every campus | Every campus with that term number | Only campuses whose term has ended |
| School document | Always | Always | Only once every campus has ended |
ensureRun creates the run, or adopts the existing one if two callers race on the same period. Pending documents are queued; failed ones are re-queued on a manual start, or when a to-date run is being extended to the full term. Each job gets one attempt.
How a document is made
The worker (SchoolReportProcessor, concurrency 2) runs each document through:
Count. A campus document collects admissions, enrolments, structure, grades, staff and students. The school document collects enquiries, guest accounts and one summary row per campus.
Write. A model writes a summary, one block per section, headlines of up to twelve words, and a callout per fact. It times out at 120 seconds and retries once. The words are refused if they contain an em dash or ellipsis, or any number that isn't in that section's data.
Paint. Each page (a cover plus one per section) is drawn as a 1248x1760 PNG by the configured gpt-image-2 model, in the school's schoolReportStyle. A reader then checks the picture: missing or cut-off words, or an invented number, fail it. A failed page is redrawn once; a second failure fails the document.
Store. The PDF is saved and the document becomes ready. When the run is complete and this was the school document, runReady fires.
Any failure marks the document failed with the error. The daily tick doesn't retry it; staff retry from the screen.
What the numbers count
| Figure | Counts |
|---|---|
| Active enrolments at a moment | Rows active now, or now in an exit status but updated at or after that moment. There is no status history |
| New enrolments | date_enrolled inside the window |
| Leavers | The latest 100 in an exit status (transferred, graduated, dropped, withdrawn, suspended, revoked, expired, excluded, cancelled, rejected) |
| Grade average | score / max_score * 100 for grades created in the window for that term. Pass share is rows with points above 0 |
| Top and bottom subjects | Subjects with at least five graded learners |
| Applications decided | Counted once, at the first move to offered, admitted, rejected or enrolled. offered is kept so older history still counts |
| Applications pending | draft, submitted or approved. Long-pending is over 30 days old, at most 50 |
| Staff who left | Deactivated, suspended or deleted in the window. There is no employment end date |
| Teaching load | subject_x_teacher rows per teacher, in buckets 0, 1-3, 4-6, 7+ |
| Open enquiries | new or contacted, or resolved after the window end. Median hours use the first contacted entry and resolved_at |
Comparisons use the previous month, the previous term on that campus, or for the school document the previous term number across the school. Grades are left out when no campus term covers the window end.
The daily tick
Two cron jobs, cron.schoolReportsMonthly and cron.schoolReportsTermly, both default to 0 0 * * *: 00:00 UTC, which is 03:00 in Kampala. CRON_ENABLED=0 turns them off. Older plan and onboarding notes quote other times; the env schema is what runs.
| Monthly tick | Termly tick | |
|---|---|---|
| Which schools | Active, with the school reports flag on | Same |
| Period | The previous month in the school's time zone (default Africa/Kampala) | Terms that ended in the last 45 days, grouped by school, year and term number |
| Existing run | Left alone, even if failed | Passed back in, so later campuses and the full term can be added |
| One school fails | Logged, the next school runs | Logged, the next group runs |