5 var d0 = new Date('2016-08-01T00:00:00Z');
6 var d1 = new Date('2016-09-01T00:00:00Z');
7 var d2 = new Date('2016-10-01T00:00:00Z');
9 // var horizonTimestamp = Date.now() - 86400000 * 31;
11 function getStat(tag, start, end) {
12 var e = db.tagsynonyms.find({ synonym: tag }).map(function(f) {
15 var bases = [tag].concat(e);
16 var synonyms = db.tagsynonyms.find({ name: { $in: bases } }).map(function(f) {
20 synonyms.forEach(function(s) {
21 s.forEach(function(q) {
27 var troupeIds = db.troupes.find({ tags: { $in: bases } }, { _id: 1 }).map(function(f) {
31 var aggr = db.chatmessages.aggregate([
35 $gt: createIdForTimestampString(start),
36 $lt: createIdForTimestampString(end)
40 toTroupeId: { $in: troupeIds },
47 sent: { $type: 'date' }
55 userIds: { $addToSet: '$fromUserId' },
56 roomIds: { $addToSet: '$toTroupeId' },
63 userIds: { $size: '$userIds' },
64 roomIds: { $size: '$roomIds' },
70 return aggr.toArray()[0];
97 return f.toLowerCase();
100 print(['tag', 'p1-users', 'p1-rooms', 'p1-msgs', 'p0-users', 'p0-rooms', 'p0-count'].join(','));
102 tags.forEach(function(tag) {
103 var s = getStat(tag, d1, d2);
104 var t = getStat(tag, d0, d1);
105 print([tag, s.userIds, s.roomIds, s.count, t.userIds, t.roomIds, t.count].join(','));