-
Notifications
You must be signed in to change notification settings - Fork 307
/
progressboard.html
124 lines (107 loc) · 3.66 KB
/
progressboard.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<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: #F88; font-size:1.2em}
.passed {background-color: #8F8;}
.unknown {background-color: #FF8;}
.table td {padding:0.25rem;}
.strike {background-color: yellow;}
.spare {background-color: cyan;}
.both {font-weight: bold;}
</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 = "bowling";
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 formatName(name){
const good = (name.toLowerCase().indexOf("spare") >=0 && name.toLowerCase().indexOf("strike") >=0);
name = name.
replace("strike", "<span class='strike'>strike</span>").
replace("spare", "<span class='spare'>spare</span>").
replace("Strike", "<span class='strike'>Strike</span>").
replace("Spare", "<span class='spare'>Spare</span>");
if (good) return "<span class='both'>" + name + "</span>";
return name;
}
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 + "'>" +
formatName(htmlEscape(name)) +
"</span> ";
}
</script>
</body>
</html>