3 var start = new Date('2014-09-01T00:00:00Z');
5 var a = db.chatmessages.aggregate([
6 { $match: { sent: { $gt: start } } },
8 _id: { m: { $month: "$sent" }, y: { $year: "$sent" }, t: "$toTroupeId" },
14 var groupings = a.toArray();
16 var troupeIds = groupings.map(function(f) { return f._id.t; } );
18 var troupes = db.troupes.find({ _id: { $in: troupeIds } }, { uri: 1, githubType: 1, security: 1 }).toArray();
20 var troupesIndexed = troupes.reduce(function(memo, f) {
25 function addValue(mString, hash, key, value) {
26 if (!hash[mString]) hash[mString] = {};
27 var dateBucket = hash[mString];
28 if (!dateBucket[key]) {
29 dateBucket[key] = value;
31 dateBucket[key] += value;
35 var chatsPerRoomType = {};
39 groupings.forEach(function(group) {
40 var troupeId = group._id.t;
41 var month = group._id.m;
42 var year = group._id.y;
43 var troupe = troupesIndexed[troupeId];
46 var mString = (month > 9 ? "" + month : "0" + month) + "-" + year;
48 addValue(mString, githubTypes, troupe.githubType, 1);
49 addValue(mString, chatsPerRoomType, troupe.githubType, group.s);
52 if(troupe.githubType === 'ONETOONE') {
53 otoPPCategory = 'ONETOONE';
55 otoPPCategory = troupe.security === 'PUBLIC' ? 'PUBLIC' : 'PRIVATE';
58 addValue(mString, rooms, otoPPCategory, 1);
59 addValue(mString, otoPP, otoPPCategory, group.s);
62 print("Chats per Room Type");
63 printjson(chatsPerRoomType);
65 print("Chats per github type");
66 printjson(githubTypes);
68 print("Unique rooms per month:");
71 print("Total per room:");