[nodebb-widget-board-stats] discrepancy to dashboard count
-
hi.
i'm still pretty new to nodeBB - it's my second thread. we are a group of seven enthusiasts who moved a nearly 20 year old voluntary sports-forum in germany from a proprietary internet forum software to nodeBB. ... and we are still happy with our choice =;^) it's a great piece of software!
we are using the nodebb-widget-board-stats widget in a self-localized and customized version. we found a distinct discrepancy of the active users count shown by the widget compared to the dashboard. as far as i understand the active users count is calculated by
105 db.sortedSetCount('users:online', now - 300000, '+inf', next);
of library.js while the guest count is required by
108 require.main.require('./src/socket.io/admin/rooms').getTotalGuestCount(function (err, guestCount) { ...
as a live-value from nodeBB. unfortunately i have no idea where the active users count shown in the dashboard comes from. it's definitely not calculated the same way!
we had to treble the span of time from
300000
to900000
like in105 db.sortedSetCount('users:online', now - 900000, '+inf', next);
to come closer to the active users count shown in the dashboard but it depends on some undisclosed criteria - user activities or devices or whatever - that both values still differ significantly in both directions. my questions are:
- how is the active users count shown in the dashboard required?
- how to get the same value for the nodebb-widget-board-stats plugin?
some other thoughts: i'm wondering why the span of time is hard coded in the widget. from a more user perspective i would expect the
"onlineCutoff"
found in the"config"
key is taken into account. in both places!... and i have an additional "{count24h} users were active for the last 24 hours." on my personal wishlist, based on something like
... db.sortedSetCount('users:online', now - 8640000, '+inf', next);
i will try to achieve this by myself.
ober!schöne grüße,
mrx. -
Core uses the following to get the number of active users.
db.getSortedSetCount('users:online', now - (meta.config.onlineCutoff * 60000), '+inf');
This gives you the user count that is considered active, ie navigated or made a post in the past x minutes.
The dashboard is more real time, the values shown there are calculate here
If you want the same values as ACP you need to use
SocketRooms.getOnlineUserCount(io);
-
@DownPW said in [nodebb-widget-board-stats] discrepancy to dashboard count:
any news @murcs ?
i just digged a little deeper for you: „our“
/var/www/nodebb/node_modules/nodebb-widget-board-stats/library.js
looks like this'use strict'; const async = require('async'); const nconf = module.parent.require('nconf'); const db = require.main.require('./src/database'); const user = require.main.require('./src/user'); const utils = require.main.require('./src/utils'); const socketPlugins = require.main.require('./src/socket.io/plugins'); const socketRooms = require.main.require('./src/socket.io/admin/rooms'); let app; const Widget = module.exports; Widget.init = function (params, callback) { app = params.app; callback(); }; socketPlugins.boardStats = {}; socketPlugins.boardStats.get = function (socket, tid, callback) { getWidgetData(callback); }; function addDots(text) { return String(text).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.'); }; function getWidgetData(callback) { async.parallel({ global: function (next) { db.getObjectFields('global', ['topicCount', 'postCount', 'userCount'], next); }, latestUser: getLatestUser, activeUsers: getActiveUsers, onlineUsers: Widget.updateAndGetOnlineUsers, activeWithin24h: function (next) { var now = Date.now(); db.sortedSetCount('users:online', now - 86400000, '+inf', next); }, }, function (err, results) { if (err) { return callback(err); } var data = { within24h: results.activeWithin24h, count: addDots(results.onlineUsers.onlineCount + results.onlineUsers.guestCount), members: addDots(results.onlineUsers.onlineCount), guests: addDots(results.onlineUsers.guestCount), list: joinUsers(results.activeUsers), posts: addDots(results.global.postCount ? results.global.postCount : 0), topics: addDots(results.global.topicCount ? results.global.topicCount : 0), registered: addDots(results.global.userCount ? results.global.userCount : 0), latest: joinUsers(results.latestUser), relative_path: nconf.get('relative_path'), mostUsers: { date: (new Date(parseInt(results.onlineUsers.timestamp, 10))).toDateString(), total: results.onlineUsers.total, }, }; callback(null, data); }); } function getActiveUsers(callback) { async.waterfall([ function (next) { user.getUidsFromSet('users:online', 0, 19, next); }, function (uids, next) { user.getUsersFields(uids, ['username', 'userslug', 'status'], next); }, ], function (err, data) { if (err) { return callback(err); } data = data.filter(function (a) { return a.status === 'online'; }); callback(err, data); }); } function getLatestUser(callback) { async.waterfall([ function (next) { user.getUidsFromSet('users:joindate', 0, 0, next); }, function (uids, next) { user.getUsersWithFields(uids, ['username', 'userslug'], 0, next); }, ], callback); } function joinUsers(usersData) { var str = []; for (var i = 0, ii = usersData.length; i < ii; i++) { str.push('<a href="' + nconf.get('relative_path') + '/user/' + usersData[i].userslug + '">' + usersData[i].username + '</a>'); } return str.join(', '); } Widget.updateAndGetOnlineUsers = function (callback) { callback = typeof callback === 'function' ? callback : function () {}; async.waterfall([ function (next) { next(null, socketRooms.getLocalStats().onlineRegisteredCount); }, function (onlineCount, next) { socketRooms.getTotalGuestCount(function (err, guestCount) { if (err) { return next(err); } next(null, { onlineCount: parseInt(onlineCount, 10), guestCount: parseInt(guestCount, 10), }); }); }, function (users, next) { db.getObjectFields('plugin:widget-board-stats', ['total', 'timestamp'], function (err, data) { if (err) { return next(err); } var totalUsers = users.onlineCount + users.guestCount; data.timestamp = data.timestamp || Date.now(); if (parseInt(data.total || 0, 10) <= totalUsers) { data.timestamp = Date.now(); data.total = totalUsers; db.setObject('plugin:widget-board-stats', data); } data.onlineCount = users.onlineCount; data.guestCount = users.guestCount; return next(null, data); }); }, ], callback); }; Widget.renderWidget = function (widget, callback) { getWidgetData(function (err, data) { if (err) { return callback(err); } app.render('widgets/board-stats', data, function (err, html) { if (err) { return callback(err); } widget.html = html; callback(null, widget); }); }); }; Widget.defineWidgets = function (widgets, callback) { var widget = { widget: 'board-stats', name: 'Board Stats', description: 'Classical board stats widget in real-time.', content: 'admin/board-stats', }; app.render(widget.content, {}, function (err, html) { widget.content = html; widgets.push(widget); callback(err, widgets); }); };
which corresponds with our localized version of
/var/www/nodebb/node_modules/nodebb-widget-board-stats/public/templates/widgets/board-stats.tpl
<div component="widget/board-stats" class="widget-board-stats" style="border: 1px solid #999"> <h3 style="background: #666; font-size: 15px; font-weight: 500">Folgende Nutzende sind gerade online: <a href="{config.relative_path}/users?section=online">[komplette Liste]</a></h3> <p> Davon sind aktuell <strong component="widget/board-stats/count">{count}</strong> Nutzende aktiv (<strong component="widget/board-stats/members">{members}</strong> Registrierte + <strong component="widget/board-stats/guests">{guests}</strong>Gäste).<br /> <span style="display: block; line-height: 0.5em" > </span> <span component="widget/board-stats/list">{list}</span> <span style="display: block; line-height: 0.5em" > </span> In den letzten 24 Stunden waren <strong component="widget/board-stats/within24h">{within24h}</strong> verschiedene Nutzende eingeloggt. </p> <h3 style="background: #666; font-size: 15px; font-weight: 500">Forum-Statistik</h3> <p> Unsere aktiven registrierten Mitglieder haben <strong component="widget/board-stats/posts">{posts}</strong> Beiträge zu <strong component="widget/board-stats/topics">{topics}</strong> Themen verfasst –<strong component="widget/board-stats/registered">{registered}</strong> Mitglieder sind bei <em>schoenen-dunk.de</em> registriert.<br /> <span style="display: block; line-height: 0.5em" > </span> <span component="widget/board-stats/latest">{latest}</span> ist unser neuestes Mitglied. Herzlich Willkommen!<br /> <span style="display: block; line-height: 0.5em" > </span> Am {mostUsers.date} waren <strong>{mostUsers.total}</strong> Nutzende gleichzeitig online. </p> </div>
well. i hope this helps a bit.
ober!schöne grüße,
m.