feat: implement modern Sınav Rapor dashboard with dual-metric delta tracking and inline mistake review

This commit is contained in:
tyuXX 2026-10-21 20:03:39 +00:00
parent 455baa6aa4
commit f138403918
10 changed files with 2838 additions and 3 deletions

View file

@ -3,7 +3,8 @@ import { LocalDatabase } from '../src/services/db';
import { InsightService } from '../src/services/insight';
import { ScraperService } from '../src/services/scraper';
import { SyllabusService } from '../src/services/syllabus';
import { Assignment, Lesson } from '../src/types';
import { ExamService } from '../src/services/exam';
import { Assignment, Lesson, ExamReportDetail } from '../src/types';
async function runAllTests() {
console.log('========================================================');
@ -430,6 +431,217 @@ async function runAllTests() {
assert.strictEqual(db.getStudentAdvisoryTeacher(testStudentId), 'SEVGİ BİKİL');
});
// 6. Exam Reports & Analytics Tests
await test('ExamService: categorizeExam correctly segregates TYT and AYT', () => {
assert.strictEqual(ExamService.categorizeExam('12 YKS-01_MF'), 'TYT');
assert.strictEqual(ExamService.categorizeExam('12 YKS-04 MF'), 'TYT');
assert.strictEqual(ExamService.categorizeExam('TYT Deneme Sınavı 3'), 'TYT');
assert.strictEqual(ExamService.categorizeExam('12 AYT-01 MF'), 'AYT');
assert.strictEqual(ExamService.categorizeExam('AYT Sayısal Deneme'), 'AYT');
assert.strictEqual(ExamService.categorizeExam('Bilinmeyen Sınav', 80), 'AYT');
assert.strictEqual(ExamService.categorizeExam('Bilinmeyen Sınav', 120), 'TYT');
});
await test('ExamService: computeDeltasAndRatings calculates Net deltas, Rank deltas, and difficulty-adjusted ratings', () => {
const mockExams: ExamReportDetail[] = [
{
summary: {
id: '3322',
name: '12 YKS-01_MF',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 78,
totalWrong: 22,
totalEmpty: 20,
totalNet: 72.50,
totalScore: 72.50,
generalRank: 16
},
subjects: [
{ subjectId: '1', subjectName: 'Türkçe', questionCount: 40, correctCount: 30, wrongCount: 6, emptyCount: 4, net: 28.5, score: 28.5, percentage: 71 }
],
hasAnswerKey: true
},
{
summary: {
id: '3326',
name: '12 YKS-02_MF',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 88,
totalWrong: 18,
totalEmpty: 14,
totalNet: 83.50,
totalScore: 83.50,
generalRank: 14
},
subjects: [
{ subjectId: '1', subjectName: 'Türkçe', questionCount: 40, correctCount: 35, wrongCount: 2, emptyCount: 3, net: 34.5, score: 34.5, percentage: 86 }
],
hasAnswerKey: true
},
{
summary: {
id: '3340',
name: '12 YKS-03 MF',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 92,
totalWrong: 16,
totalEmpty: 12,
totalNet: 88.00,
totalScore: 88.00,
generalRank: 8
},
subjects: [
{ subjectId: '1', subjectName: 'Türkçe', questionCount: 40, correctCount: 36, wrongCount: 2, emptyCount: 2, net: 35.5, score: 35.5, percentage: 89 }
],
hasAnswerKey: true
},
{
summary: {
id: '3366',
name: '12 YKS-04 MF',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 86,
totalWrong: 14,
totalEmpty: 20,
totalNet: 82.50, // Net dropped due to harder test
totalScore: 82.50,
generalRank: 9 // Held single-digit rank #9
},
subjects: [
{ subjectId: '1', subjectName: 'Türkçe', questionCount: 40, correctCount: 30, wrongCount: 7, emptyCount: 3, net: 28.25, score: 28.25, percentage: 75 }
],
hasAnswerKey: true
}
];
const processed = ExamService.computeDeltasAndRatings(mockExams);
assert.strictEqual(processed.length, 4);
// Map by ID for assertion
const yks1 = processed.find(p => p.summary.id === '3322')!;
const yks2 = processed.find(p => p.summary.id === '3326')!;
const yks3 = processed.find(p => p.summary.id === '3340')!;
const yks4 = processed.find(p => p.summary.id === '3366')!;
// Exam 1: Baseline
assert.strictEqual(yks1.summary.deltaNet, undefined);
assert.strictEqual(yks1.summary.deltaRank, undefined);
// Exam 2: Net +11.00, Rank improved from 16 to 14 (+2 places climbed) -> Breakthrough
assert.strictEqual(yks2.summary.deltaNet, 11.00);
assert.strictEqual(yks2.summary.deltaRank, 2);
assert.strictEqual(yks2.summary.rating?.label, 'Breakthrough');
assert.strictEqual(yks2.subjects[0].deltaNet, 6.00); // 34.5 - 28.5
// Exam 3: Net +4.50, Rank improved from 14 to 8 (+6 places climbed) -> Breakthrough
assert.strictEqual(yks3.summary.deltaNet, 4.50);
assert.strictEqual(yks3.summary.deltaRank, 6);
assert.strictEqual(yks3.summary.rating?.label, 'Breakthrough');
// Exam 4: Net -5.50 (harder exam), but rank held in top 10 (#9) -> Outperformed Curve!
assert.strictEqual(yks4.summary.deltaNet, -5.50);
assert.strictEqual(yks4.summary.deltaRank, -1);
assert.strictEqual(yks4.summary.rating?.label, 'Outperformed Curve');
});
await test('ExamService: calculateKPIs correctly computes aggregate metrics', () => {
const mockDetails: ExamReportDetail[] = [
{
summary: {
id: '1',
name: 'Exam 1',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 80,
totalWrong: 20,
totalEmpty: 20,
totalNet: 75.0,
totalScore: 75.0,
generalRank: 15
},
subjects: [],
hasAnswerKey: false
},
{
summary: {
id: '2',
name: 'Exam 2',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 90,
totalWrong: 15,
totalEmpty: 15,
totalNet: 85.0,
totalScore: 85.0,
generalRank: 5
},
subjects: [],
hasAnswerKey: false
}
];
const kpis = ExamService.calculateKPIs(mockDetails);
assert.strictEqual(kpis.latestNet, 75.0);
assert.strictEqual(kpis.bestNet, 85.0);
assert.strictEqual(kpis.averageNet, 80.0);
assert.strictEqual(kpis.bestRank, 5);
assert.strictEqual(kpis.averageRank, 10);
assert.strictEqual(kpis.totalExams, 2);
});
await test('LocalDatabase: saveExamReports and saveTopicWeaknesses persistence', () => {
const db = LocalDatabase.getInstance();
const testStudentId = `test_student_exam_${Date.now()}`;
const mockDetail: ExamReportDetail = {
summary: {
id: '9999',
name: 'Test Exam',
examType: 'TYT',
totalQuestions: 120,
totalCorrect: 80,
totalWrong: 20,
totalEmpty: 20,
totalNet: 75.0,
totalScore: 75.0,
generalRank: 10
},
subjects: [],
hasAnswerKey: false
};
db.saveExamReports(testStudentId, [mockDetail]);
const examStore = db.getExamReports(testStudentId);
assert(examStore !== null);
assert(examStore.reports['9999'] !== undefined);
assert.strictEqual(examStore.reports['9999'].summary.name, 'Test Exam');
// Topic weaknesses
const mockWeakness = [
{
examId: '9999',
examName: 'Test Exam',
subjectName: 'Türkçe',
topicName: 'Paragraf',
totalCount: 5,
correctCount: 2,
wrongCount: 3,
emptyCount: 0,
successRate: 40
}
];
db.saveTopicWeaknesses(testStudentId, '9999', mockWeakness);
const retrieved = db.getTopicWeaknesses(testStudentId, '9999');
assert(retrieved !== null);
assert.strictEqual(retrieved.length, 1);
assert.strictEqual(retrieved[0].topicName, 'Paragraf');
});
// 6. Optional Live Portal Test (via environment variables only)
const testStudentId = process.env.TEST_STUDENT_ID;
const testPassword = process.env.TEST_PASSWORD;