-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGradings.ts
More file actions
118 lines (100 loc) · 3.07 KB
/
Gradings.ts
File metadata and controls
118 lines (100 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { IExercise, IHasExercises } from './HasExercises';
export enum SheetState {
PASSED = 'Bestanden',
NOT_PASSED = 'Nicht bestanden',
NO_STATE = 'Nicht bewertet',
}
export interface GradingResponseData {
studentId: string;
gradingData: IGrading | undefined;
}
export interface IExerciseGrading {
points: number;
comment?: string;
additionalPoints?: number;
subExercisePoints?: [string, number][];
}
export interface IGrading {
id: string;
exerciseGradings: [string, IExerciseGrading][];
belongsToTeam: boolean;
points: number;
comment?: string;
additionalPoints?: number;
sheetState?: SheetState;
}
export interface IExerciseGradingDTO {
comment?: string;
additionalPoints?: number;
points?: number;
subExercisePoints?: [string, number][];
}
export interface IGradingDTO {
exerciseGradings: [string, IExerciseGradingDTO][];
createNewGrading: boolean;
sheetId?: string;
examId?: string;
shortTestId?: string;
comment?: string;
additionalPoints?: number;
sheetState?: SheetState;
}
export interface IPresentationPointsDTO {
sheetId: string;
points: number;
}
export interface IExercisePointsInfo {
must: number;
bonus: number;
}
export class ExercisePointsInfo implements IExercisePointsInfo {
readonly must: number;
readonly bonus: number;
get total(): number {
return this.must + this.bonus;
}
constructor({ must, bonus }: Partial<IExercisePointsInfo>) {
this.must = must ?? 0;
this.bonus = bonus ?? 0;
}
}
export function convertExercisePointInfoToString(exPointInfo: IExercisePointsInfo): string {
if (exPointInfo.must > 0 && exPointInfo.bonus > 0) {
return `${exPointInfo.must} + ${exPointInfo.bonus} Bonus`;
} else if (exPointInfo.bonus === 0) {
return `${exPointInfo.must}`;
} else {
return `${exPointInfo.bonus} Bonus`;
}
}
export function getPointsOfExercise(exercise: IExercise): ExercisePointsInfo {
const points: IExercisePointsInfo = { must: 0, bonus: 0 };
if (exercise.subexercises.length === 0) {
if (exercise.bonus) {
return new ExercisePointsInfo({
must: 0,
bonus: exercise.maxPoints,
});
} else {
return new ExercisePointsInfo({ must: exercise.maxPoints });
}
}
const info: IExercisePointsInfo = exercise.subexercises.reduce((pts, subEx) => {
if (subEx.bonus) {
return { ...pts, bonus: pts.bonus + subEx.maxPoints };
} else {
return { ...pts, must: pts.must + subEx.maxPoints };
}
}, points);
return new ExercisePointsInfo(info);
}
export function getPointsOfAllExercises({ exercises }: IHasExercises): ExercisePointsInfo {
const info: IExercisePointsInfo = exercises.reduce(
(pts, ex) => {
const { must, bonus } = getPointsOfExercise(ex);
return { must: pts.must + must, bonus: pts.bonus + bonus };
},
{ must: 0, bonus: 0 }
);
return new ExercisePointsInfo(info);
}