-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboard.js
More file actions
130 lines (86 loc) · 2.97 KB
/
leaderboard.js
File metadata and controls
130 lines (86 loc) · 2.97 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
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
var firebaseConfig = {
apiKey: "AIzaSyCgRDhjFb26u8iiMkoJP3TpfSlZnU96P-w",
authDomain: "medicodes-77362.firebaseapp.com",
projectId: "medicodes-77362",
storageBucket: "medicodes-77362.appspot.com",
messagingSenderId: "387859315681",
appId: "1:387859315681:web:23df9db36792f34e2930a0",
measurementId: "G-0RZHG2KT93"
};
firebase.initializeApp(firebaseConfig);
firebase.analytics;
//Set the type as student or teacher
var id = sessionStorage.getItem("email");
function first(){
ref = firebase.database().ref("students/").once('value', gotdata, errdata);
function compareSecondColumn(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] > b[0]) ? -1 : 1;
}
}
function gotdata(data){
const db = data.val();
const keys = Object.keys(db);
var w = [];
firebase.database().ref("students/" + id).once('value').then(function (snapshot) {
if(sessionStorage.getItem("type") === "student"){
var email = snapshot.val().Email;
}
else{
var email = "";
}
for (let i = 0; i < keys.length; i++) {
var k = keys[i];
const arr = []
var score = (db[k].Contest_questions.split(" ").length - 1) * 100;
arr.push(score);
arr.push(db[k].Name);
arr.push(db[k].Email);
w.push(arr);
}
w = w.sort(compareSecondColumn)
var table = document.getElementById("showdata");
for(let i=0; i<w.length; i++){
var a = document.createElement("tr");
var b = document.createElement("th");
var c = document.createElement("td");
var d = document.createElement("td");
var e = document.createElement("td");
b.innerText = i+1;
c.innerText = w[i][1];
d.innerText = w[i][2];
e.innerText = w[i][0];
//Current user classname -- "current-user"
if(email === w[i][2]){
a.className = "current-user";
}
a.appendChild(b);
a.appendChild(c);
a.appendChild(d);
a.appendChild(e);
table.appendChild(a);
}
});
}
function errdata(){
}
}
function profile(){
if(sessionStorage.getItem("type") === "student"){
location.href = "profile.html";
}
else{
location.href = "faculty-profile.html";
}
}
function dashboard(){
if(sessionStorage.getItem("type") === "student"){
location.href = "dashboard.html";
}
else{
location.href = "faculty-dashboard.html";
}
}