curl --request POST \
--url https://api.example.com/api/exam-results \
--header 'Content-Type: application/json' \
--data '
{
"examId": "<string>",
"totalQuestions": 123,
"correctAnswers": 123,
"totalTimeMinutes": 123
}
'{
"message": "<string>",
"examResult": {},
"examResult.examId": "<string>",
"examResult.barScore": 123,
"examResult.percentile": 123,
"examResult.totalQuestions": 123,
"examResult.correctAnswers": 123,
"examResult.incorrectAnswers": 123,
"examResult.skippedAnswers": 123,
"examResult.totalTimeMinutes": 123,
"examResult.averageTimePerQuestion": 123,
"examResult.strengths": [
{}
],
"examResult.areasForImprovement": [
{}
],
"examResult.timestamp": "<string>",
"studyStreak": 123,
"totalMarks": 123,
"performanceInsights": [
{}
],
"error": "<string>"
}Save exam results, calculate bar scores and percentiles, and track performance insights
curl --request POST \
--url https://api.example.com/api/exam-results \
--header 'Content-Type: application/json' \
--data '
{
"examId": "<string>",
"totalQuestions": 123,
"correctAnswers": 123,
"totalTimeMinutes": 123
}
'{
"message": "<string>",
"examResult": {},
"examResult.examId": "<string>",
"examResult.barScore": 123,
"examResult.percentile": 123,
"examResult.totalQuestions": 123,
"examResult.correctAnswers": 123,
"examResult.incorrectAnswers": 123,
"examResult.skippedAnswers": 123,
"examResult.totalTimeMinutes": 123,
"examResult.averageTimePerQuestion": 123,
"examResult.strengths": [
{}
],
"examResult.areasForImprovement": [
{}
],
"examResult.timestamp": "<string>",
"studyStreak": 123,
"totalMarks": 123,
"performanceInsights": [
{}
],
"error": "<string>"
}const barScore = correctAnswers * 4;
/workspace/source/src/app/api/exam-results/route.ts:68
const percentile = Math.round((correctAnswers / totalQuestions) * 100);
/workspace/source/src/app/api/exam-results/route.ts:71
const totalTimeSeconds = totalTimeMinutes * 60;
const averageTimePerQuestion = totalTimeSeconds / totalQuestions;
/workspace/source/src/app/api/exam-results/route.ts:74-75
const incorrectAnswers = totalQuestions - correctAnswers;
const skippedAnswers = 0; // Currently not tracked
/workspace/source/src/app/api/exam-results/route.ts:78-79
import { examStrengthsAndImprovements } from "@/lib/examStrengthsAndImprovements";
const strengthsAndImprovements = examStrengthsAndImprovements[examId] || {
strengths: [],
areasForImprovement: [],
};
/workspace/source/src/app/api/exam-results/route.ts:3,82-85
examId already exists, updates that entry/workspace/source/src/app/api/exam-results/route.ts:117-144
const existingExamIndex = performanceInsights.findIndex(
(exam: any) => exam.examId === examId
);
if (existingExamIndex !== -1) {
// Update existing
performanceInsights[existingExamIndex] = { ...updatedData };
} else {
// Add new, remove oldest if >= 7
if (performanceInsights.length >= 7) {
performanceInsights.shift();
}
performanceInsights.push({ ...newData });
}
const today = new Date().toISOString().split("T")[0];
const lastStudyDate = userData.lastStudyDate || "";
let studyStreak = userData.studyStreak || 0;
if (lastStudyDate !== today) {
studyStreak += 1; // Only increment if not already studied today
}
/workspace/source/src/app/api/exam-results/route.ts:104-111
curl -X POST 'https://api.lsattraining.com/api/exam-results?uuid=user123' \
-H 'Content-Type: application/json' \
-d '{
"examId": "bar_exam_2024_july",
"totalQuestions": 50,
"correctAnswers": 38,
"totalTimeMinutes": 90
}'
{
"message": "Exam results saved successfully",
"examResult": {
"examId": "bar_exam_2024_july",
"barScore": 152,
"percentile": 76,
"totalQuestions": 50,
"correctAnswers": 38,
"incorrectAnswers": 12,
"skippedAnswers": 0,
"totalTimeMinutes": 90,
"averageTimePerQuestion": 108,
"strengths": [
"Constitutional Law",
"Contract Analysis",
"Legal Writing"
],
"areasForImprovement": [
"Criminal Procedure",
"Evidence Rules",
"Time Management"
],
"timestamp": "2024-03-03T15:45:00.000Z"
},
"studyStreak": 12,
"totalMarks": 200,
"performanceInsights": [
{
"examId": "bar_exam_2024_july",
"totalQuestions": 50,
"correctAnswers": 38,
"totalTimeMinutes": 90,
"timestamp": "2024-03-03T15:45:00.000Z"
},
{
"examId": "bar_exam_2024_feb",
"totalQuestions": 50,
"correctAnswers": 35,
"totalTimeMinutes": 95,
"timestamp": "2024-02-15T10:30:00.000Z"
}
]
}
{
"error": "UUID is required"
}
{
"error": "Invalid JSON format"
}
{
"error": "Missing required fields"
}
{
"error": "User not found"
}
{
"error": "Failed to save exam results"
}
await userRef.update({
examResult, // Complete exam result object
studyStreak, // Updated streak
lastStudyDate: today, // Current date (YYYY-MM-DD)
totalMarks, // Total possible marks
performanceInsights, // Array of recent exams (max 7)
});
/workspace/source/src/app/api/exam-results/route.ts:147-153
examStrengthsAndImprovements mapping/workspace/source/src/app/api/exam-results/route.ts