forked from kontur-courses/testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
90 lines (80 loc) · 3.02 KB
/
index.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
<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>
.no {
background-color: #FCC;
}
.ok {
background-color: #DFD;
}
.over {
background-color: #FFA;
}
</style>
</head>
<body>
<div id="container"/>
<script>
var implementationCodes = ["C", "E", "CR", "E2", "E3", "E4", "L2", "L3", "L4", "O1", "O2", "O3", "O4", "123", "998", "999", "EN1", "EN2", "QWE", "STA"];
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 = "word-statistics";
var dateKey = buildDateKey();
return new Firebase(`${url}/${realm}/${dateKey}`);
}
console.log("hi!");
var fb = createFirebase();
fb.on("value", function (snapshot) {
var html = "<table class='table table-condensed'>";
html += "<tr>";
["Name"].concat(implementationCodes).forEach(v => html += "<th>" + v + "</th>");
html += "</tr>";
var res = snapshot.val();
res = res ? res : [];
var names = Object.keys(res).filter(k => res[k].implementations);
names.sort((a, b) => {
return -countNonZero(res[a].implementations) + countNonZero(res[b].implementations)
|| countFailedTests(res[a].implementations) - countFailedTests(res[b].implementations)
});
names.forEach(function (name) {
var lang = res[name].lang;
var urlParams = new URLSearchParams(window.location.search);
var langFilter = urlParams.get('lang');
if (langFilter != null && langFilter != lang) return;
var suffix = lang ? " (" + lang + ")" : "";
if (langFilter != null) suffix = "";
html += "<tr><td>" + name.replace("<", "").replace(">", "") + suffix + "</td>";
implementationCodes.forEach(i => {
var result = res[name].implementations["WordsStatistics" + i];
html += formatCell(result);
});
html += "</tr>";
});
html += "</table>";
document.getElementById("container").innerHTML = html;
});
function countNonZero(implementations) {
return Object.keys(implementations).filter(k => implementations[k] > 0).length;
}
function countFailedTests(implementations) {
return Object
.values(implementations)
.reduce((sum, val) => sum + val);
}
function formatCell(v) {
var clazz = v === 0 ? "no" : (v <= 3 ? "ok" : "over");
return "<td class='" + clazz + "'>" + v + "</td>";
}
</script>
</body>
</html>