Analytics
Read-only counts behind one controller. Each route hands off to the service that owns the data, and every count runs on a school-scoped repository.
One controller at analytics/* answers every analytics screen. It does no counting itself: each route calls the service that owns the data. Nothing is cached, so every request counts live rows.
Routes
Every route needs read on analytics, except audit logs. A route with a /campus/:campusId twin filters to that campus.
| Route | Campus twin | Extra permission | Calls |
|---|---|---|---|
students, staff, guardians | Yes | None | Each profile service's getAnalytics |
guests | No | None | GuestService.getAnalytics |
classes | Yes | None | ClassService.getAnalytics |
classes/:classId | No | Read on that class (checked in the service) | getClassDetailAnalytics |
applications | Yes | None | AdmissionApplicationService.getAnalytics |
enquiries, enquiries/by-period, enquiries/by-staff | No | None | Enquiry getStats, getStatsByPeriod, getStatsByStaff |
academics | Yes | Read on grade | AcademicAnalyticsService |
teaching | Yes | Read on scheme_of_work | TeachingAnalyticsService |
audit-logs | No | Read on audit_log instead of analytics | AuditLogService.getAnalytics |
Two rules for a new count
- Build it on a scoped repository. Use
this.someRepository.createQueryBuilder(...), neverdataSource.query. Then theschool_idfilter applies to everyCOUNTas it does to every list. The usual shape:Promise.allover several counts,COUNT(DISTINCT ...), explicitdeleted_at IS NULL, and an inner join tocampus_x_academic_yearwithis_current = truewhen "this year" matters. - Reuse the date window. Extend
AnalyticsTimelineQueryDto(optionalstartDate,endDate) and callresolveAnalyticsDateRange. It defaults to the last 30 days and returnsendDatePlusOne, so queries use[start, end + 1). When start and end fall on the same day, timelines bucket by hour. Return the shared shapes such asTimelineDataPointDto { date, count }.
The academics and teaching routes use a term instead of a date window; see Term-based counts.
What each count covers
The trap on every route: only some fields use the date window. The rest cover all time, the current year, or the calendar month.
| Route | Uses the date window | Ignores the window |
|---|---|---|
| People (all four) | dailyTimeline | total, active, suspended, newThisMonth (calendar month), recent (newest 5) |
| Classes | enrollmentTimeline | Stream and enrolment counts, byLevel, byGradeLevel, gradeTimeline (current year only) |
| Applications | dailyTimeline | total, byStatus |
| Enquiries | total, unassignedCount, averageResolutionTimeSeconds, byStatus, byPriority, dailyTimeline | newThisMonth, recent |
| Audit logs | Everything | Nothing |
An unknown campus or year id is never an error. The response is 200 with zeros and empty lists.
Term-based counts
academics and teaching take AnalyticsTermQueryDto: optional academicYearId and term (1 to 3). TermPeriodService.resolve picks the period:
Year. The given id if it exists, otherwise the current year, otherwise the highest order. No year at all returns the empty shape (period null, zeros).
Term. The given term, otherwise the highest current term, otherwise 1. A campus route keeps only that campus's terms.
Previous term. The one before it; term 1 compares with the last term of the previous year.
term arrives as a string, because the pipe does not transform it; the service runs Number(query.term).
Academics turns marks into percents (18 of 20 is 90), skipping max_score 0 and deleted rows. It returns averagePercent and previousAveragePercent, counts graded students, grades and subjects, bySubject, byGradeLevel, bands, and a termTrend across the year. Report cards are counted by status; released counts rows with released_at set, on top of their status. For CBT, the average and passRate use graded attempts only.
Teaching counts lesson plans in the term. done is published plus approved. byWeek and bySubject (furthest behind first) break that down. Schemes count as approved, in review (a submitted revision exists) or draft.
Two lists only appear for managers, and are left out silently otherwise:
| List | Needs |
|---|---|
topStudents, needsAttention (at least 3 subjects, max 10) | Approve on report_card for that campus, or the school |
byTeacher | Approve on lesson_plan or scheme_of_work |
In the Education Hub
| Screen | Path | Who can open it |
|---|---|---|
| School analytics | /staff-hub/school/analytics | Read on analytics or audit_log |
| Campus analytics | /staff-hub/campus/$campusId/analytics | Read on analytics |
Both use AnalyticsLayout, OverviewCards and AreaPage. useVisibleAreas decides which areas show:
| Area | Also needs | Campus hub |
|---|---|---|
| Academics | Read on grade | Shown |
| Teaching | Read on scheme_of_work and the lesson-planning flag | Shown |
| Admissions | The admissions flag | Shown |
| Enquiries | The admissions flag | Hidden |
| Guests, audit logs | Audit logs: read on audit_log | Hidden |
An area the viewer cannot open redirects to the overview.
Screen sums to know before you trust a number:
- "New this period" on people cards is the sum of
dailyTimeline, notnewThisMonth. - "Awaiting decision" is
submittedfrombyStatus, so it covers all time, not the window. - Enquiry resolution rate on the tab is
completedovertotal. The staff table uses the service'sresolutionRate(resolved_atover assigned), a different measure. - "Cannot sign in" on staff and guardian tiles is screen wording. The service only counts suspended profiles; it does not check sign-in.
- Released report cards sit beside the status total, not inside it.