diff --git a/client/src/components/LiveResults/LiveResults.tsx b/client/src/components/LiveResults/LiveResults.tsx index a19518d..0ee2019 100644 --- a/client/src/components/LiveResults/LiveResults.tsx +++ b/client/src/components/LiveResults/LiveResults.tsx @@ -69,27 +69,6 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti return classTotal / students.length; }, [students]); - - const getCorrectAnswersPerQuestion = (index: number): number => { - return ( - (students.filter((student) => - student.answers.some( - (answer) => - parseInt(answer.idQuestion.toString()) === index + 1 && answer.isCorrect - ) - ).length / students.length) * 100 - ); - }; - - 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) { @@ -114,15 +93,38 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti return correctAnswers; }; - const totalParticipation: number = useMemo(() => { + const totalCorrectAnswers: number = useMemo(() => { let classTotal = 0; students.forEach((student) => { - classTotal += getTotalAnswers(student); + classTotal += getTotalCorrectAnswers(student); }); - return (classTotal / (students.length * maxQuestions)) * 100; + return classTotal; }, [students]); + + const getCorrectAnswersPerQuestion = (index: number): number => { + return ( + (students.filter((student) => + student.answers.some( + (answer) => + parseInt(answer.idQuestion.toString()) === index + 1 && answer.isCorrect + ) + ).length / students.length) * 100 + ); + }; + + const getTotalCorrectAnswersPerQuestion = (index: number): number => { + let total = 0; + students.filter((student)=>{ + student.answers.forEach( (ans) =>{ + if(parseInt(ans.idQuestion.toString()) === index + 1 && ans.isCorrect){ + total++; + } + }) + }) + return (total); + }; const getTotalAnswers = (student: StudentType): number => { if (student.answers.length === 0) { @@ -143,6 +145,16 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti return answers; }; + const totalParticipation: number = useMemo(() => { + let classTotal = 0; + + students.forEach((student) => { + classTotal += getTotalAnswers(student); + }); + + return (classTotal / (students.length * maxQuestions)) * 100; + }, [students]); + const getParticipationPerQuestion = (index: number): number => { return ( (students.filter((student) => @@ -321,6 +333,41 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti {students.length > 0 ? `${classAverage.toFixed()} %` : '-'} + + +
% participation
+
+ {Array.from({ length: maxQuestions }, (_, index) => ( + + {students.length > 0 + ? `${getParticipationPerQuestion(index).toFixed()} %` + : '-'} + + ))} + + {students.length > 0 ? `${totalParticipation.toFixed()} %` : '-'} + +
Bonnes réponses
@@ -356,41 +403,6 @@ const LiveResults: React.FC = ({ questions, showSelectedQuesti {students.length > 0 ? `${totalCorrectAnswers.toFixed()}` : '-'}
- - -
% réussite
-
- {Array.from({ length: maxQuestions }, (_, index) => ( - - {students.length > 0 - ? `${getParticipationPerQuestion(index).toFixed()} %` - : '-'} - - ))} - - {students.length > 0 ? `${totalParticipation.toFixed()} %` : '-'} - -