-
Notifications
You must be signed in to change notification settings - Fork 6
/
subject.ts
114 lines (102 loc) · 2.64 KB
/
subject.ts
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
import {
Constant,
SubjectNameConstant
} from 'Constant';
/**
* Subject Class
*/
export class Subject {
name: string;
code: number;
totalAppeared: number = 0;
totalPassed: number = 0;
private totalMarks: number = 0;
r0to32: number = 0;
r33to44: number = 0;
r45to59: number = 0;
r60to74: number = 0;
r75to89: number = 0;
r90to100: number = 0;
gradeObj: any = {};
/**
* Pushes the subject to the collection
* @param code Code is the primary key for the subject
*/
constructor(code: number) {
this.code = code;
this.name = ( < any > SubjectNameConstant)[code];
}
/**
* Returns the subject code
*/
getCode() {
return this.code;
}
/**
* Adds total appeared
*/
incrementTotalAppeared() {
++this.totalAppeared;
}
/**
* Increments total passed
*/
incrementTotalPassed(grade: string) {
if (!grade.match(/E|F/)) {
++this.totalPassed;
}
}
/**
* Increments the count of a particular grade for a subject
* @param grade Grade string
*/
incrementGradeCount(grade: string) {
if (this.gradeObj[grade]) {
++this.gradeObj[grade];
} else {
this.gradeObj[grade] = 1;
}
}
/**
* Sets the marks into proper range
*/
incrementMarkRange(marks: number) {
this.totalMarks += marks;
if (marks > 89) {
++this.r90to100;
} else if (marks > 74) {
++this.r75to89;
} else if (marks > 59) {
++this.r60to74;
} else if (marks > 44) {
++this.r45to59;
} else if (marks > 32) {
++this.r33to44;
} else {
++this.r0to32;
}
}
getPassPercentage() {
return parseFloat(((this.totalPassed / this.totalAppeared) * 100).toFixed(2)) || 0;
}
getGradeCount(grade: string) {
return this.gradeObj[grade] || 0;
}
getNxW() {
return this.getGradeCount('A1') * 8 + this.getGradeCount('A2') * 7 +
this.getGradeCount('B1') * 6 + this.getGradeCount('B2') * 5 +
this.getGradeCount('C1') * 4 + this.getGradeCount('C2') * 3 +
this.getGradeCount('D1') * 2 + this.getGradeCount('D2') * 1 +
this.getGradeCount('E') * 0;
}
getPI() {
return parseFloat(((this.getNxW() * 100) / (this.totalAppeared * Constant.maxPoint))
.toFixed(2));
}
getTotalMarks() {
return this.totalMarks;
}
getMean() {
return parseFloat((this.totalMarks / this.totalAppeared).toFixed(2));
}
}