diff --git a/client/src/components/LiveResults/LiveResults.tsx b/client/src/components/LiveResults/LiveResults.tsx index d1e560a..1a88a9e 100644 --- a/client/src/components/LiveResults/LiveResults.tsx +++ b/client/src/components/LiveResults/LiveResults.tsx @@ -81,6 +81,39 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti ); }; + const totalCorrectAnswers: number = useMemo(() => { + let classTotal = 0; + + students.forEach((student) => { + classTotal += getTotalCorrectAnswers(student); + }); + + return classTotal; + }, [students]); + + const getTotalCorrectAnswers = (student: StudentType): number => { + if (student.answers.length === 0) { + return 0; + } + + const uniqueQuestions = new Set(); + let correctAnswers = 0; + + for (const answer of student.answers) { + const { idQuestion, isCorrect } = answer; + + if (!uniqueQuestions.has(idQuestion)) { + uniqueQuestions.add(idQuestion); + + if (isCorrect) { + correctAnswers++; + } + } + } + + return correctAnswers; + }; + return (
@@ -249,6 +282,41 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti {students.length > 0 ? `${classAverage.toFixed()} %` : '-'} + + +
Bonnes réponses
+
+ {Array.from({ length: maxQuestions }, (_, index) => ( + + {students.length > 0 + ? `${getTotalCorrectAnswersPerQuestion(index).toFixed()}` + : '-'} + + ))} + + {students.length > 0 ? `${totalCorrectAnswers.toFixed()}` : '-'} + +