Skip to content

feat(question): add DSA study-plan scheduler endpoint - #2306

Merged
KaranUnique merged 1 commit into
Canopus-Labs:mainfrom
vedant7007:build/study-plan-scheduler
Sep 1, 2026
Merged

feat(question): add DSA study-plan scheduler endpoint#2306
KaranUnique merged 1 commit into
Canopus-Labs:mainfrom
vedant7007:build/study-plan-scheduler

Conversation

@vedant7007

@vedant7007 vedant7007 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What & why

Closes #2305.

Turns a practice sheet into a "prep in N days" plan: given a list of problems and a target number of days, it produces a balanced day-by-day schedule.

Changes

  • backend/utils/studyPlanScheduler.js (new, pure, CommonJS) — buildStudyPlan(problems, days) weights problems by difficulty (easy=1, medium=2, hard=3; unknown/missing→medium via problemWeight) and distributes them across days buckets with difficulty-weighted LPT scheduling (assign each, heaviest-first, to the least-loaded day). Returns { plan: [{ day, problems, load }], totalLoad, days }. Deterministic; guards invalid input.
  • questionController.jsbuildStudyPlanHandler with inline validation (non-empty array, ≤1000 problems, integer days 1–365), mirroring the existing atsMatch style.
  • questionRoutes.jsPOST /api/question/study-plan (auth + rate-limit already applied globally).

No new dependency; no package.json/lockfile changes.

Testing

  • backend/tests/studyPlanScheduler.unit.test.js — 11 vitest cases (weights, load balancing, exactly-once placement, empty days, default difficulty, determinism, input guards).
  • Full backend vitest run207 passed (18 files).

Contributing as part of Elite Coders Summer of Code (ECSoC 2026).

Adds an authenticated POST /api/question/study-plan endpoint.

  • Uses deterministic, pure LPT scheduling with difficulty weights: easy 1, medium 2, hard 3.
  • Defaults missing or unknown difficulty to medium.
  • Supports empty days when days exceeds the problem count.
  • Validates problem lists and day counts.
  • Adds 11 Vitest unit tests.
  • Full backend suite passes: 207 tests across 18 files.

POST /api/question/study-plan distributes a list of problems across N
days using difficulty-weighted LPT scheduling so day loads stay balanced.
Core is a pure, unit-tested buildStudyPlan util; no new dependency.

Closes Canopus-Labs#2305
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Thank you for submitting your pull request, @vedant7007! 🙌
We'll review it as soon as possible.
If there are any specific instructions or feedback regarding your PR, we'll provide them here.
Thanks again for your contribution to our project! 😊

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 95f43cb9-5ae5-4056-8037-695c7130244e

📥 Commits

Reviewing files that changed from the base of the PR and between ecb5cef and 3652452.

📒 Files selected for processing (4)
  • backend/controllers/questionController.js
  • backend/routes/questionRoutes.js
  • backend/tests/studyPlanScheduler.unit.test.js
  • backend/utils/studyPlanScheduler.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Adds a deterministic, difficulty-weighted study-plan scheduler. The new POST /api/question/study-plan endpoint validates inputs, builds balanced day buckets, and returns the generated plan. Unit tests cover weighting, scheduling, determinism, and invalid inputs.

Changes

Study plan scheduling

Layer / File(s) Summary
Deterministic study-plan scheduling
backend/utils/studyPlanScheduler.js, backend/tests/studyPlanScheduler.unit.test.js
Adds difficulty weights, medium defaults, stable ordering, least-loaded-day assignment, input validation, deterministic output, and unit tests.
Study-plan API endpoint
backend/controllers/questionController.js, backend/routes/questionRoutes.js
Adds request validation, scheduler invocation, response handling, and the POST /api/question/study-plan route.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to 36524

The PR adds an authenticated, rate-limited study-plan endpoint that performs bounded in-process scheduling. The change is mergeable, with explicit owner awareness that the new API surface introduces a limited compute and availability exposure despite input limits and access controls.

Suggested reviewers: ionfwsrijan

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant questionRoutes
  participant buildStudyPlanHandler
  participant buildStudyPlan
  Client->>questionRoutes: POST /api/question/study-plan
  questionRoutes->>buildStudyPlanHandler: Forward request
  buildStudyPlanHandler->>buildStudyPlan: Pass problems and days
  buildStudyPlan-->>buildStudyPlanHandler: Return plan and totalLoad
  buildStudyPlanHandler-->>Client: Return study-plan response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: a DSA study-plan scheduler endpoint.
Linked Issues check ✅ Passed The changes satisfy issue [#2305]. They add the endpoint, implement deterministic difficulty-weighted LPT scheduling, validate inputs, support empty days, and add unit tests for the scheduler.
Out of Scope Changes check ✅ Passed All changes support issue [#2305]. The additional 1000-problem limit is related input validation. No unrelated code or dependency changes are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 Biome (2.5.8)
backend/tests/studyPlanScheduler.unit.test.js

File contains syntax errors that prevent linting: Line 1: Illegal use of an import declaration outside of a module; Line 2: Illegal use of an import declaration outside of a module


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.

@KaranUnique
KaranUnique merged commit 647ce41 into Canopus-Labs:main Sep 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DSA study-plan scheduler endpoint

2 participants