From dc7052105785c9508c3ceac0089adf5066768e9f Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 17 Jan 2019 20:18:02 -0700 Subject: [PATCH] + New, more detailed user event log entries that can be summed/etc. * Last callers indicators now use new user event log entries --- core/last_callers.js | 2 +- core/stat_log.js | 26 ++------------ core/sys_event_user_log.js | 69 ++++++++++++++++++++++++++++++++++++ core/user_log_name.js | 21 +++++++++++ docs/modding/last-callers.md | 16 +++++---- 5 files changed, 102 insertions(+), 32 deletions(-) create mode 100644 core/sys_event_user_log.js create mode 100644 core/user_log_name.js diff --git a/core/last_callers.js b/core/last_callers.js index f7c2552e..9d875b2e 100644 --- a/core/last_callers.js +++ b/core/last_callers.js @@ -174,7 +174,7 @@ exports.getModule = class LastCallersModule extends MenuModule { let indicatorSumsSql; if(actionIndicatorNames.length > 0) { 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}`; }); } diff --git a/core/stat_log.js b/core/stat_log.js index 0ff6aff6..f03319d0 100644 --- a/core/stat_log.js +++ b/core/stat_log.js @@ -364,30 +364,8 @@ class StatLog { } initUserEvents(cb) { - // - // We map some user events directly to user stat log entries such that they - // 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 - ); - }); - + const systemEventUserLogInit = require('./sys_event_user_log.js'); + systemEventUserLogInit(this); return cb(null); } } diff --git a/core/sys_event_user_log.js b/core/sys_event_user_log.js new file mode 100644 index 00000000..8b9b3f22 --- /dev/null +++ b/core/sys_event_user_log.js @@ -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); + } + }); +}; diff --git a/core/user_log_name.js b/core/user_log_name.js new file mode 100644 index 00000000..6186d326 --- /dev/null +++ b/core/user_log_name.js @@ -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 +}; diff --git a/docs/modding/last-callers.md b/docs/modding/last-callers.md index 830244d7..0e15b4f8 100644 --- a/docs/modding/last-callers.md +++ b/docs/modding/last-callers.md @@ -14,13 +14,15 @@ Available `config` block entries: * `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. * `hide`: Hide all +op logins -* `actionIndicators`: Maps user actions to indicators. For example: `userDownload` to "D". Available indicators: - * `userDownload` - * `userUpload` - * `userPostMsg` - * `userSendMail` - * `userRunDoor` - * `userSendNodeMsg` +* `actionIndicators`: Maps user events/actions to indicators. For example: `userDownload` to "D". Available indicators: + * `newUser`: User is new. + * `dlFiles`: User downloaded file(s). + * `ulFiles`: User uploaded file(s). + * `postMsg`: User posted message(s) to the message base, EchoMail, etc. + * `sendMail`: User sent _private_ mail. + * `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 "-". Remember that entries such as `actionIndicators` and `actionIndicatorDefault` may contain pipe color codes!