-
Notifications
You must be signed in to change notification settings - Fork 87
/
leaderboard.html
108 lines (94 loc) · 2.99 KB
/
leaderboard.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
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css">
<style>
body {margin:20px;}
h1 {text-align:center;}
.team-row { margin-top:0px;}
.testname {padding:5px;line-height: 2em;}
.failed {background-color: #FDD; font-size:1.2em}
.passed {background-color: #DFD;}
.unknown {background-color: #FFD;}
.table td {padding:0.25rem;}
</style>
</head>
<body>
<div id="container" />
<script>
function buildDateKey() {
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var year = now.getFullYear();
return year + month + day;
}
function createFirebase() {
var url = "https://testing-challenge.firebaseio.com";
var realm = "legacy";
var dateKey = buildDateKey();
return new Firebase(`${url}/${realm}/${dateKey}`);
}
var fb = createFirebase();
fb.on("value", function(snapshot) {
var res = snapshot.val();
var html = "<table class='table table-condensed table-striped'>";
var names = Object.keys(res);
names.sort((a,b) => Object.keys(res[b].tests).length - Object.keys(res[a].tests).length);
names.forEach(function(name){
html += buildTeamHtml(name, res[name]);
});
html += "</table>";
document.getElementById("container").innerHTML = html;
});
function buildTeamHtml(name, value) {
var lang = value.lang;
var suffix = lang ? " (" + lang + ")" : "";
var html = "<tr><td class='name'>" + htmlEscape(name) + suffix + "</td>";
var rawTests = value.tests;
var maxLastRunTime = getMaxLastRunTime(rawTests);
var tests = rawTests
.filter(test => {
var lastRunTime = new Date(test.LastRunTime);
var diffInMinutes = getDifferenceInMinutes(maxLastRunTime, lastRunTime);
console.log(diffInMinutes);
return diffInMinutes < 10;
})
.map(test => {
return {
"name": test.TestName,
"status": test.Succeeded ? "passed" : "failed"
}
});
tests.sort((a,b) => a.name < b.name ? -1 : +(a.status > b.status));
html += "<td>" + tests.filter(t => t.status == "passed").length + "/" + tests.length + "</td>";
html += "<td>"
tests.forEach(test => html += formatTest(test.name, test.status));
html += "</td></tr>";
return html;
}
function getMaxLastRunTime(rawTests) {
var lastRunTimes = rawTests.map(test => new Date(test.LastRunTime));
var time = Math.max.apply(Math, lastRunTimes);
return new Date(time);
}
function getDifferenceInMinutes(date1, date2) {
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
return Math.ceil(timeDiff / (1000 * 60));
}
function htmlEscape(str) {
return str
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '')
.replace(/>/g, '');
}
function formatTest(name, status){
return "<span title='" + status + "' class='testname " + status + "'>" +
htmlEscape(name) +
"</span> ";
}
</script>
</body>
</html>