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:
parent
7776391184
commit
0457a6601f
|
@ -6,17 +6,17 @@ const DropFile = require('./dropfile.js');
|
||||||
const Door = require('./door.js');
|
const Door = require('./door.js');
|
||||||
const theme = require('./theme.js');
|
const theme = require('./theme.js');
|
||||||
const ansi = require('./ansi_term.js');
|
const ansi = require('./ansi_term.js');
|
||||||
const Events = require('./events.js');
|
|
||||||
const { Errors } = require('./enig_error.js');
|
const { Errors } = require('./enig_error.js');
|
||||||
const StatLog = require('./stat_log.js');
|
const {
|
||||||
const UserProps = require('./user_property.js');
|
trackDoorRunBegin,
|
||||||
|
trackDoorRunEnd
|
||||||
|
} = require('./door_util.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const paths = require('path');
|
const paths = require('path');
|
||||||
const moment = require('moment');
|
|
||||||
|
|
||||||
const activeDoorNodeInstances = {};
|
const activeDoorNodeInstances = {};
|
||||||
|
|
||||||
|
@ -152,9 +152,6 @@ exports.getModule = class AbracadabraModule extends MenuModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
runDoor() {
|
runDoor() {
|
||||||
StatLog.incrementUserStat(this.client.user, UserProps.DoorRunTotalCount, 1);
|
|
||||||
Events.emit(Events.getSystemEvents().UserRunDoor, { user : this.client.user } );
|
|
||||||
|
|
||||||
this.client.term.write(ansi.resetScreen());
|
this.client.term.write(ansi.resetScreen());
|
||||||
|
|
||||||
const exeInfo = {
|
const exeInfo = {
|
||||||
|
@ -168,14 +165,10 @@ exports.getModule = class AbracadabraModule extends MenuModule {
|
||||||
node : this.client.node,
|
node : this.client.node,
|
||||||
};
|
};
|
||||||
|
|
||||||
const startTime = moment();
|
const doorTracking = trackDoorRunBegin(this.client, this.config.name);
|
||||||
|
|
||||||
this.doorInstance.run(exeInfo, () => {
|
this.doorInstance.run(exeInfo, () => {
|
||||||
const endTime = moment();
|
trackDoorRunEnd(doorTracking);
|
||||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
|
||||||
if(runTimeMinutes > 0) {
|
|
||||||
StatLog.incrementUserStat(this.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Try to clean up various settings such as scroll regions that may
|
// Try to clean up various settings such as scroll regions that may
|
||||||
|
|
|
@ -10,32 +10,29 @@ const moment = require('moment');
|
||||||
exports.trackDoorRunBegin = trackDoorRunBegin;
|
exports.trackDoorRunBegin = trackDoorRunBegin;
|
||||||
exports.trackDoorRunEnd = trackDoorRunEnd;
|
exports.trackDoorRunEnd = trackDoorRunEnd;
|
||||||
|
|
||||||
|
|
||||||
function trackDoorRunBegin(client, doorTag) {
|
function trackDoorRunBegin(client, doorTag) {
|
||||||
const startTime = moment();
|
const startTime = moment();
|
||||||
|
return { startTime, client, doorTag };
|
||||||
// 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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trackDoorRunEnd(trackInfo) {
|
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(diff.asMinutes());
|
||||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
|
||||||
if(runTimeMinutes > 0) {
|
if(runTimeMinutes > 0) {
|
||||||
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
||||||
|
|
||||||
|
const eventInfo = {
|
||||||
|
runTimeMinutes,
|
||||||
|
user : client.user,
|
||||||
|
doorTag : doorTag || 'unknown',
|
||||||
|
};
|
||||||
|
|
||||||
|
Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -54,8 +54,8 @@ module.exports = function systemEventUserLogInit(statLog) {
|
||||||
append(e, LogNames.SendMail, 1);
|
append(e, LogNames.SendMail, 1);
|
||||||
},
|
},
|
||||||
[ systemEvents.UserRunDoor ] : (e) => {
|
[ systemEvents.UserRunDoor ] : (e) => {
|
||||||
// :TODO: store door tag, else '-' ?
|
append(e, LogNames.RunDoor, e.doorTag);
|
||||||
append(e, LogNames.RunDoor, 1);
|
append(e, LogNames.RunDoorMinutes, e.runTimeMinutes);
|
||||||
},
|
},
|
||||||
[ systemEvents.UserSendNodeMsg ] : (e) => {
|
[ systemEvents.UserSendNodeMsg ] : (e) => {
|
||||||
append(e, LogNames.SendNodeMsg, e.global ? 'global' : 'direct');
|
append(e, LogNames.SendNodeMsg, e.global ? 'global' : 'direct');
|
||||||
|
|
|
@ -19,7 +19,7 @@ module.exports = {
|
||||||
UserDownload : 'codes.l33t.enigma.system.user_download', // { ..., files[ fileEntry, ...] }
|
UserDownload : 'codes.l33t.enigma.system.user_download', // { ..., files[ fileEntry, ...] }
|
||||||
UserPostMessage : 'codes.l33t.enigma.system.user_post_msg', // { ..., areaTag }
|
UserPostMessage : 'codes.l33t.enigma.system.user_post_msg', // { ..., areaTag }
|
||||||
UserSendMail : 'codes.l33t.enigma.system.user_send_mail', // { ... }
|
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 }
|
UserSendNodeMsg : 'codes.l33t.enigma.system.user_send_node_msg', // { ..., global }
|
||||||
UserStatSet : 'codes.l33t.enigma.system.user_stat_set', // { ..., statName, statValue }
|
UserStatSet : 'codes.l33t.enigma.system.user_stat_set', // { ..., statName, statValue }
|
||||||
UserStatIncrement : 'codes.l33t.enigma.system.user_stat_increment', // { ..., statName, statIncrementBy, statValue }
|
UserStatIncrement : 'codes.l33t.enigma.system.user_stat_increment', // { ..., statName, statIncrementBy, statValue }
|
||||||
|
|
|
@ -14,7 +14,8 @@ module.exports = {
|
||||||
DlFileBytes : 'dl_file_bytes', // value=total bytes
|
DlFileBytes : 'dl_file_bytes', // value=total bytes
|
||||||
PostMessage : 'post_msg', // value=areaTag
|
PostMessage : 'post_msg', // value=areaTag
|
||||||
SendMail : 'send_mail',
|
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
|
SendNodeMsg : 'send_node_msg', // value=global|direct
|
||||||
AchievementEarned : 'achievement_earned', // value=achievementTag
|
AchievementEarned : 'achievement_earned', // value=achievementTag
|
||||||
AchievementPointsEarned : 'achievement_pts_earned', // value=points earned
|
AchievementPointsEarned : 'achievement_pts_earned', // value=points earned
|
||||||
|
|
Loading…
Reference in New Issue