@@ -9,6 +9,7 @@ import StudentStatsUtils from "../../services/StudentStatsUtils";
99import ShowChartIcon from "@mui/icons-material/ShowChart" ;
1010import { BonusTag , DefaultTags , TestTag } from "../Common/HomeworkTags" ;
1111import Lodash from "lodash"
12+ import ApiSingleton from "@/api/ApiSingleton" ;
1213
1314interface IStudentStatsProps {
1415 course : CourseViewModel ;
@@ -35,6 +36,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
3536 }
3637
3738 const { searched} = state
39+ const isMentor = ApiSingleton . authService . isMentor ( )
3840
3941 useEffect ( ( ) => {
4042 const keyDownHandler = ( event : KeyboardEvent ) => {
@@ -98,6 +100,25 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
98100 const hasHomeworks = homeworksMaxSum > 0
99101 const hasTests = testsMaxSum > 0
100102
103+ const bestTaskSolutions = new Map < number , string > ( )
104+ if ( solutions ) {
105+ Lodash ( homeworks )
106+ . flatMap ( h => h . tasks ! )
107+ . map ( t => solutions
108+ . map ( s => s . homeworks !
109+ . flatMap ( h1 => h1 . tasks ! )
110+ . find ( t1 => t1 . id === t . id ) ?. solution || [ ] )
111+ . map ( s => StudentStatsUtils . calculateLastRatedSolution ( s ) )
112+ . filter ( x => x != undefined && x . rating ! > 0 ) )
113+ . filter ( x => x . length > 0 )
114+ . map ( x => Lodash ( x ) . orderBy ( [
115+ ( x ) => x . rating ,
116+ ( x ) => new Date ( x . publicationDate ! ) . getTime ( )
117+ ] , [ "desc" , "asc" ] ) . value ( ) [ 0 ]
118+ )
119+ . forEach ( x => bestTaskSolutions . set ( x . taskId ! , x . studentId ! ) )
120+ }
121+
101122 return (
102123 < div >
103124 { props . solutions === undefined && < LinearProgress /> }
@@ -291,6 +312,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
291312 studentId = { String ( cm . id ) }
292313 taskId = { task . id ! }
293314 taskMaxRating = { task . maxRating ! }
315+ isBestSolution = { isMentor && bestTaskSolutions . get ( task . id ! ) === cm . id }
294316 { ...additionalStyles } /> ;
295317 } )
296318 ) }
0 commit comments