forked from design-camp/design-camp.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
144 lines (134 loc) · 3.68 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html>
<head>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="firebase.js"></script>
<script src="marked.min.js"></script>
<script src="mustache.min.js"></script>
<script src="plotly-latest.min.js"></script>
<style>
td, th {
font-size: 16pt;
}
</style>
</head>
<body class="container">
<div id="scoretable"></div>
<h1>Релизы</h1>
Минут до следующего релиза: <span id="nextReleaseTime"></span>
<div id="releasesPlot" style="width:100%;height:300px;"></div>
<a href="https://design-camp.firebaseio.com/camp.json">Полная информация в JSON</a>
<h1>Формулировки заданий</h1>
<div id="statements" style="padding:50px"></div>
<script id="scoretable-template" type="text/template">
<table class="table table-condensed">
<tr>
<th>Name</th>
<th>Score</th>
{{#tasks}}
<th>{{.}}</th>
{{/tasks}}
</tr>
{{#teams}}
<tr>
<th>{{name}}</th>
<th>{{score}}</th>
{{#tasks}}
<td>{{.}}</td>
{{/tasks}}
</tr>
{{/teams}}
</table>
</script>
<script>
function convertData(curState, teamNames, tasks){
var teamsData = teamNames.map(function(n){
return {
name:n,
score:Math.round(curState[n].Score),
tasks: tasks.map(function(t) {
return Math.round(curState[n].Tasks ? +curState[n].Tasks[t.id] : 0);
})
}});
return {
tasks: tasks.map(function(t) {return t.id;}),
teams: teamsData
};
}
function updateScoreboard(data){
var tmpl = document.getElementById("scoretable-template").innerHTML;
var rendered = Mustache.render(tmpl, data);
document.getElementById("scoretable").innerHTML = rendered;
}
function updateStatements(tasks){
var statements = tasks.map(function (t) {
return "## " + t.id + "\n\n" + t.md}).join("\n\n");
document.getElementById("statements").innerHTML = marked(statements);
}
</script>
<script>
var fb = new Firebase("https://design-camp.firebaseio.com/camp/");
fb.child("CurrentState")
.on("value", function(snapshot) {
var data = snapshot.val();
console.log(data);
var teams = Object.keys(data);
teams = teams.sort(function(t1, t2){return data[t2].Score-data[t1].Score;});
showPlot(teams);
fb.child("Tasks").once("value", function(snapshot) {
var tasks = snapshot.val();
updateScoreboard(convertData(data, teams, tasks));
updateStatements(tasks);
});
});
var nextReleaseTime;
fb.child("NextReleaseTime").on("value", function(snapshot){
nextReleaseTime = new Date(snapshot.val());
setInterval(updateReleaseTimeSpan, 1000);
});
function updateReleaseTimeSpan(){
var mins = Math.max(0, (nextReleaseTime - new Date()) / 1000 / 60);
document.getElementById("nextReleaseTime").innerHTML = Math.round(mins);
setTimer()
}
function showPlot(){
fb.child("Releases").on("value", function(snapshot) {
var data = snapshot.val();
var xx = Object.keys(data).sort();
if (xx.length <= 1) return;
var lastRelease = data[xx[xx.length-1]];
var teams = Object.keys(lastRelease);
var tracks = teams.map(
function getTrack(team){
var yy = xx.map(function(x) { return data[x][team].Score});
for(var i=1; i<yy.length; i++)
yy[i] = yy[i] + yy[i-1];
return {
x: xx.map(function(v,i) {return i;}),
y: yy,
name: team,
type: 'scatter',
mode: 'lines',
line: {
width: 5
}
}
});
var plotDiv = document.getElementById('releasesPlot');
if (plotDiv.data){
plotDiv.data = tracks;
Plotly.redraw(plotDiv);
}
else{
var layout = {
margin: { t: 0 },
font: {
size: 24,
},
};
Plotly.plot(plotDiv, tracks, layout );
}
})
}
</script>
</body>
</html>