From 101605ad882d3944046471a3b931e797a430c2e5 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sat, 24 Aug 2024 11:06:44 +0100 Subject: [PATCH] Updated Master Statistical with user grade count --- src/dashboards/MasterStatistical.tsx | 49 +++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/dashboards/MasterStatistical.tsx b/src/dashboards/MasterStatistical.tsx index 71537fb4..3a4a2e57 100644 --- a/src/dashboards/MasterStatistical.tsx +++ b/src/dashboards/MasterStatistical.tsx @@ -199,6 +199,28 @@ const MasterStatistical = (props: Props) => { }); const areAllSelected = selectedCorporates.length === corporates.length; + + const getStudentsConsolidateScore = () => { + if (tableResults.length === 0) { + return { highest: null, lowest: null }; + } + + // Find the student with the highest and lowest score + return tableResults.reduce( + (acc, curr) => { + if (curr.correct > acc.highest.correct) { + acc.highest = curr; + } + if (curr.correct < acc.lowest.correct) { + acc.lowest = curr; + } + return acc; + }, + { highest: tableResults[0], lowest: tableResults[0] } + ); + }; + + const consolidateResults = getStudentsConsolidateScore(); return ( <>
@@ -239,7 +261,8 @@ const MasterStatistical = (props: Props) => { ); })}
-
+
+ {
-
- console.log("clicked")} - Icon={BsPersonFill} - label="Consolidate Highest Student" - color="purple" - /> +
+ {consolidateResults.highest && ( + {}} + Icon={BsPersonFill} + label={`Highest result: ${consolidateResults.highest.user}`} + color="purple" + /> + )} + {consolidateResults.lowest && ( + {}} + Icon={BsPersonFill} + label={`Lowest result: ${consolidateResults.lowest.user}`} + color="purple" + /> + )}
);