user presence pie chart

v1.18.x
psychobunny 10 years ago
parent f549ef8e26
commit b34ec8d732

@ -124,13 +124,18 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
'<div>Connections</div>' + '<div>Connections</div>' +
'</div>'; '</div>';
var idle = data.socketCount - data.users.home + data.users.topics + data.users.category;
updateRegisteredGraph(data.onlineRegisteredCount, data.onlineGuestCount); updateRegisteredGraph(data.onlineRegisteredCount, data.onlineGuestCount);
updatePresenceGraph(data.users.home, data.users.topics, data.users.category, idle);
$('#active-users').html(html); $('#active-users').html(html);
}; };
var graphs = { var graphs = {
traffic: null traffic: null,
registered: null,
presence: null
}; };
function getHoursArray() { function getHoursArray() {
@ -148,8 +153,10 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
function setupGraphs() { function setupGraphs() {
var trafficCanvas = document.getElementById('analytics-traffic'), var trafficCanvas = document.getElementById('analytics-traffic'),
registeredCanvas = document.getElementById('analytics-registered'), registeredCanvas = document.getElementById('analytics-registered'),
presenceCanvas = document.getElementById('analytics-presence'),
trafficCtx = trafficCanvas.getContext('2d'), trafficCtx = trafficCanvas.getContext('2d'),
registeredCtx = registeredCanvas.getContext('2d'), registeredCtx = registeredCanvas.getContext('2d'),
presenceCtx = presenceCanvas.getContext('2d'),
trafficLabels = getHoursArray(); trafficLabels = getHoursArray();
var data = { var data = {
@ -198,6 +205,33 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
responsive: true responsive: true
}); });
graphs.presence = new Chart(presenceCtx).Doughnut([{
value: 1,
color:"#F7464A",
highlight: "#FF5A5E",
label: "On homepage"
},
{
value: 1,
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Reading posts"
},
{
value: 1,
color: "#FDB45C",
highlight: "#FFC870",
label: "Browsing topics"
},
{
value: 1,
color: "#949FB1",
highlight: "#A8B3C5",
label: "Idle"
}], {
responsive: true
});
setInterval(updateTrafficGraph, 15000); setInterval(updateTrafficGraph, 15000);
updateTrafficGraph(); updateTrafficGraph();
} }
@ -222,5 +256,13 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
graphs.registered.update(); graphs.registered.update();
} }
function updatePresenceGraph(homepage, posts, topics, idle) {
graphs.presence.segments[0].value = homepage;
graphs.presence.segments[1].value = posts;
graphs.presence.segments[2].value = topics;
graphs.presence.segments[3].value = idle;
graphs.presence.update();
}
return Admin; return Admin;
}); });

@ -83,11 +83,27 @@ SocketMeta.rooms.enter = function(socket, data, callback) {
}; };
SocketMeta.rooms.getAll = function(socket, data, callback) { SocketMeta.rooms.getAll = function(socket, data, callback) {
var userData = { var rooms = websockets.server.sockets.manager.rooms,
onlineGuestCount: websockets.getOnlineAnonCount(), userData = {
onlineRegisteredCount: websockets.getOnlineUserCount(), onlineGuestCount: websockets.getOnlineAnonCount(),
socketCount: websockets.getSocketCount() onlineRegisteredCount: websockets.getOnlineUserCount(),
}; socketCount: websockets.getSocketCount(),
users: {
home: rooms['/home'] ? rooms['/home'].length : 0,
topics: 0,
category: 0
}
};
for (var room in rooms) {
if (rooms.hasOwnProperty(room)) {
if (room.match(/^\/topic/)) {
userData.users.topics += rooms[room].length
} else if (room.match(/^\/category/)) {
userData.users.category += rooms[room].length
}
}
}
callback(null, userData); callback(null, userData);
}; };

@ -66,6 +66,15 @@
</div> </div>
</div> </div>
<div class="panel panel-default">
<div class="panel-heading">User Presence</div>
<div class="panel-body">
<div class="graph-container">
<canvas id="analytics-presence"></canvas>
</div>
</div>
</div>
<!-- BEGIN stats --> <!-- BEGIN stats -->
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">{stats.name}</div> <div class="panel-heading">{stats.name}</div>

Loading…
Cancel
Save