-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
77 lines (65 loc) · 2.16 KB
/
main.js
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
(function (window, undefined) {
"use strict";
let host = "http://23.22.137.193:5000/";
//let host = "http://localhost:5000/";
fetch_classes(2174, "cs");
//let table = build_table(mock);
function fetch_classes(term, code)
{
let num = 0;
console.log("Fetching courses...");
fetch(host + "courses/" + term + "/" + code)
.then(response => {
console.log("Done!");
return response.json();
})
.then(json => {
let classes = json.map((course) => {return course.class_number});
let num_classes = classes.length;
console.log("Fetching individual class details...");
Promise.all(classes.map((class_number) => {
return fetch(host + "class/" + class_number + "/" + term)
.then(response => {
return response.json();
})
.then(json => {
num++;
console.log(num + "/" + num_classes);
return json;
});
}))
.then((response) => {
console.log("Done!");
let table = build_table(response);
});
});
}
function build_table(data)
{
let table = {};
data.filter((cl) => {
if(cl.time[0] == "")
{
return false;
}
else
{
return true;
}
}).forEach((cl) => {
cl.time[0] = format_time(cl.time[0]);
cl.time[1] = format_time(cl.time[1]);
table[cl.class_number] = cl;
});
return table;
}
function format_time(time)
{
let time_minutes = (parseInt(time.substring(0,2)) - 1) * 60 + parseInt(time.substring(3,4));
if(time.substring(6) == "PM" && time.substring(0,2) != "12")
{
time_minutes += 720;
}
return time_minutes;
}
})(typeof window !== "undefined" ? window : {});