This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrating.html
234 lines (192 loc) · 6.74 KB
/
rating.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
---
---
<!DOCTYPE html>
<html lang="en">
<head>
{% include head.html %}
</head>
<body>
{% include nav.html %}
<div class="container">
<div style="height:25vh"></div>
<div class="center">
<h1>Student rating</value>
</h1>
<p>This pages shows an objective representation of your marks</p>
</div>
<br>
<div id="rating_data" style="max-width:800px;margin:auto;">
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</div>
{% include foot.html %}
<!-- Auth redirect handler -->
<script src="/assets/js/cookies.js"></script>
<script src="/assets/js/api.js"></script>
<script src="/assets/js/navbar.js"></script>
<script>
if (!cookieExists("auth_token_2")) {
console.log("Redirecting to login page");
document.location = "/login";
}
</script>
<!-- ChartJS -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
<!-- Analyze marking data -->
<script src="/assets/js/marks.js"></script>
<script>
// Mapping of all course prefixes to a title
// This data is manually scraped from the HB Beal course calendar
course_pref_mapping = {
"NA": "FNMI",
"NB": "FNMI",
"ND": "FNMI",
"ND": "FNMI",
"LN": "FNMI",
"AT": "The Arts",
"AD": "The Arts",
"AM": "The Arts",
"AV": "The Arts",
"AW": "The Arts",
"BA": "Business",
"IC": "Computer Science",
"BD": "Business",
"BT": "Business",
"BB": "Business",
"BM": "Business",
"ID": "Interdisciplinary",
"BO": "Business",
"CI": "World Studies",
"CG": "World Studies",
"CH": "History",
"CL": "Law",
"EN": "English",
"OL": "English",
"EM": "Media",
"EP": "English",
"EW": "English",
"ET": "English",
"ES": "English",
"EL": "English",
"GL": "Learning",
"GL": "Learning",
"MA": "Math",
"SN": "Science",
"HI": "Life Management",
"GW": "Life Management",
"GP": "Leadership",
"PP": "Health",
"PA": "Health",
"PL": "Health",
"PS": "Health",
"MF": "Math",
"MP": "Math",
"ME": "Math",
"MB": "Math",
"MC": "Math",
"MH": "Math",
"MD": "Math",
"FS": "French",
"LW": "Spanish",
"SV": "Science",
"SB": "Science",
"SC": "Science",
"SP": "Science",
"SN": "Science",
"HP": "Family",
"HL": "Family",
"HI": "Family",
"HH": "Family",
"HF": "Food",
"HN": "Fashion",
"HR": "Religion",
"HS": "Social Studies",
"HZ": "Philosophy",
"TD": "Sewing",
"TG": "Comm. Tech",
"TE": "Computer Engineering",
"TC": "Construction",
"TD": "Construction",
"TW": "Construction",
"TM": "Manufacturing",
"TX": "Aesthetics",
"TT": "Transportation",
}
// Get marks data
getMarks((data) => {
// Build a list of "my courses"
var my_courses = {};
// Iterate through every course
Object.keys(data.marks).reverse().forEach((year) => {
data.marks[year].forEach((course) => {
// Determine the course type
var course_type = course_pref_mapping[course.course.substr(0, 2)];
// Skip undefined courses
if (course_type == undefined) {
console.log(course.course + " is not a supported course");
return;
}
// If needed, create a new course entry
if (!(course_type in my_courses)) {
my_courses[course_type] = {
"accumulator": 0,
"entries": 0
}
}
// Add the course mark
my_courses[course_type].accumulator += course.mark;
my_courses[course_type].entries += 1;
})
})
// Create some chartJS data
var data = {
labels: [],
datasets: [{
data: [],
label: "Your Marks",
backgroundColor: "rgba(255, 99, 132, 0.2)",
borderColor: "rgb(255, 99, 132)",
pointBackgroundColor: "rgb(255, 99, 132)",
}]
}
// Convert courses list to averages
Object.keys(my_courses).forEach((key) => {
// Get data
var accumulator = my_courses[key].accumulator;
var entries = my_courses[key].entries;
// Average, and fill in to chartJS data
data.labels.push(key);
data.datasets[0].data.push(Math.round(accumulator / entries));
})
// Fill in a new canvas
document.getElementById("rating_data").innerHTML = "";
// Get average of all marks
var avg = 0;
data.datasets[0].data.forEach((x) => {
avg += x;
})
avg /= data.datasets[0].data.length;
avg = Math.round(avg);
document.getElementById("rating_data").innerHTML += '<div class="progress"><div class="progress-bar bg-info" role="progressbar" style="width: ' + avg + '%" aria-valuenow="' + avg + '" aria-valuemin="0" aria-valuemax="100">Progress</div></div><br>';
// Create a balance chart
document.getElementById("rating_data").innerHTML += "<canvas id='balance_ctx'></canvas>";
var course_balance = new Chart(document.getElementById("balance_ctx").getContext("2d"), {
type: "radar",
data: data,
options: {
scale: {
ticks: {
suggestedMin: 25,
suggestedMax: 100
}
}
}
})
})
</script>
</body>
</html>