-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (90 loc) · 3.69 KB
/
Copy pathscript.js
File metadata and controls
90 lines (90 loc) · 3.69 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
let dates,
days,
firsubs,
secsubs,
ranges,
mins,
maxes,
fsubjects,
ssubjects,
timerz,
centers;
let ICS1 = "I Comp. Sc. I English I Math I Islamic Studies I Urdu I Physics I Al Quran";
let PE1 = "I Chem I English I Math I Islamic Studies I Urdu I Physics I Al Quran";
let PM1 = "I Chem I English I Biology I Islamic Studies I Urdu I Physics I Al Quran";
let ICS2 = "II Comp. Sc. II English II Math II Pakistan Studies II Urdu II Physics II Al Quran";
let PE2 = "II Chem II English II Math II Pakistan Studies II Urdu II Physics II Al Quran";
let PM2 = "II Chem II English II Biology II Pakistan Studies II Urdu II Physics II Al Quran";
let ART1 = "I English Lit. I Persian I Punjabi I H. & P. Edu. I Fine Arts I Geography I Islamic Studies (Ele) I History of Pakistan I History of Muslim India I Ethics I Edu I Philosophy I Pak Culture I Civics I French I Urdu Advance";
let ART2 = "II English Lit. II Persian II Punjabi II H. & P. Edu. II Fine Arts II Geography II Islamic Studies (Ele) II History of Pakistan II History of Muslim India II Ethics II Edu II Philosophy II Pak Culture II Civics II French II Urdu Advance II Psy";
let COM1 = "I Principles of Economics I Business Math I Principles of Comm. I Princ. of Account.";
let COM2 = "II Commercial Geography II Business Math II Principles of Comm. II Princ. of Account. II Stat";
let GS1 = "I Economics I Stat";
let GS2 = "II Economics II Stat";
let ICSA1, ICSA2, PEA1, PEA2, PMA1, PMA2, ARTA1, ARTA2, COMA1, COMA2, GSA1, GSA2;
function mapdata() {
fsubjects = rem(markAsNull(datac[0], " II"));
ssubjects = rem(datac[0].map((x, i) => (fsubjects[i] == null ? x : null)));
ranges = datac[1];
centers = datac[2];
timerz = datac[3];
mins = ranges.map((r) => parseRange(r).min);
maxes = ranges.map((r) => parseRange(r).max);
}
function mapschedule() {
dates = schedule[0];
days = schedule[1];
secsubs = schedule[3].map((x) => saparator(x, "II "));
firsubs = schedule[2].map((x) => saparator(x, "I "));
ICSA1 = saparator(ICS1, "I ");
PEA1 = saparator(PE1, "I ");
PMA1 = saparator(PM1, "I ");
ARTA1 = saparator(ART1, "I ");
COMA1 = saparator(COM1, "I ");
GSA1 = saparator(GS1, "I ");
ICSA2 = saparator(ICS2, "II ");
PEA2 = saparator(PE2, "II ");
PMA2 = saparator(PM2, "II ");
ARTA2 = saparator(ART2, "II ");
COMA2 = saparator(COM2, "II ");
GSA2 = saparator(GS2, "II ");
}
function saparator(input, delimiter) {
return input
.split(delimiter)
.map((x) => x.trim().replace(/"/g, ""))
.filter((x) => x);
}
function parseRange(input) {
if (input === "All Students") return { min: 0, max: 10000 };
let [min, max] = input.split("-").map(Number);
return { min, max };
}
function markAsNull(arr, destroyer) {
return arr.map((x) => (x && x.endsWith(destroyer) ? null : x));
}
function rem(arr) {
return arr.map((x) => (x ? x.replace(/ (II|I)$/, "") : null));
}
function extract(input) {
let [rollNo, _, grade] = input.split("-").map(Number);
if(grade > 2000) grade -= 2000;
grade = grade == 25 ? 1 : 2;
return rollNo && grade ? { rollNo, grade } : null;
}
function validate(input) {
let err = document.getElementById("errorMessage");
let table = document.getElementById("scheduleTable");
err.textContent = "";
table.style.display = "none";
if (!input.trim()) return (err.textContent = "Input cannot be empty."), false;
if (/[a-zA-Z]/.test(input))
return (err.textContent = "Input cannot contain alphabets."), false;
if (!/^\d{1,4}-\d{1,2}(-\d{2})?$/.test(input))
return (
(err.textContent = 'Invalid format. Please enter in "XXXX-X-XX"'), false
);
if (extract(input)?.grade > 2 || extract(input)?.grade < 1)
return (err.textContent = "You must be either 1st year or 2nd year"), false;
return true;
}