forked from binarymaster/3WiFi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.html
165 lines (155 loc) · 4.29 KB
/
graph.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<title>%l10n_title_graph%</title>
<head>
<script language="javascript" type="text/javascript" src="jquery.flot.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.categories.min.js"></script>
<script type="text/javascript">
function showLoads()
{
$.get('3wifi.php?a=loads', function(d)
{
var lo = 0, hi = 0, dt = 0;
if (!d.result)
{
$('#stat').text(errorStr(d.error));
return;
}
for (var i = 0; i < d.data.length; i++)
{
d.data[i][2] = d.data[i][0];
dt = d.data[i][0].split('.');
if (lo == 0) lo = dt[0] + '.' + dt[1];
hi = dt[0] + '.' + dt[1];
if (d.data.length-i < 5) dt[2] += ' '; // dirty hack to prevent graph overlapping
d.data[i][0] = dt[2];
}
d.label = (lo == hi ? lo : lo + '-' + hi);
$('#stat').text('%l10n_str_today_loaded% ');
var dyn = (d.data[d.data.length - 1][1] > d.data[d.data.length - 2][1] ? 1 : -1);
$('#today').html(d.data[d.data.length - 1][1] + ' <font color="#'+(dyn > 0 ? '0f0">▲' : 'f00">▼')+'</font>');
gl_data.pop();
gl_data.push(d);
$.plot('#graphload', gl_data, gl_opts);
setTimeout(showLoads, 600000); // 10 min
}).fail(function(jqXHR, textStatus, errorThrown) {
$('#stat').text('%l10n_err_data%');
setTimeout(showLoads, 5000);
});
}
function zip(arr)
{
var result = [];
for (var i = 0; i < arr.length; i++) result.push([i,arr[i]]);
return result;
}
function showTasks()
{
$.get('3wifi.php?a=stat&mode=2', function(d)
{
if (!d.result)
{
$('#task').text(errorStr(d.error));
return;
}
$('#task').text(d.stat.tasks.comment == null ? '%l10n_str_no_tasks%' : '%l10n_tbl_task_now% ' + d.stat.tasks.comment);
gtv_load.splice(0,1);
gtv_load.push(d.stat.tasks.uploading);
gt_load.data = zip(gtv_load);
gtv_proc.splice(0,1);
gtv_proc.push(d.stat.tasks.processing);
gt_proc.data = zip(gtv_proc);
gtv_geo.splice(0,1);
gtv_geo.push(d.stat.geoloc);
gt_geo.data = zip(gtv_geo);
$.plot('#graphtask', [gt_geo,gt_load,gt_proc], gt_opts);
setTimeout(showTasks, 1000);
}).fail(function(jqXHR, textStatus, errorThrown) {
$('#task').text('%l10n_err_data%');
setTimeout(showTasks, 5000);
});
}
function initpage()
{
$('.content').css('padding-top', '0px');
$("<div id='tooltip'></div>").css({
position: 'absolute',
display: 'none',
border: '1px solid #ffd',
padding: '2px',
'background-color': '#ffe',
opacity: 0.80
}).appendTo('body');
var wid = Math.round(screen.width / 1.75);
$('.graphbkg').css('width', wid);
$('.graphbkg').css('height', Math.round(wid / 1.8));
gl_opts = {
series: {
color: '#9d7',
lines: { show: true, fill: true, lineWidth: 1 },
points: { show: true }
},
grid: { hoverable: true },
xaxis: {
mode: 'categories',
tickDecimals: 0,
tickSize: 1
},
yaxis: { min: 0, tickDecimals: 0 }
};
gl_data = [];
$.plot('#graphload', gl_data, gl_opts);
$('#graphload').bind('plothover', function (event, pos, item)
{
if (item) {
var x = item.series.data[item.dataIndex][2],
y = item.datapoint[1];
$('#tooltip').html(y + ' %l10n_str_loaded% ' + x)
.css({top: item.pageY - $('#tooltip').height() - 9, left: item.pageX - $('#tooltip').width()/2})
.fadeIn(200);
} else
$('#tooltip').hide();
});
$('#today').empty();
$('#stat').text('%l10n_str_updating%');
showLoads();
gtv_load = [];
for (var i = 0; i < 60; i++) gtv_load.push(0);
gt_load = {};
gt_load.data = zip(gtv_load);
gt_load.label = '%l10n_graph_task_load%';
gtv_proc = [];
for (var i = 0; i < 60; i++) gtv_proc.push(0);
gt_proc = {};
gt_proc.data = zip(gtv_proc);
gt_proc.label = '%l10n_graph_task_proc%';
gtv_geo = [];
for (var i = 0; i < 60; i++) gtv_geo.push(0);
gt_geo = {};
gt_geo.data = zip(gtv_geo);
gt_geo.label = '%l10n_graph_task_geo%';
gt_opts = {
series: { bars: { show: true, fill: true, lineWidth: 1 } },
xaxis: {
show: false,
tickDecimals: 0,
tickSize: 1
},
yaxis: { min: 0, tickDecimals: 0 }
};
$.plot('#graphtask', [gt_geo,gt_load,gt_proc], gt_opts);
showTasks();
}
</script>
</head>
<body>
<h2 align=center class=header_cap>%l10n_msg_graph%</h2>
<div align=center>
<div class=graphbkg>
<div id=graphload class=graph></div>
<div align=left><span id=stat></span><span id=today></span></div>
</div>
<div class=graphbkg>
<div id=graphtask class=graph></div>
<div align=left><span id=task></span></div>
</div>
</div>
</body>