From 6cce013187df1fcaff85ce862a21275e377f52cc Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Tue, 27 Nov 2018 21:21:00 -0700 Subject: [PATCH] + MCI: PT - total messages posted today (non-private) + MCI: TP - total messages/posts on system (non-private, includes imports, only counts *current*, not all of time) * Move some stats to startup() calls * Fix some DATE() comparisons in SQL to use 'localtime' as our timestamps include TZ * Update luciano_blocktronics SYSSTAT to show more info --- art/themes/luciano_blocktronics/SYSSTAT.ANS | Bin 2877 -> 3066 bytes art/themes/luciano_blocktronics/theme.hjson | 7 ++-- core/bbs.js | 14 ++------ core/file_base_area.js | 20 ++++++++++- core/fse.js | 6 +++- core/message.js | 8 ++++- core/message_area.js | 36 ++++++++++++++++++++ core/msg_area_post_fse.js | 2 +- core/predefined_mci.js | 16 ++++++--- core/scanner_tossers/ftn_bso.js | 10 ++++-- core/stat_log.js | 2 +- core/system_property.js | 3 ++ 12 files changed, 98 insertions(+), 26 deletions(-) diff --git a/art/themes/luciano_blocktronics/SYSSTAT.ANS b/art/themes/luciano_blocktronics/SYSSTAT.ANS index 19a3d39e0b11353a7c8b7415742ea3870a3c6fcb..a76e3bd654c45d46566905990ca88b74c0b5e868 100644 GIT binary patch delta 493 zcmdlh_Dg(1qn~uNv3ag^w3#!IVU(-j3KTHR&6JKdum*D7eH}sE)ljZNS!z*nW_})* zf&y3@h%(Gob@DR=DgYW{XgRUhLLVXpF%HaD4f8YN0`q}N41g9H<|+UIM33dfi{X+G zz+stxHGILX*G745;XQ?`em;ps5>u|VofRuuq zJDHDDO~@D&PGB?c-?^`FN8vu#lo7{?#YteDgfF0f*t?> delta 261 zcmew*zE^BQBM+B?f^@X8d9HM{k?F+q7RY?V$!3hUjoHuJR6|=Gf zb*Vb}8BSi#K84@dELSzm$4ENb0BDk-<>V-icu}xYAkW&^Aa^6s9FUapWC2cBRxoFB zBd5sZX`F_W_jAZie#U7vIf+wI2dr2D2q4N$oq<}+a+3>6q2?$kSb?QfgPlz#@8vX| zY{H?!WNbKDic5t>I@%QIMlLn6lFZyxn0lyk=Mb~Wd0cuxH5Sg3`M8fUUFDj5javl( DX{|*^ diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index a5100e6b..330075ff 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -127,15 +127,16 @@ mainMenuSystemStats: { mci: { BN1: { width: 17 } - VL2: { width: 17 } + VN2: { width: 17 } OS3: { width: 33 } SC4: { width: 33 } - DT5: { width: 33 } - CT6: { width: 33 } AN7: { width: 6 } ND8: { width: 6 } TC9: { width: 6 } TT11: { width: 6 } + PT12: { width: 6 } + TP13: { width: 6 } + NV14: { width: 17 } } } diff --git a/core/bbs.js b/core/bbs.js index c154f285..4d371fb3 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -263,17 +263,6 @@ function initialize(cb) { } ); }, - function initFileAreaStats(callback) { - const getAreaStats = require('./file_base_area.js').getAreaStats; - getAreaStats( (err, stats) => { - if(!err) { - const StatLog = require('./stat_log.js'); - StatLog.setNonPersistentSystemStat(SysProps.FileBaseAreaStats, stats); - } - - return callback(null); - }); - }, function initCallsToday(callback) { const StatLog = require('./stat_log.js'); const filter = { @@ -289,6 +278,9 @@ function initialize(cb) { return callback(null); }); }, + function initMessageStats(callback) { + return require('./message_area.js').startup(callback); + }, function initMCI(callback) { return require('./predefined_mci.js').init(callback); }, diff --git a/core/file_base_area.js b/core/file_base_area.js index f699a543..293ab265 100644 --- a/core/file_base_area.js +++ b/core/file_base_area.js @@ -57,7 +57,25 @@ const WellKnownAreaTags = exports.WellKnownAreaTags = { }; function startup(cb) { - return cleanUpTempSessionItems(cb); + async.series( + [ + (callback) => { + return cleanUpTempSessionItems(callback); + }, + (callback) => { + getAreaStats( (err, stats) => { + if(!err) { + StatLog.setNonPersistentSystemStat(SysProps.FileBaseAreaStats, stats); + } + + return callback(null); + }); + } + ], + err => { + return cb(err); + } + ); } function isInternalArea(areaTag) { diff --git a/core/fse.js b/core/fse.js index 9ecf3bdd..d294f10b 100644 --- a/core/fse.js +++ b/core/fse.js @@ -25,6 +25,7 @@ const Config = require('./config.js').get; const { getAddressedToInfo } = require('./mail_util.js'); const Events = require('./events.js'); const UserProps = require('./user_property.js'); +const SysProps = require('./system_property.js'); // deps const async = require('async'); @@ -470,7 +471,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul ); } - updateUserStats(cb) { + updateUserAndSystemStats(cb) { if(Message.isPrivateAreaTag(this.message.areaTag)) { Events.emit(Events.getSystemEvents().UserSendMail, { user : this.client.user }); if(cb) { @@ -480,6 +481,9 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul } Events.emit(Events.getSystemEvents().UserPostMessage, { user : this.client.user, areaTag : this.message.areaTag }); + + StatLog.incrementNonPersistentSystemStat(SysProps.MessageTotalCount, 1); + StatLog.incrementNonPersistentSystemStat(SysProps.MessagesToday, 1); return StatLog.incrementUserStat(this.client.user, UserProps.MessagePostCount, 1, cb); } diff --git a/core/message.js b/core/message.js index 768cd116..df0804d5 100644 --- a/core/message.js +++ b/core/message.js @@ -239,7 +239,10 @@ module.exports = class Message { filter.toUserName filter.fromUserName filter.replyToMesageId - filter.newerThanTimestamp + + filter.newerThanTimestamp - may not be used with |date| + filter.date - moment object - may not be used with |newerThanTimestamp| + filter.newerThanMessageId filter.areaTag - note if you want by conf, send in all areas for a conf *filter.metaTuples - {category, name, value} @@ -356,7 +359,10 @@ module.exports = class Message { }); if(_.isString(filter.newerThanTimestamp) && filter.newerThanTimestamp.length > 0) { + // :TODO: should be using "localtime" here? appendWhereClause(`DATETIME(m.modified_timestamp) > DATETIME("${filter.newerThanTimestamp}", "+1 seconds")`); + } else if(moment.isMoment(filter.date)) { + appendWhereClause(`DATE(m.modified_timestamp, "localtime") = DATE("${filter.date.format('YYYY-MM-DD')}")`); } if(_.isNumber(filter.newerThanMessageId)) { diff --git a/core/message_area.js b/core/message_area.js index a465b235..7f4993ec 100644 --- a/core/message_area.js +++ b/core/message_area.js @@ -9,12 +9,17 @@ const Log = require('./logger.js').log; const msgNetRecord = require('./msg_network.js').recordMessage; const sortAreasOrConfs = require('./conf_area_util.js').sortAreasOrConfs; const UserProps = require('./user_property.js'); +const StatLog = require('./stat_log.js'); +const SysProps = require('./system_property.js'); // deps const async = require('async'); const _ = require('lodash'); const assert = require('assert'); +const moment = require('moment'); +exports.startup = startup; +exports.shutdown = shutdown; exports.getAvailableMessageConferences = getAvailableMessageConferences; exports.getSortedAvailMessageConferences = getSortedAvailMessageConferences; exports.getAvailableMessageAreasByConfTag = getAvailableMessageAreasByConfTag; @@ -35,6 +40,37 @@ exports.updateMessageAreaLastReadId = updateMessageAreaLastReadId; exports.persistMessage = persistMessage; exports.trimMessageAreasScheduledEvent = trimMessageAreasScheduledEvent; +function startup(cb) { + // by default, private messages are NOT included + async.series( + [ + (callback) => { + Message.findMessages( { resultType : 'count' }, (err, count) => { + if(count) { + StatLog.setNonPersistentSystemStat(SysProps.MessageTotalCount, count); + } + return callback(err); + }); + }, + (callback) => { + Message.findMessages( { resultType : 'count', date : moment() }, (err, count) => { + if(count) { + StatLog.setNonPersistentSystemStat(SysProps.MessagesToday, count); + } + return callback(err); + }); + } + ], + err => { + return cb(err); + } + ); +} + +function shutdown(cb) { + return cb(null); +} + function getAvailableMessageConferences(client, options) { options = options || { includeSystemInternal : false }; diff --git a/core/msg_area_post_fse.js b/core/msg_area_post_fse.js index 123ce13c..613cee04 100644 --- a/core/msg_area_post_fse.js +++ b/core/msg_area_post_fse.js @@ -38,7 +38,7 @@ exports.getModule = class AreaPostFSEModule extends FullScreenEditorModule { return persistMessage(msg, callback); }, function updateStats(callback) { - self.updateUserStats(callback); + self.updateUserAndSystemStats(callback); } ], function complete(err) { diff --git a/core/predefined_mci.js b/core/predefined_mci.js index 39310559..76b34fd5 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -155,13 +155,14 @@ const PREDEFINED_MCI_GENERATORS = { // // Date/Time // - // :TODO: change to CD for 'Current Date' DT : function date(client) { return moment().format(client.currentTheme.helpers.getDateFormat()); }, CT : function time(client) { return moment().format(client.currentTheme.helpers.getTimeFormat()) ;}, // // OS/System Info // + // https://github.com/nodejs/node-v0.x-archive/issues/25769 + // OS : function operatingSystem() { return { linux : 'Linux', @@ -169,6 +170,9 @@ const PREDEFINED_MCI_GENERATORS = { win32 : 'Windows', sunos : 'SunOS', freebsd : 'FreeBSD', + android : 'Android', + openbsd : 'OpenBSD', + aix : 'IBM AIX', }[os.platform()] || os.type(); }, @@ -227,14 +231,16 @@ const PREDEFINED_MCI_GENERATORS = { const totalBytes = parseInt(_.get(areaStats, 'totalBytes', 0)); return formatByteSize(totalBytes, true); // true=withAbbr }, + PT : function messagesPostedToday() { // Obv/2 + return sysStatAsString(SysProps.MessagesToday, 0); + }, + TP : function totalMessagesOnSystem() { // Obv/2 + return sysStatAsString(SysProps.MessageTotalCount, 0); + }, - // :TODO: PT - Messages posted *today* (Obv/2) - // -> Include FTN/etc. // :TODO: NT - New users today (Obv/2) // :TODO: FT - Files uploaded/added *today* (Obv/2) // :TODO: DD - Files downloaded *today* (iNiQUiTY) - // :TODO: TP - total message/posts on the system (Obv/2) - // -> Include FTN/etc. // :TODO: LC - name of last caller to system (Obv/2) // :TODO: TZ - Average *system* post/call ratio (iNiQUiTY) diff --git a/core/scanner_tossers/ftn_bso.js b/core/scanner_tossers/ftn_bso.js index 3292588d..36f0d769 100644 --- a/core/scanner_tossers/ftn_bso.js +++ b/core/scanner_tossers/ftn_bso.js @@ -21,6 +21,8 @@ const copyFileWithCollisionHandling = require('../file_util.js').copyFileWit const getAreaStorageDirectoryByTag = require('../file_base_area.js').getAreaStorageDirectoryByTag; const isValidStorageTag = require('../file_base_area.js').isValidStorageTag; const User = require('../user.js'); +const StatLog = require('../stat_log.js'); +const SysProps = require('../system_property.js'); // deps const moment = require('moment'); @@ -1261,12 +1263,12 @@ function FTNMessageScanTossModule() { } } - // we do this after such that error cases can be preseved above + // we do this after such that error cases can be preserved above if(lookupName !== message.toUserName) { message.toUserName = localUserName; } - // set the meta information - used elsehwere for retrieval + // set the meta information - used elsewhere for retrieval message.meta.System[Message.SystemMetaNames.LocalToUserID] = localToUserId; return callback(null); }); @@ -1277,6 +1279,10 @@ function FTNMessageScanTossModule() { // save to disc message.persist(err => { + if(!message.isPrivate()) { + StatLog.incrementNonPersistentSystemStat(SysProps.MessageTotalCount, 1); + StatLog.incrementNonPersistentSystemStat(SysProps.MessagesToday, 1); + } return callback(err); }); } diff --git a/core/stat_log.js b/core/stat_log.js index 805198bd..b97ea417 100644 --- a/core/stat_log.js +++ b/core/stat_log.js @@ -253,7 +253,7 @@ class StatLog { if(filter.date) { filter.date = moment(filter.date); - sql += ` AND DATE(timestamp) = DATE("${filter.date.format('YYYY-MM-DD')}")`; + sql += ` AND DATE(timestamp, "localtime") = DATE("${filter.date.format('YYYY-MM-DD')}")`; } if('count' !== filter.resultType) { diff --git a/core/system_property.js b/core/system_property.js index 52830a06..28250f20 100644 --- a/core/system_property.js +++ b/core/system_property.js @@ -15,6 +15,9 @@ module.exports = { FileUlTotalCount : 'ul_total_count', FileUlTotalBytes : 'ul_total_bytes', + MessageTotalCount : 'message_post_total_count', // total non-private messages on the system; non-persistent + MessagesToday : 'message_post_today', // non-private messages posted/imported today; non-persistent + // begin +op non-persistent... SysOpUsername : 'sysop_username', SysOpRealName : 'sysop_real_name',