Skip to content

fix: pass offerings to slotUsedWeight in semester-row so FY units aren't double-counted" #15

Open
coldfinity wants to merge 1 commit into
monashcoding:mainfrom
coldfinity:fix/fy-unit-double-count-in-semester-row
Open

fix: pass offerings to slotUsedWeight in semester-row so FY units aren't double-counted" #15
coldfinity wants to merge 1 commit into
monashcoding:mainfrom
coldfinity:fix/fy-unit-double-count-in-semester-row

Conversation

@coldfinity

@coldfinity coldfinity commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Full-year (FY) units like FIT3170 (12cp, runs across S1+S2) appear in both S1 and S2 of a year, with each twin contributing half the unit's workload per semester. The planner displays usedWeight / capacity units on the left rail to show how full each semester is.

But semester-row was double-counting FY units:

Actual Before (broken) After (fixed)
1 × FY 12cp in S1 2 / 4 units 1 / 4 units
1 × FY 12cp in S1 + S2 2 / 4 each 1 / 4 each
2 × FY 12cp + 1 × 6cp in S1 5 / 4 units (overflow!) 3 / 4 units

A student adding a single FY unit would see "2 / 4 units" and think the semester was half-full when it wasn't. With multiple FY units the display could even show usedWeight > capacity.

Root cause

slotUsedWeight in types.ts has an optional offerings parameter. When present, it checks whether a unit is full-year via isFullYearTwinSlot and halves its CP contribution per semester (so a 12cp FY unit = weight 1 per semester, not 2). Without offerings, the FY check is always skipped.

semester-row.tsx was the only call site (out of 10) that omitted offerings:

File Passes offerings?
semester-row.tsx ❌ → ✅ fixed
semester-slot.tsx
draggable-unit-row.tsx
plan-grid.tsx (6 calls)
progress.ts
validation.ts

Fix

2-line change in packages/webapp/components/planner/semester-row.tsx:

-  const { dispatch, units } = usePlanner()
-  const usedWeight = slotUsedWeight(slot, units)
+  const { dispatch, units, offerings } = usePlanner()
+  const usedWeight = slotUsedWeight(slot, units, offerings)

Testing

pnpm --filter webapp build

To verify

  1. Create a plan with a course that includes a full-year unit (e.g. FIT3170 any unit whose offerings are exclusively FULL_YEAR)
  2. Add it to planner, it should appear in both S1 and S2
  3. Check the left rail label, it should show 1 / 4 units for each semester, not 2 / 4
  4. Add another FY unit, should show 2 / 4, not 4 / 4 and overflowing
  5. Verify the capacity controls (Add/Remove unit slots) still work correctly
  6. Verify normal (non-FY) units are unaffected

Fixes #13.

…n't double-counted

semester-row.tsx was the only call site of slotUsedWeight that omitted the
offerings parameter. Without it, full-year units had their entire CP counted
toward usedWeight in each semester (weight=2 for a 12cp unit instead of
weight=1), causing the 'X / Y units' display to show incorrect numbers.

Fixes monashcoding#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect number of units displayed for semester

1 participant