Better door tracking

* Send event info with door run time & door tag
* Only if >= 45s
* Only log minutes if >= 1
* No timer required; track only @ door exit time
This commit is contained in:
Bryan Ashby 2019-01-18 23:12:01 -07:00
parent 7776391184
commit 0457a6601f
5 changed files with 26 additions and 35 deletions

View File

@ -6,17 +6,17 @@ const DropFile = require('./dropfile.js');
const Door = require('./door.js');
const theme = require('./theme.js');
const ansi = require('./ansi_term.js');
const Events = require('./events.js');
const { Errors } = require('./enig_error.js');
const StatLog = require('./stat_log.js');
const UserProps = require('./user_property.js');
const {
trackDoorRunBegin,
trackDoorRunEnd
} = require('./door_util.js');
// deps
const async = require('async');
const assert = require('assert');
const _ = require('lodash');
const paths = require('path');
const moment = require('moment');
const activeDoorNodeInstances = {};
@ -152,9 +152,6 @@ exports.getModule = class AbracadabraModule extends MenuModule {
}
runDoor() {
StatLog.incrementUserStat(this.client.user, UserProps.DoorRunTotalCount, 1);
Events.emit(Events.getSystemEvents().UserRunDoor, { user : this.client.user } );
this.client.term.write(ansi.resetScreen());
const exeInfo = {
@ -168,14 +165,10 @@ exports.getModule = class AbracadabraModule extends MenuModule {
node : this.client.node,
};
const startTime = moment();
const doorTracking = trackDoorRunBegin(this.client, this.config.name);
this.doorInstance.run(exeInfo, () => {
const endTime = moment();
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(this.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
}
trackDoorRunEnd(doorTracking);
//
// Try to clean up various settings such as scroll regions that may

View File

@ -10,32 +10,29 @@ const moment = require('moment');
exports.trackDoorRunBegin = trackDoorRunBegin;
exports.trackDoorRunEnd = trackDoorRunEnd;
function trackDoorRunBegin(client, doorTag) {
const startTime = moment();
// door must be running for >= 45s for us to officially record it
const timeout = setTimeout( () => {
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalCount, 1);
const eventInfo = { user : client.user };
if(doorTag) {
eventInfo.doorTag = doorTag;
}
Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo);
}, 45 * 1000);
return { startTime, timeout, client, doorTag };
return { startTime, client, doorTag };
}
function trackDoorRunEnd(trackInfo) {
const { startTime, timeout, client } = trackInfo;
const { startTime, client, doorTag } = trackInfo;
clearTimeout(timeout);
const diff = moment.duration(moment().diff(startTime));
if(diff.asSeconds() >= 45) {
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalCount, 1);
}
const endTime = moment();
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
const runTimeMinutes = Math.floor(diff.asMinutes());
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
const eventInfo = {
runTimeMinutes,
user : client.user,
doorTag : doorTag || 'unknown',
};
Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo);
}
}

View File

@ -54,8 +54,8 @@ module.exports = function systemEventUserLogInit(statLog) {
append(e, LogNames.SendMail, 1);
},
[ systemEvents.UserRunDoor ] : (e) => {
// :TODO: store door tag, else '-' ?
append(e, LogNames.RunDoor, 1);
append(e, LogNames.RunDoor, e.doorTag);
append(e, LogNames.RunDoorMinutes, e.runTimeMinutes);
},
[ systemEvents.UserSendNodeMsg ] : (e) => {
append(e, LogNames.SendNodeMsg, e.global ? 'global' : 'direct');

View File

@ -19,7 +19,7 @@ module.exports = {
UserDownload : 'codes.l33t.enigma.system.user_download', // { ..., files[ fileEntry, ...] }
UserPostMessage : 'codes.l33t.enigma.system.user_post_msg', // { ..., areaTag }
UserSendMail : 'codes.l33t.enigma.system.user_send_mail', // { ... }
UserRunDoor : 'codes.l33t.enigma.system.user_run_door', // { ... }
UserRunDoor : 'codes.l33t.enigma.system.user_run_door', // { ..., runTimeMinutes, doorTag|unknown }
UserSendNodeMsg : 'codes.l33t.enigma.system.user_send_node_msg', // { ..., global }
UserStatSet : 'codes.l33t.enigma.system.user_stat_set', // { ..., statName, statValue }
UserStatIncrement : 'codes.l33t.enigma.system.user_stat_increment', // { ..., statName, statIncrementBy, statValue }

View File

@ -14,7 +14,8 @@ module.exports = {
DlFileBytes : 'dl_file_bytes', // value=total bytes
PostMessage : 'post_msg', // value=areaTag
SendMail : 'send_mail',
RunDoor : 'run_door',
RunDoor : 'run_door', // value=doorTag|unknown
RunDoorMinutes : 'run_door_minutes', // value=minutes ran
SendNodeMsg : 'send_node_msg', // value=global|direct
AchievementEarned : 'achievement_earned', // value=achievementTag
AchievementPointsEarned : 'achievement_pts_earned', // value=points earned