-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
201 lines (163 loc) · 8.98 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Alex Javadi">
<meta name="description" content="This is a BTEC IT Grade Calculator (To see what grade you may get at the end)">
<meta name="keywords" content="BTEC, IT, Grade, Calculator, Alex Javadi">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<!-- short Icon -->
<link rel="icon" href="assets/favicon.ico" type="image/x-icon">
<title>BTEC IT Grade Calculator</title>
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">BTEC IT Grade Calculator</h1>
<p class="text-center">This is a BTEC IT Grade Calculator (To see what grade you may get at the end)</p>
<div class="col-md-12 d-none" id="div_selGrades">
<select class="form-control" id="selGrades" multiple></select>
</div>
</div>
<div class="d-flex justify-content-end mt-2 d-none" id="div_btnCreate">
<button class="btn btn-success" id="btnCreate">Generate grades</button>
</div>
<div class="col-md-12 mt-3 d-none" id="div_result"></div>
</div>
</div>
<center>
<footer class="mt-5">
<p>© 2024 - <a href="https://aljm.org" rel="noopener" target="_blank">Alex Javadi</a></p>
</footer>
</center>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <!-- SweetAlert2 -->
<script>
let configs = {
units: 0,
glh: {},
total: 0,
};
$(document).ready(() => {
Swal.fire({
title: "Select your Study Year",
html: "<p>Which year are you studying?</p><strong>Year 1</strong>: Foundation Year (510 GLH)<br> <strong>Year 2</strong>: Extended Diploma (1080 GLH)",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#005A70",
cancelButtonColor: "#005A70",
confirmButtonText: "Year 1 (Foundation)",
cancelButtonText: "Year 2 (Extended)",
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
customClass: {
confirmButton: 'shadow-sm',
cancelButton: 'shadow-sm'
}
}).then((result) => {
$.getJSON(`assets/grades-${result.isConfirmed ? "foundation" : "extended"}.json`, (grades) => {
configs.grades = grades;
})
$.getJSON(`assets/ucas-calculator-${result.isConfirmed ? "foundation" : "extended"}.json`, (ucas_calc) => {
configs.ucas_calculator = ucas_calc;
})
})
$.getJSON("assets/units.json", (data) => {
$.each(data, (key, value) => {
$("#selGrades").append(`<option value="${btoa(value.Unit_Title + "|" + value.GLH + "|" + value.Unit_Number + "|" + (value.Is_External ? "TRUE" : "FALSE"))}">Unit ${value.Unit_Number} - ${value.Unit_Title} (${value.Is_External == true ? "Exam" : "Assignment"})</option>`);
});
$("#div_selGrades").removeClass("d-none");
$("#selGrades").select2({
placeholder: "Click to select the units you have done...",
allowClear: true,
closeOnSelect: false
});
}).fail(() => {
alert("Failed to load the data. Please try again later.")
});
})
$("#selGrades").on("change", () => {
if ($("#selGrades").val().length > 0) {
$("#div_btnCreate").removeClass("d-none").addClass("d-flex");
}
else {
$("#div_btnCreate").removeClass("d-flex").addClass("d-none");
}
})
$("#btnCreate").on("click", (e) => {
e.preventDefault();
$("#div_selGrades,#div_btnCreate").addClass("d-none");
if (configs.externals == undefined) {
$.getJSON("assets/externals.json", (ext) => {
configs.glh.external = ext;
})
$.getJSON("assets/internals.json", (int) => {
configs.glh.internal = int;
})
}
configs.units = $("#selGrades").val().length;
const internal_select = `<select class="form-control" id="INTERNAL_SELECT_ID"><option value="-1" selected disabled>Select the internal grade...</option><option value="U">Failed</option><option value="P">Pass</option><option value="M">Merit</option><option value="D">Distinction</option></select>`
const external_select = `<select class="form-control" id="EXTERNAL_SELECT_ID"><option value="-1" selected disabled>Select the external grade...</option><option value="U">Failed</option><option value="NP">Near Pass</option><option value="P">Pass</option><option value="M">Merit</option><option value="D">Distinction</option></select>`
$.each($("#selGrades").val(), (key, value) => {
let base64 = atob(value).split("|");
if (base64[3] == "TRUE") {
$("#div_result").append(`<div class="col-md-12 mt-2"><h5>UNIT ${base64[2]} - ${base64[0]}: </h5> ${external_select.replace("EXTERNAL_SELECT_ID", `${base64[2]}_${base64[3]}_${base64[1]}`)}</div><hr>`);
}
else {
$("#div_result").append(`<div class="col-md-12 mt-2"><h5>UNIT ${base64[2]} - ${base64[0]}: </h5> ${internal_select.replace("INTERNAL_SELECT_ID", `${base64[2]}_${base64[3]}_${base64[1]}`)}</div><hr>`);
}
});
$("#div_result").removeClass("d-none").append(`<div id="config_buttons" class="d-flex justify-content-end"><button class="btn btn-primary" onclick="calculate()">Calculate</button></div>`);
});
const calculate = () => {
if (configs.total > 0) {
configs.total = 0;
}
// check if all the grades are selected
let allGradesSelected = true;
$.each($("#div_result").find("select"), (key, value) => {
if ($(value).val() == "-1" || $(value).val() == null) {
allGradesSelected = false;
return false;
}
});
if (!allGradesSelected) {
alert("Please select all the grades to calculate the final grade.");
return;
}
$.each($("#div_result").find("select"), (key, value) => {
let id = $(value).attr("id")
let base64 = id.split("_");
if (base64[1] == "TRUE") {
configs.total += configs.glh.external[parseInt(base64[2])][$("#" + id).val()]
}
else {
configs.total += configs.glh.internal[parseInt(base64[2])][$("#" + id).val()]
}
});
// calculate the final grade
let finalGrade = "";
$.each(configs.grades, (key, value) => {
if (configs.total >= key) {
finalGrade = value;
}
});
if ($("#div_result").find("h3").length > 0) {
$("#div_result").find("h3").remove();
}
if ($("#config_buttons").find("button").length > 1) {
$("#config_buttons").find("button.btn-danger").remove();
}
const ucasPoints = configs['ucas_calculator'][finalGrade];
$("#config_buttons").append(`<button class="btn btn-danger" onclick="location.reload()">Reset</button>`);
$("#div_result").append(`<h3 class="text-center">Your Approximate final grade is: <strong>${finalGrade}</strong> <br> UCAS Tarrif Points: <strong>${ucasPoints ?? '0'}</strong> <p style="color:red">NOTE: This is an approximate grade and may not be 100% accurate.</p></h3>`);
}
</script>
</body>
</html>