Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/quizzes/quizzes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,32 @@ export class QuizzesService {
const lowestScore = scores.length > 0 ? Math.min(...scores) : 0;

const passScore = 5.0; // Điểm đạt
const passRate = scores.length > 0
? (scores.filter((score) => score >= passScore).length / scores.length) * 100

// Tạo map để lưu điểm của mỗi học sinh (dựa trên bestAttempts)
const studentScores = new Map<string, number>();
bestAttempts.forEach((attempt) => {
if (attempt.studentId && attempt.submittedAt !== null && attempt.score !== null) {
const score = Number(attempt.score);
// Chỉ lưu điểm cao nhất nếu học sinh có nhiều attempt
const currentScore = studentScores.get(attempt.studentId);
if (currentScore === undefined || score > currentScore) {
studentScores.set(attempt.studentId, score);
}
}
});

// Tính passrate dựa trên tổng số học sinh enrolled
// Học sinh chưa submit hoặc không có attempt được tính là không đạt
let passedStudents = 0;
enrolledStudentIds.forEach((studentId) => {
const score = studentScores.get(studentId);
if (score !== undefined && score >= passScore) {
passedStudents++;
}
});

const passRate = totalStudents > 0
? (passedStudents / totalStudents) * 100
: 0;

// Tính thời gian trung bình làm bài (phút)
Expand Down
Loading