Skip to content

feat(crew): add staffing calculator#529

Merged
theianjones merged 2 commits into
mainfrom
codex/crew-staffing-calculator
Jun 19, 2026
Merged

feat(crew): add staffing calculator#529
theianjones merged 2 commits into
mainfrom
codex/crew-staffing-calculator

Conversation

@zacjones93

@zacjones93 zacjones93 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a public Crew /calculator route for estimating judges, volunteers, concurrent staffing, and shift slots.
  • Add pure staffing calculator helpers with default role assumptions for lanes, floors, heats, heat duration, and shift length.
  • Link the calculator from the Crew shell nav/home route list and update the generated TanStack route tree.
  • Cover role/time assumptions with focused Vitest unit tests.

Validation

  • pnpm check:schema-ownership passed.
  • pnpm --filter crew type-check passed.
  • pnpm --filter crew build passed after creating ignored validation-only apps/crew/.alchemy/local/wrangler.jsonc from the checked-in Crew wrangler config. No Alchemy/deploy command was run.
  • pnpm --filter crew lint exited 0; it still reports existing repo warnings outside this slice.
  • pnpm --filter crew exec vitest run test/lib/crew-staffing-calculator.test.ts passed: 5 tests.
  • git diff --check passed.

Notes

  • pnpm --filter crew test was attempted and failed on pre-existing/unrelated suites: missing legacy imports under routes/compete/... and routes/api/webhooks/stripe, plus existing invite permission timeout/assertion failures. The new calculator test passed during that full run.
  • pnpm install completed, with the known optional better-sqlite3 native rebuild failure from Python 3.7 on this machine.

Summary by cubic

Adds a public Crew staffing calculator at /calculator to estimate judges, volunteers, concurrent staffing, and shift slots from simple event inputs. Adds nav/home links, a helper library with defaults and normalization, and tests.

  • New Features
    • New /calculator route with inputs for lanes, floors, heats, heat duration, and shift length; shows per‑role concurrent coverage and shift slots.
    • Helper library: estimateCrewStaffing, formatStaffingDuration, normalizeStaffingCalculatorInputs, and default role assumptions; supports event, floor, lane, and lanePerFloor; returns per‑role and group totals; covered by vitest tests for scaling, coverage, normalization, and formatting.
    • Crew shell updates: adds “Calculator” nav link and home CTA; updates route tree via @tanstack/react-router.
    • Operator notes in lat.md/crew.md.

Written for commit 99ec4b0. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added a staffing calculator tool to estimate crew requirements based on event parameters (lanes, floors, heats, shift duration).
    • Displays per-role staffing estimates with judges and volunteers breakdown and coverage details.
    • Allows customization of role assumptions for refined estimates.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

A new staffing calculator module (crew-staffing-calculator.ts) is introduced with domain types, default role assumptions, and the estimateCrewStaffing function that normalizes event inputs and computes per-role shift slot counts. A new /calculator React page renders editable inputs and role assumptions with derived summary panels. The route is registered in the TanStack Router tree and linked from the shell navigation and home page.

Changes

Crew Staffing Calculator

Layer / File(s) Summary
Staffing calculator types, defaults, estimation logic, and tests
apps/crew/src/lib/crew-staffing-calculator.ts, apps/crew/test/lib/crew-staffing-calculator.test.ts
Exports StaffingRoleGroup, StaffingRoleBasis, and four interfaces; provides defaultStaffingRoleAssumptions and defaultStaffingCalculatorInputs; implements estimateCrewStaffing (input normalization, basis-unit mapping, per-role shift-slot derivation, judge/volunteer aggregation) and formatStaffingDuration; Vitest suite validates scaling, heat-to-coverage conversion, group separation, minimum normalization, and duration formatting.
Calculator page UI and local components
apps/crew/src/routes/calculator.tsx
Creates the /calculator route page with inputs state, memoized estimateCrewStaffing call, updateNumberField/updateRole handlers, event assumption inputs, summary panels for judge/volunteer/total slots, an editable role assumptions table, and coverage notes. Adds local components NumberField, RoleRow, SummaryPanel, SummaryBadge, and Fact.
Route registration and navigation links
apps/crew/src/routeTree.gen.ts, apps/crew/src/routes/__root.tsx, apps/crew/src/routes/index.tsx
Registers CalculatorRoute in all TanStack Router type maps and the runtime routeTree; adds a "Calculator" nav link with active styling to the shell root; adds an "Estimate staffing" primary button and a route list entry to the index page.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hippity-hop, I count the lanes,
How many judges for all those heats and pains?
Floors times roles, I clamp and I sum,
Shift slots appear — the math is done!
/calculator is live, the rabbit hops in cheer 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat(crew): add staffing calculator' directly and clearly summarizes the main change—adding a new staffing calculator feature to the crew module.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/crew-staffing-calculator

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zacjones93 zacjones93 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign-off: no remaining actionable blockers

@theianjones theianjones marked this pull request as ready for review June 19, 2026 07:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/crew/src/lib/crew-staffing-calculator.ts (1)

1-204: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add required @lat concept references in this TypeScript module.

This file currently has no // @lat: [[section-id]] annotations, which breaks the repo’s source-to-concept traceability rule.

As per coding guidelines, **/*.{js,ts,rs,go,c,h,py} must tie source code to concepts using // @lat: [[section-id]].

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/crew/src/lib/crew-staffing-calculator.ts` around lines 1 - 204, The
crew-staffing-calculator.ts file is missing required `// `@lat`: [[section-id]]`
concept reference annotations needed for source-to-concept traceability. Add `//
`@lat`: [[section-id]]` comments above logical groupings of related code to tie
each section to its corresponding concept identifier. Place these annotations
before the type definitions block (StaffingRoleGroup, StaffingRoleBasis,
StaffingRoleAssumption, etc.), before the constant definitions
(defaultStaffingRoleAssumptions, defaultStaffingCalculatorInputs), before the
main calculation function estimateCrewStaffing, before the formatting function
formatStaffingDuration, and before the helper functions
(normalizeStaffingCalculatorInputs, getRoleBasisUnits, sumRoleValue,
clampWholeNumber, clampDecimal) using appropriate section identifiers that match
your project's concept documentation.

Source: Coding guidelines

🧹 Nitpick comments (1)
apps/crew/src/routes/calculator.tsx (1)

20-49: Migrate form state to React Hook Form + Zod for consistency with project standard.

This calculator currently uses manual state management and validation. Align with the established pattern across the crew app by adopting React Hook Form with Zod schemas to reduce custom parsing logic and improve maintainability.

Applies to lines 20-49 (input state), 76-122 (number field handlers), and 244-285 (role updates).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/crew/src/routes/calculator.tsx` around lines 20 - 49, Replace the manual
useState-based state management for the StaffingCalculatorInputs with React Hook
Form's useForm hook and Zod schema validation. Create a Zod schema for
StaffingCalculatorInputs that defines validation rules for all numeric fields
(lanes, floors, heats, heatDurationMinutes, shiftLengthHours) and the
roleAssumptions array. Update the updateNumberField and updateRole functions to
use the form's field register and setValue methods instead of direct setInputs
calls, and leverage Zod's validation instead of inline Number.isFinite checks.
This aligns the component with the established React Hook Form + Zod pattern
used elsewhere in the crew app.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/crew/test/lib/crew-staffing-calculator.test.ts`:
- Around line 45-105: The test file is missing required `@lat` reference
comments for test specifications. Add exactly one `// `@lat`: [[section-id]]`
comment adjacent to each of the five `it(...)` test blocks: the tests for
"scales lane judge assumptions by floors and lanes", "converts heat time into
shift slots for coverage", "keeps judge and volunteer estimates separated",
"normalizes invalid minimums without producing zero coverage", and "formats full
hours and mixed durations". Ensure each `@lat` comment is placed immediately
next to its corresponding `it()` declaration and that no section IDs are
duplicated across the different tests.

---

Outside diff comments:
In `@apps/crew/src/lib/crew-staffing-calculator.ts`:
- Around line 1-204: The crew-staffing-calculator.ts file is missing required
`// `@lat`: [[section-id]]` concept reference annotations needed for
source-to-concept traceability. Add `// `@lat`: [[section-id]]` comments above
logical groupings of related code to tie each section to its corresponding
concept identifier. Place these annotations before the type definitions block
(StaffingRoleGroup, StaffingRoleBasis, StaffingRoleAssumption, etc.), before the
constant definitions (defaultStaffingRoleAssumptions,
defaultStaffingCalculatorInputs), before the main calculation function
estimateCrewStaffing, before the formatting function formatStaffingDuration, and
before the helper functions (normalizeStaffingCalculatorInputs,
getRoleBasisUnits, sumRoleValue, clampWholeNumber, clampDecimal) using
appropriate section identifiers that match your project's concept documentation.

---

Nitpick comments:
In `@apps/crew/src/routes/calculator.tsx`:
- Around line 20-49: Replace the manual useState-based state management for the
StaffingCalculatorInputs with React Hook Form's useForm hook and Zod schema
validation. Create a Zod schema for StaffingCalculatorInputs that defines
validation rules for all numeric fields (lanes, floors, heats,
heatDurationMinutes, shiftLengthHours) and the roleAssumptions array. Update the
updateNumberField and updateRole functions to use the form's field register and
setValue methods instead of direct setInputs calls, and leverage Zod's
validation instead of inline Number.isFinite checks. This aligns the component
with the established React Hook Form + Zod pattern used elsewhere in the crew
app.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 507e309d-0725-4d0b-84d8-b27cefaa89ad

📥 Commits

Reviewing files that changed from the base of the PR and between eb43e5a and 13bc450.

📒 Files selected for processing (6)
  • apps/crew/src/lib/crew-staffing-calculator.ts
  • apps/crew/src/routeTree.gen.ts
  • apps/crew/src/routes/__root.tsx
  • apps/crew/src/routes/calculator.tsx
  • apps/crew/src/routes/index.tsx
  • apps/crew/test/lib/crew-staffing-calculator.test.ts

Comment thread apps/crew/test/lib/crew-staffing-calculator.test.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/crew/src/routes/calculator.tsx Outdated
Comment thread apps/crew/test/lib/crew-staffing-calculator.test.ts

@zacjones93 zacjones93 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign-off: no remaining actionable blockers

@theianjones theianjones merged commit 0e0f3fb into main Jun 19, 2026
15 checks passed
@theianjones theianjones deleted the codex/crew-staffing-calculator branch June 19, 2026 07:54
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.

2 participants