Skip to content

feat: Student dashboard has no chapter-wise weak area identification β€” completed quiz attempts are not analyzed to show which chapters need the most revisionΒ #457

Description

@divyanshim27

πŸš€ Problem Statement

VidyaSetu documents "Student dashboard and analytics views" as a core feature. The dashboard currently shows general statistics, but does not identify which specific chapters a student is consistently struggling with based on their quiz history.

For an adaptive study platform, knowing that a student scores below 60% on "Acids, Bases and Salts" (Class 10 Chemistry) across multiple attempts is far more actionable than knowing their overall average. Without this view, VidyaSetu's analytics are cosmetic rather than adaptive.

Expected Behavior

A "Weak Chapters" panel on the student dashboard should:

  • Query all quiz attempts for the logged-in student
  • Group by chapterId and calculate average score percentage per chapter
  • Surface the bottom 3-5 chapters by average score with a "Revise Now" CTA that links directly to that chapter's revision mode quiz
  • Show a bar chart or progress ring per subject showing chapter-level performance

Proposed Implementation

New API route GET /api/analytics/weak-chapters:

import { prisma } from "@/lib/prisma";
import { getServerSession } from "next-auth";

export async function GET() {
  const session = await getServerSession(authOptions);
  if (!session?.user?.id) return new Response("Unauthorized", { status: 401 });

  const attempts = await prisma.quizAttempt.findMany({
    where: { userId: session.user.id },
    include: { chapter: { include: { subject: true } } },
  });

  // Group by chapterId and compute average score %
  const chapterMap = new Map<string, { chapter: any; scores: number[] }>();

  for (const attempt of attempts) {
    const pct = (attempt.score / attempt.totalQ) * 100;
    const entry = chapterMap.get(attempt.chapterId) ?? {
      chapter: attempt.chapter,
      scores: [],
    };
    entry.scores.push(pct);
    chapterMap.set(attempt.chapterId, entry);
  }

  const weakChapters = [...chapterMap.values()]
    .map(({ chapter, scores }) => ({
      chapterId: chapter.id,
      chapterTitle: chapter.title,
      subject: chapter.subject.name,
      avgScore: scores.reduce((a, b) => a + b, 0) / scores.length,
      attempts: scores.length,
    }))
    .filter(c => c.attempts >= 2)          // Minimum 2 attempts for reliability
    .sort((a, b) => a.avgScore - b.avgScore) // Sort ascending (worst first)
    .slice(0, 5);                            // Top 5 weakest

  return Response.json({ weakChapters });
}

Frontend β€” add a "Focus Areas" card to the dashboard:

Render the weak chapters list with:

  • Chapter name + subject name
  • Average score as a percentage ring
  • "Revise Now" button linking to /quiz/revision?chapterId=xxx

Files to Create/Modify

File Change
src/app/api/analytics/weak-chapters/route.ts New endpoint
src/ (dashboard page/component) Add "Focus Areas" section

πŸ“Š Impact

This directly fulfills VidyaSetu's stated mission: "helping students move from passive studying to structured practice." Without chapter-level weakness identification, students don't know where to direct their revision effort. This feature turns raw quiz history into an actionable, personalized study plan.

Suggested labels: enhancement, analytics, frontend, backend, gssoc:level2

I would like to work on this. Could you please assign it to me?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions