@@ -106,25 +106,35 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
106106
107107 const notTests = homeworks . filter ( h => ! h . tags ! . includes ( TestTag ) )
108108
109- const testGroups = Lodash ( homeworks . filter ( h => h . tags ! . includes ( TestTag ) ) )
109+ const testHomeworks = homeworks . filter ( h => h . tags ! . includes ( TestTag ) )
110+ const testGroups = Lodash ( testHomeworks )
110111 . groupBy ( ( h : HomeworkViewModel ) => {
111112 const key = h . tags ! . find ( t => ! DefaultTags . includes ( t ) )
112113 return key || h . id ! . toString ( ) ;
113114 } )
114115 . values ( )
115116 . value ( ) ;
116117
117- const testsMaxSum = testGroups
118- . map ( h => h [ 0 ] )
119- . flatMap ( homework => homework . tasks )
120- . reduce ( ( sum , task ) =>
121- sum + ( task ! . tags ! . includes ( BonusTag ) ? 0 : ( task ! . maxRating || 0 ) ) , 0 )
118+ const testsWithGroupsMaxSum = testHomeworks
119+ . filter ( h => h . groupId !== undefined )
120+ . flatMap ( h => h . tasks )
121+ . reduce ( ( sum , task ) => sum + ( task ! . maxRating || 0 ) , 0 )
122+
123+ const testsWithoutGroupsMaxSum = testHomeworks . filter ( h => h . groupId === undefined )
124+ . flatMap ( h => h . tasks )
125+ . reduce ( ( sum , task ) => sum + ( task ! . maxRating || 0 ) , 0 )
122126
123- const hasHomeworks = ! ! notTests
127+ const homeworksWithGroups = notTests . filter ( h => h . groupId )
128+ const homeworksWithoutGroupMaxSum = notTests . filter ( h => ! h . groupId )
124129 . filter ( h => ! h . tags ! . includes ( BonusTag ) )
125130 . flatMap ( homework => homework . tasks )
126- . filter ( task => ! task ! . tags ! . includes ( BonusTag ) )
127- const hasTests = testsMaxSum > 0
131+ . reduce ( ( sum , task ) => {
132+ return sum + ( task ! . tags ! . includes ( BonusTag ) ? 0 : ( task ! . maxRating || 0 ) ) ;
133+ } , 0 )
134+ console . log ( homeworksWithoutGroupMaxSum )
135+
136+ const hasHomeworks = homeworksWithoutGroupMaxSum > 0 || homeworksWithGroups . length > 0
137+ const hasTests = testsWithGroupsMaxSum + testsWithoutGroupsMaxSum > 0
128138 const showBestSolutions = isMentor && ( hasHomeworks || hasTests )
129139
130140 const bestTaskSolutions = new Map < number , string > ( )
@@ -215,7 +225,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
215225 paddingRight : 5 ,
216226 borderLeft : borderStyle ,
217227 } } >
218- ДЗ
228+ ДЗ { homeworksWithoutGroupMaxSum > 0 && `( ${ homeworksWithoutGroupMaxSum } )` }
219229 </ TableCell > }
220230 { hasTests && < TableCell padding = "checkbox" component = "td" align = "center"
221231 style = { {
@@ -224,7 +234,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
224234 paddingRight : 5 ,
225235 borderLeft : borderStyle ,
226236 } } >
227- КР ( { testsMaxSum } )
237+ КР { testsWithoutGroupsMaxSum > 0 && `( ${ testsWithoutGroupsMaxSum } )` }
228238 </ TableCell > }
229239 { showBestSolutions && < TableCell padding = "checkbox" component = "td" align = "center"
230240 style = { { borderLeft : borderStyle } } >
@@ -257,13 +267,13 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
257267 . flatMap ( t => StudentStatsUtils . calculateLastRatedSolution ( t . solutions || [ ] ) ?. rating || 0 ) || 0
258268 )
259269 . reduce ( ( sum , rating ) => sum + rating , 0 )
260- const homeworksMaxSum = notTests
270+ const userHomeworksMaxSum = notTests
261271 . filter ( h => ! h . tags ! . includes ( BonusTag ) &&
262- ( props . groups . find ( g => g . id === h . groupId ) ?. studentsIds ?. includes ( cm . id ! ) || ! h . groupId ) )
272+ ( props . groups . find ( g => g . id === h . groupId ) ?. studentsIds ?. includes ( cm . id ! ) ) )
263273 . flatMap ( homework => homework . tasks )
264274 . reduce ( ( sum , task ) => {
265275 return sum + ( task ! . tags ! . includes ( BonusTag ) ? 0 : ( task ! . maxRating || 0 ) ) ;
266- } , 0 )
276+ } , 0 ) + homeworksWithoutGroupMaxSum
267277
268278 const testsSum = testGroups
269279 . map ( group => {
@@ -282,6 +292,12 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
282292 . flat ( )
283293 . reduce ( ( sum , rating ) => sum + rating , 0 )
284294
295+ const userTestsMaxSum = testHomeworks
296+ . filter ( h => h . groupId !== undefined &&
297+ ( props . groups . find ( g => g . id === h . groupId ) ?. studentsIds ?. includes ( cm . id ! ) ) )
298+ . flatMap ( homework => homework . tasks )
299+ . reduce ( ( sum , task ) => sum + ( task ! . maxRating || 0 ) , 0 ) + testsWithoutGroupsMaxSum
300+
285301 const bestSolutionsCount = bestTaskSolutions . values ( )
286302 . filter ( x => x === cm . id )
287303 . toArray ( ) . length
@@ -338,12 +354,12 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
338354 scope = "row"
339355 variant = { "body" }
340356 >
341- < Chip size = { "small" }
357+ { userHomeworksMaxSum > 0 && < Chip size = { "small" }
342358 style = { {
343- backgroundColor : StudentStatsUtils . getRatingColor ( homeworksSum , homeworksMaxSum ) ,
359+ backgroundColor : StudentStatsUtils . getRatingColor ( homeworksSum , userHomeworksMaxSum ) ,
344360 fontSize : 16
345361 } }
346- label = { `${ homeworksSum } / ${ homeworksMaxSum } ` } />
362+ label = { `${ homeworksSum } ${ homeworksWithGroups . length > 0 ? ` / ${ userHomeworksMaxSum } ` : "" } ` } /> }
347363 </ TableCell > }
348364 { hasTests && < TableCell
349365 align = "center"
@@ -356,12 +372,12 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
356372 scope = "row"
357373 variant = { "body" }
358374 >
359- < Chip size = { "small" }
375+ { userTestsMaxSum > 0 && < Chip size = { "small" }
360376 style = { {
361- backgroundColor : StudentStatsUtils . getRatingColor ( testsSum , testsMaxSum ) ,
377+ backgroundColor : StudentStatsUtils . getRatingColor ( testsSum , userTestsMaxSum ) ,
362378 fontSize : 16
363379 } }
364- label = { testsSum } />
380+ label = { ` ${ testsSum } ${ testHomeworks . some ( h => h . groupId !== undefined ) ? `/ ${ userTestsMaxSum } ` : "" } ` } /> }
365381 </ TableCell > }
366382 { showBestSolutions && < TableCell
367383 align = "center"
0 commit comments