-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
107 lines (94 loc) · 4.97 KB
/
script.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
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
document.addEventListener('DOMContentLoaded', function () {
fetch('data/GenAI_May28.csv')
.then(response => response.text())
.then(data => {
const rows = data.split('\n');
const tableBody = document.querySelector('#leaderboard tbody');
// Create an array to store leaderboard data objects
const leaderboardData = [];
for (let i = 1; i < rows.length; i++) {
const rowData = rows[i].split(',');
if (rowData.length === 9) {
const [nameWithQuotes, email, profile, status, prompt_design, gemini_and_streamlit, genAIGames, allPathways, redemptionStatus] = rowData;
if (status !== 'All Good') continue; // Skip if the student is not enrolled
// Remove double quotes from the name
const name = nameWithQuotes.replace(/"/g, '');
// Convert redemption status to lowercase and remove whitespace
const cleanedRedemptionStatus = redemptionStatus.toLowerCase().replace(/\s/g, '');
if (cleanedRedemptionStatus === 'yes') {
val = 1;
}
else{
val = 0;
}
const cleanedAllPathways = allPathways.toLowerCase().replace(/\s/g, '');
// Calculate rank based on the number of courses completed
leaderboardData.push({
rank: parseInt(prompt_design) + parseInt(gemini_and_streamlit) + parseInt(genAIGames) + val,
name,
prompt_design: parseInt(prompt_design),
gemini_and_streamlit: parseInt(gemini_and_streamlit),
genAIGames: parseInt(genAIGames),
redemptionStatus: cleanedRedemptionStatus === 'yes' ? '<span class="green-tick">✔</span>' : '<span class="red-cross">✘</span>',
allPathways: cleanedAllPathways === 'yes' ? '<span class="green-tick">✔</span>' : '<span class="red-cross">✘</span>',
});
}
}
// Sort leaderboard data by rank (number of courses completed)
leaderboardData.sort((a, b) => b.rank - a.rank);
// Populate the leaderboard table
leaderboardData.forEach((data, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${index + 1}</td>
<td>${data.name}</td>
<td>${data.redemptionStatus}</td>
<td>${data.prompt_design}</td>
<td>${data.gemini_and_streamlit}</td>
<td>${data.genAIGames}</td>
<td>${data.allPathways}</td>
`;
tableBody.appendChild(row);
});
// Search functionality
const searchInput = document.querySelector('#search');
searchInput.addEventListener('input', function () {
const searchQuery = searchInput.value.toLowerCase();
const filteredData = leaderboardData.filter(data => data.name.toLowerCase().includes(searchQuery));
renderTable(filteredData);
});
// Initial rendering of the full leaderboard
renderTable(leaderboardData);
// Function to render the table based on data
function renderTable(data) {
tableBody.innerHTML = '';
data.forEach((data, index) => {
if (data.prompt_design + data.gemini_and_streamlit + data.genAIGames == 3){
const row = document.createElement('tr');
row.innerHTML = `
<td><img src="badge.png" width=20px></td>
<td>${data.name}</td>
<td>${data.redemptionStatus}</td>
<td>${data.prompt_design}</td>
<td>${data.gemini_and_streamlit}</td>
<td>${data.genAIGames}</td>
`;
tableBody.appendChild(row);
}
else {
const row = document.createElement('tr');
row.innerHTML = `
<td>${index + 1}</td>
<td>${data.name}</td>
<td>${data.redemptionStatus}</td>
<td>${data.prompt_design}</td>
<td>${data.gemini_and_streamlit}</td>
<td>${data.genAIGames}</td>
`;
tableBody.appendChild(row);
}
});
}
})
.catch(error => console.error('Error:', error));
});