fix(year-level): prefer units-passed standing over calendar-year history count
ci / test (push) Successful in 2m21s
ci / test (pull_request) Successful in 38s

The grade-history method counted distinct academic years, which over-advanced
standing for students who repeated/failed a year (e.g. showing Year 5 when the
student is genuinely Year 4, since a partial 2025 year didn't advance them).

Reorder the hybrid so the UNITS math (total prospectus units minus still-lacking
units = units actually passed) is primary, and View Grades history is only a
fallback when units data is unavailable.
This commit is contained in:
2026-08-20 08:54:55 +08:00
parent 3067335274
commit 90e4107bf0
2 changed files with 21 additions and 15 deletions
+7 -6
View File
@@ -101,12 +101,13 @@
return history;
}
// Standing for the study load printed at (semester, year): it is the number
// of distinct academic years strictly before that term's year + 1. SUMMER of
// year Y is the same standing as the rest of year Y (the student has just
// finished the preceding level during Y's regular semesters). Clamped to at
// most the number of distinct years in history (a student cannot be past the
// final level recorded).
// Standing for a study load printed in `year` from the View Grades history.
// It is the number of distinct academic years strictly before that year + 1
// (FIRST/SECOND/SUMMER of a year share the same standing), clamped to at most
// the number of distinct years in history. NOTE: this is only an
// approximation for the printed semester — it counts calendar years present,
// not units passed — so a repeated/failed year can over-advance. It is used
// only as a fallback when the units-based standing is unavailable.
function yearLevelForSemester(history, year) {
if (!history || !history.length || !Number.isFinite(year)) return null;
const distinctYears = [...new Set(history.map((t) => t.year))].sort((a, b) => a - b);