Skip to content

Commit 0479395

Browse files
committed
Use last rated solution info for stats
1 parent 914b9f2 commit 0479395

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

hwproj.front/src/components/Courses/Course.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {RouteComponentProps} from 'react-router';
44
import {AccountDataDto, CourseViewModel, HomeworkViewModel, StatisticsCourseMatesModel} from "../../api";
55
import CourseHomework from "../Homeworks/CourseHomework";
66
import AddHomework from "../Homeworks/AddHomework";
7-
import CourseStudents from "./CourseStudents";
7+
import StudentStats from "./StudentStats";
88
import NewCourseStudents from "./NewCourseStudents";
99
import ApiSingleton from "../../api/ApiSingleton";
1010
import {Button, Grid, Tab, Tabs, Typography, IconButton, Switch} from "@material-ui/core";
@@ -294,7 +294,7 @@ const Course: React.FC<RouteComponentProps<ICourseProps>> = (props) => {
294294
{tabValue === 1 &&
295295
<Grid container style={{marginBottom: "15px"}}>
296296
<Grid item xs={11}>
297-
<CourseStudents
297+
<StudentStats
298298
homeworks={courseState.courseHomework}
299299
userId={userId as string}
300300
isMentor={isMentor}

hwproj.front/src/components/Courses/CourseStudents.tsx renamed to hwproj.front/src/components/Courses/StudentStats.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import React from "react";
22
import {CourseViewModel, HomeworkViewModel, StatisticsCourseMatesModel} from "../../api/";
33
import {Table, TableBody, TableCell, TableContainer, TableHead, TableRow} from "@material-ui/core";
4-
import TaskStudentCell from "../Tasks/TaskStudentCell";
4+
import StudentStatsCell from "../Tasks/StudentStatsCell";
55
import {Alert} from "@mui/material";
66

7-
interface ICourseStudentsProps {
7+
interface IStudentStatsProps {
88
course: CourseViewModel;
99
homeworks: HomeworkViewModel[];
1010
isMentor: boolean;
1111
userId: string;
1212
solutions: StatisticsCourseMatesModel[];
1313
}
1414

15-
interface ICourseStudentsState {
15+
interface IStudentStatsState {
1616
searched: string
1717
}
1818

19-
class CourseStudents extends React.Component<ICourseStudentsProps, ICourseStudentsState> {
20-
constructor(props: ICourseStudentsProps) {
19+
class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsState> {
20+
constructor(props: IStudentStatsProps) {
2121
super(props);
2222
this.state = {
2323
searched: ""
@@ -93,7 +93,7 @@ class CourseStudents extends React.Component<ICourseStudentsProps, ICourseStuden
9393
</TableCell>
9494
{homeworks.map((homework) =>
9595
homework.tasks!.map((task) => (
96-
<TaskStudentCell
96+
<StudentStatsCell
9797
solutions={solutions
9898
.find(s => s.id == cm.id)!.homeworks!
9999
.find(h => h.id == homework.id)!.tasks!
@@ -115,4 +115,4 @@ class CourseStudents extends React.Component<ICourseStudentsProps, ICourseStuden
115115
}
116116
}
117117

118-
export default CourseStudents;
118+
export default StudentStats;

hwproj.front/src/components/Tasks/TaskStudentCell.tsx renamed to hwproj.front/src/components/Tasks/StudentStatsCell.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ interface ITaskStudentCellProps {
1414

1515
interface ITaskStudentCellState {
1616
isLoaded: boolean;
17-
solution?: StatisticsCourseSolutionsModel;
17+
lastRatedSolution?: StatisticsCourseSolutionsModel;
1818
redirectForMentor: boolean;
1919
redirectForStudent: boolean;
2020
color: string;
2121
ratedSolutionsCount: number;
2222
}
2323

24-
export default class TaskStudentCell extends React.Component<ITaskStudentCellProps,
25-
ITaskStudentCellState> {
24+
export default class StudentStatsCell extends React.Component<ITaskStudentCellProps, ITaskStudentCellState> {
2625
constructor(props: ITaskStudentCellProps) {
2726
super(props);
2827
this.state = {
2928
isLoaded: false,
30-
solution: {},
29+
lastRatedSolution: {},
3130
redirectForMentor: false,
3231
redirectForStudent: false,
3332
color: "",
@@ -59,10 +58,10 @@ export default class TaskStudentCell extends React.Component<ITaskStudentCellPro
5958
: this.props.userId === this.props.studentId
6059
? () => this.onStudentCellClick()
6160
: () => 0;
62-
const result = this.state.solution === undefined || this.state.solution.state! === Solution.StateEnum.NUMBER_0
61+
const result = this.state.lastRatedSolution === undefined
6362
? ""
6463
: <Stack direction="row" spacing={0.3} justifyContent={"center"} alignItems={"center"}>
65-
<div>{this.state.solution.rating!}</div>
64+
<div>{this.state.lastRatedSolution.rating!}</div>
6665
<Chip color={"default"} size={"small"} label={this.state.ratedSolutionsCount}/>
6766
</Stack>
6867
return (
@@ -102,22 +101,25 @@ export default class TaskStudentCell extends React.Component<ITaskStudentCellPro
102101

103102
async componentDidMount() {
104103
const solutions = this.props.solutions
105-
const ratedSolutionsCount = solutions!.filter(x => x.state != Solution.StateEnum.NUMBER_0).length
104+
const ratedSolutions = solutions!.filter(x => x.state != Solution.StateEnum.NUMBER_0)
105+
const ratedSolutionsCount = ratedSolutions.length
106106
const isFirstUnratedTry = ratedSolutionsCount === 0
107107
const lastSolution = solutions!.slice(-1)[0]
108+
const lastRatedSolution = ratedSolutions.slice(-1)[0]
109+
108110
if (lastSolution === undefined) {
109111
this.setState({
110112
color: "",
111113
isLoaded: true,
112-
solution: undefined
114+
lastRatedSolution: undefined
113115
})
114116
return
115117
}
116118
this.setState({
117119
color: this.getCellBackgroundColor(lastSolution.state, isFirstUnratedTry),
118120
isLoaded: true,
119-
solution: lastSolution,
120-
ratedSolutionsCount: ratedSolutionsCount
121+
lastRatedSolution: lastRatedSolution,
122+
ratedSolutionsCount: ratedSolutions.length
121123
})
122124
}
123125
}

0 commit comments

Comments
 (0)