TopX mciMap standardized on "value" vs (propName, logName, etc.)

This commit is contained in:
Bryan Ashby 2019-01-20 21:57:31 -07:00
parent 34f0afc175
commit 18a7a79f14
2 changed files with 14 additions and 14 deletions

View File

@ -9,7 +9,6 @@ const { Errors } = require('./enig_error.js');
const UserDb = require('./database.js').dbs.user; const UserDb = require('./database.js').dbs.user;
const SysDb = require('./database.js').dbs.system; const SysDb = require('./database.js').dbs.system;
const User = require('./user.js'); const User = require('./user.js');
const stringFormat = require('./string_format.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -68,7 +67,7 @@ exports.getModule = class TopXModule extends MenuModule {
const type = o.type; const type = o.type;
switch(type) { switch(type) {
case 'userProp' : case 'userProp' :
if(!userPropValues.includes(o.propName)) { if(!userPropValues.includes(o.value)) {
return false; return false;
} }
// VM# must exist for this mci // VM# must exist for this mci
@ -78,7 +77,7 @@ exports.getModule = class TopXModule extends MenuModule {
break; break;
case 'userEventLog' : case 'userEventLog' :
if(!userLogValues.includes(o.logName)) { if(!userLogValues.includes(o.value)) {
return false; return false;
} }
// VM# must exist for this mci // VM# must exist for this mci
@ -122,7 +121,7 @@ exports.getModule = class TopXModule extends MenuModule {
return cb(Errors.UnexpectedState(`Failed to get view for MCI ${mciCode}`)); return cb(Errors.UnexpectedState(`Failed to get view for MCI ${mciCode}`));
} }
const type = this.config.mciMap[mciCode].type; const type = this.config.mciMap[mciCode].type;
switch(type) { switch(type) {
case 'userProp' : return this.populateTopXUserProp(listView, mciCode, cb); case 'userProp' : return this.populateTopXUserProp(listView, mciCode, cb);
case 'userEventLog' : return this.populateTopXUserEventLog(listView, mciCode, cb); case 'userEventLog' : return this.populateTopXUserEventLog(listView, mciCode, cb);
@ -148,9 +147,10 @@ exports.getModule = class TopXModule extends MenuModule {
} }
populateTopXUserEventLog(listView, mciCode, cb) { populateTopXUserEventLog(listView, mciCode, cb) {
const count = listView.dimens.height || 1; const mciMap = this.config.mciMap[mciCode];
const daysBack = this.config.mciMap[mciCode].daysBack; const count = listView.dimens.height || 1;
const shouldSum = _.get(this.config.mciMap[mciCode], 'sum', true); const daysBack = mciMap.daysBack;
const shouldSum = _.get(mciMap, 'sum', true);
const valueSql = shouldSum ? 'SUM(CAST(log_value AS INTEGER))' : 'COUNT()'; const valueSql = shouldSum ? 'SUM(CAST(log_value AS INTEGER))' : 'COUNT()';
const dateSql = daysBack ? `AND DATETIME(timestamp) >= DATETIME('now', '-${daysBack} days')` : ''; const dateSql = daysBack ? `AND DATETIME(timestamp) >= DATETIME('now', '-${daysBack} days')` : '';
@ -162,7 +162,7 @@ exports.getModule = class TopXModule extends MenuModule {
GROUP BY user_id GROUP BY user_id
ORDER BY value DESC ORDER BY value DESC
LIMIT ${count};`, LIMIT ${count};`,
[ this.config.mciMap[mciCode].logName ], [ mciMap.value ],
(err, rows) => { (err, rows) => {
if(err) { if(err) {
return cb(err); return cb(err);
@ -188,7 +188,7 @@ exports.getModule = class TopXModule extends MenuModule {
WHERE prop_name = ? WHERE prop_name = ?
ORDER BY value DESC ORDER BY value DESC
LIMIT ${count};`, LIMIT ${count};`,
[ this.config.mciMap[mciCode].propName ], [ this.config.mciMap[mciCode].value ],
(err, rows) => { (err, rows) => {
if(err) { if(err) {
return cb(err); return cb(err);

View File

@ -3,7 +3,7 @@ layout: page
title: TopX title: TopX
--- ---
## The TopX Module ## The TopX Module
The built in `top_x` module allows for displaying oldschool top user stats for the week, month, etc. Ops can configure what stat(s) are displayed and how far back in days the stats are considered. The built in `top_x` module allows for displaying oLDSKOOL (?!) top user stats for the week, month, etc. Ops can configure what stat(s) are displayed and how far back in days the stats are considered.
## Configuration ## Configuration
### Config Block ### Config Block
@ -21,14 +21,14 @@ The `mciMap` `config` block configures MCI code mapping to data sources. Current
##### User Event Log (userEventLog) ##### User Event Log (userEventLog)
When `type` is set to `userEventLog`, entries from the User Event Log can be counted (ie: individual instances of a particular log item) or summed in the case of log items that have numeric values. The default is to sum. When `type` is set to `userEventLog`, entries from the User Event Log can be counted (ie: individual instances of a particular log item) or summed in the case of log items that have numeric values. The default is to sum.
Some current User Event Log `logName` examples include `ul_files`, `dl_file_bytes`, or `achievement_earned`. See [user_log_name.js](/core/user_log_name.js) for additional information. Some current User Event Log `value` examples include `ul_files`, `dl_file_bytes`, or `achievement_earned`. See [user_log_name.js](/core/user_log_name.js) for additional information.
Example `userEventLog` entry: Example `userEventLog` entry:
```hjson ```hjson
mciMap: { mciMap: {
1: { // e.g.: %VM1 1: { // e.g.: %VM1
type: userEventLog type: userEventLog
logName: achievement_pts_earned // top achievement points earned value: achievement_pts_earned // top achievement points earned
sum: true // this is the default sum: true // this is the default
daysBack: 7 // omit daysBack for all-of-time daysBack: 7 // omit daysBack for all-of-time
} }
@ -36,14 +36,14 @@ mciMap: {
``` ```
#### User Properties (userProp) #### User Properties (userProp)
When `type` is set to `userProp`, data is collected from individual user's properties. For example a `propName` of `minutes_online_total_count`. See [user_property.js](/core/user_property.js) for more information. When `type` is set to `userProp`, data is collected from individual user's properties. For example a `value` of `minutes_online_total_count`. See [user_property.js](/core/user_property.js) for more information.
Example `userProp` entry: Example `userProp` entry:
```hjson ```hjson
mciMap: { mciMap: {
2: { // e.g.: %VM2 2: { // e.g.: %VM2
type: userProp type: userProp
propName: minutes_online_total_count // top users by minutes spent on the board value: minutes_online_total_count // top users by minutes spent on the board
} }
} }
``` ```