+ New, more detailed user event log entries that can be summed/etc.

* Last callers indicators now use new user event log entries
This commit is contained in:
Bryan Ashby 2019-01-17 20:18:02 -07:00
parent 7c6e3e3ad4
commit dc70521057
5 changed files with 102 additions and 32 deletions

View File

@ -174,7 +174,7 @@ exports.getModule = class LastCallersModule extends MenuModule {
let indicatorSumsSql; let indicatorSumsSql;
if(actionIndicatorNames.length > 0) { if(actionIndicatorNames.length > 0) {
indicatorSumsSql = actionIndicatorNames.map(i => { indicatorSumsSql = actionIndicatorNames.map(i => {
return `SUM(CASE WHEN log_value='${_.snakeCase(i)}' THEN 1 ELSE 0 END) AS ${i}`; return `SUM(CASE WHEN log_name='${_.snakeCase(i)}' THEN 1 ELSE 0 END) AS ${i}`;
}); });
} }

View File

@ -364,30 +364,8 @@ class StatLog {
} }
initUserEvents(cb) { initUserEvents(cb) {
// const systemEventUserLogInit = require('./sys_event_user_log.js');
// We map some user events directly to user stat log entries such that they systemEventUserLogInit(this);
// are persisted for a time.
//
const Events = require('./events.js');
const systemEvents = Events.getSystemEvents();
const interestedEvents = [
systemEvents.NewUser,
systemEvents.UserUpload, systemEvents.UserDownload,
systemEvents.UserPostMessage, systemEvents.UserSendMail,
systemEvents.UserRunDoor, systemEvents.UserSendNodeMsg,
systemEvents.UserAchievementEarned,
];
Events.addMultipleEventListener(interestedEvents, (event, eventName) => {
this.appendUserLogEntry(
event.user,
'system_event',
eventName.replace(/^codes\.l33t\.enigma\.system\./, ''), // strip package name prefix
90
);
});
return cb(null); return cb(null);
} }
} }

View File

@ -0,0 +1,69 @@
/* jslint node: true */
'use strict';
const Events = require('./events.js');
const LogNames = require('./user_log_name.js');
const DefaultKeepForDays = 365;
module.exports = function systemEventUserLogInit(statLog) {
const systemEvents = Events.getSystemEvents();
const interestedEvents = [
systemEvents.NewUser,
systemEvents.UserLogin, systemEvents.UserLogoff,
systemEvents.UserUpload, systemEvents.UserDownload,
systemEvents.UserPostMessage, systemEvents.UserSendMail,
systemEvents.UserRunDoor, systemEvents.UserSendNodeMsg,
systemEvents.UserAchievementEarned,
];
const append = (e, n, v) => {
statLog.appendUserLogEntry(e.user, n, v, DefaultKeepForDays);
};
Events.addMultipleEventListener(interestedEvents, (event, eventName) => {
const detailHandler = {
[ systemEvents.NewUser ] : (e) => {
append(e, LogNames.NewUser, 1);
},
[ systemEvents.UserLogin ] : (e) => {
append(e, LogNames.Login, 1);
},
[ systemEvents.UserLogoff ] : (e) => {
append(e, LogNames.Logoff, e.minutesOnline);
},
[ systemEvents.UserUpload ] : (e) => {
append(e, LogNames.UlFiles, e.files.length);
const totalBytes = e.files.reduce( (bytes, fileEntry) => bytes + fileEntry.meta.byte_size, 0);
append(e, LogNames.UlFileBytes, totalBytes);
},
[ systemEvents.UserDownload ] : (e) => {
append(e, LogNames.DlFiles, e.files.length);
const totalBytes = e.files.reduce( (bytes, fileEntry) => bytes + fileEntry.meta.byte_size, 0);
append(e, LogNames.DlFileBytes, totalBytes);
},
[ systemEvents.UserPostMessage ] : (e) => {
append(e, LogNames.PostMessage, e.areaTag);
},
[ systemEvents.UserSendMail ] : (e) => {
append(e, LogNames.SendMail, 1);
},
[ systemEvents.UserRunDoor ] : (e) => {
// :TODO: store door tag, else '-' ?
append(e, LogNames.RunDoor, 1);
},
[ systemEvents.UserSendNodeMsg ] : (e) => {
append(e, LogNames.SendNodeMsg, e.global ? 'global' : 'direct');
},
[ systemEvents.UserAchievementEarned ] : (e) => {
append(e, LogNames.AchievementEarned, e.achievementTag);
append(e, LogNames.AchievementPointsEarned, e.points);
}
}[eventName];
if(detailHandler) {
detailHandler(event);
}
});
};

21
core/user_log_name.js Normal file
View File

@ -0,0 +1,21 @@
/* jslint node: true */
'use strict';
//
// Common (but not all!) user log names
//
module.exports = {
NewUser : 'new_user',
Login : 'login',
Logoff : 'logoff',
UlFiles : 'ul_files', // value=count
UlFileBytes : 'ul_file_bytes', // value=total bytes
DlFiles : 'dl_files', // value=count
DlFileBytes : 'dl_file_bytes', // value=total bytes
PostMessage : 'post_msg', // value=areaTag
SendMail : 'send_mail',
RunDoor : 'run_door',
SendNodeMsg : 'send_node_msg', // value=global|direct
AchievementEarned : 'achievement_earned', // value=achievementTag
AchievementPointsEarned : 'achievement_pts_earned', // value=points earned
};

View File

@ -14,13 +14,15 @@ Available `config` block entries:
* `sysop`: Sysop options: * `sysop`: Sysop options:
* `collapse`: Collapse or roll up entries that fall within the period specified. May be a string in the form of `30 minutes`, `3 weeks`, `1 hour`, etc. * `collapse`: Collapse or roll up entries that fall within the period specified. May be a string in the form of `30 minutes`, `3 weeks`, `1 hour`, etc.
* `hide`: Hide all +op logins * `hide`: Hide all +op logins
* `actionIndicators`: Maps user actions to indicators. For example: `userDownload` to "D". Available indicators: * `actionIndicators`: Maps user events/actions to indicators. For example: `userDownload` to "D". Available indicators:
* `userDownload` * `newUser`: User is new.
* `userUpload` * `dlFiles`: User downloaded file(s).
* `userPostMsg` * `ulFiles`: User uploaded file(s).
* `userSendMail` * `postMsg`: User posted message(s) to the message base, EchoMail, etc.
* `userRunDoor` * `sendMail`: User sent _private_ mail.
* `userSendNodeMsg` * `runDoor`: User ran door(s).
* `sendNodeMsg`: User sent a node message(s).
* `achievementEarned`: User earned an achievement(s).
* `actionIndicatorDefault`: Default indicator when an action is not set. Defaults to "-". * `actionIndicatorDefault`: Default indicator when an action is not set. Defaults to "-".
Remember that entries such as `actionIndicators` and `actionIndicatorDefault` may contain pipe color codes! Remember that entries such as `actionIndicators` and `actionIndicatorDefault` may contain pipe color codes!