-
Notifications
You must be signed in to change notification settings - Fork 4
/
oldindex.html
120 lines (104 loc) · 3.49 KB
/
oldindex.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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Blip Server</title>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
</head>
<body>
<div id="graph" style="width:800px;height:400px;"></div>
<h3>Last update:</h3>
<p><pre id="text"><a href="http://browsehappy.com/">http://browsehappy.com/</a></pre></p>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.flot.js"></script>
<script type="text/javascript">
/*global jQuery:false, $:false */
/*jslint whitespace:false, indent:4, onevar:false, browser:true */
$(function () {
var options = {
lines: { show: true },
xaxis: { mode: 'time' },
yaxis: {
min: 0,
tickFormatter: function (val, axis) {
return val.toFixed(axis.tickDecimals) + 'W';
}
},
colors: [ 'red' ]
},
data,
graph = $('#graph'),
text = document.getElementById('text'),
timezoneOffset = (new Date()).getTimezoneOffset() * 60000,
preparePoint,
fillGraph,
callHome,
initReq,
pollError,
initError,
onDataReceived;
preparePoint = function (point) {
var stamp = point[0],
ms = point[1];
stamp -= ms / 2;
/* hack to show times in local time */
stamp -= timezoneOffset;
point[0] = stamp;
point[1] = 3600000 / ms;
};
fillGraph = function (values) {
for (i in values) {
preparePoint(values[i]);
}
data = values;
$.plot(graph, [ data ], options);
callHome();
};
callHome = function () {
$.ajax({
url: '/blip',
method: 'GET',
dataType: 'json',
success: onDataReceived,
error: pollError
});
};
pollError = function() {
setTimeout(callHome, 20000);
};
initReq = function() {
$.ajax({
url: '/last/1200000', /* last 20min */
method: 'GET',
dataType: 'json',
success: fillGraph,
error: initError
});
};
initError = function() {
setTimeout(initReq, 20000);
};
onDataReceived = function (point) {
var stamp = point[0],
ms = point[1],
time = new Date(stamp);
preparePoint(point);
data.push(point);
stamp = point[0] - 1200000; /* 20min */
while (data[0][0] < stamp) {
data.shift();
}
text.textContent = time.toString() + ' - ' + ms + 'ms -> ' + point[1].toFixed(0) + 'W';
$.plot(graph, [ data ], options);
callHome();
};
initReq();
});
</script>
<a href="https://github.com/labitat/blipserver"><img style="position: absolute; top: 0; right: 0; border: 0;" src="ribbon.png" alt="Fork me on GitHub"></a>
</body>
<!-- vim: ts=4 sw=4 et:
-->
</html>