codecombat/scripts/analytics/mongodb/queries/CodeLanguageUsage.js

35 lines
941 B
JavaScript
Raw Normal View History

2014-12-15 16:53:08 -05:00
// Print out code language usage based on level session data
2014-12-24 14:09:54 -05:00
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
2014-12-15 16:53:08 -05:00
var total = 0;
var languages = {};
var startDate = new ISODate("2014-12-01T00:00:00.000Z")
2014-12-24 14:09:54 -05:00
var cursor = db['level.sessions'].aggregate(
2014-12-15 16:53:08 -05:00
[
{ $match : {
//$and: [{codeLanguage: {$exists: true}}, {created : { $gte: startDate}}]
codeLanguage: {$exists: true}
}
},
{
$group : {
_id: "$codeLanguage",
total: {$sum: 1}
}
},
{ $sort : { total : -1} }
2014-12-24 14:09:54 -05:00
]);
while (cursor.hasNext()) {
var myDoc = cursor.next();
total += myDoc.total;
if (!languages[myDoc._id])
languages[myDoc._id] = 0
languages[myDoc._id] += myDoc.total
}
2014-12-15 16:53:08 -05:00
print("Total sessions with code languages", total);
for (key in languages) {
2014-12-24 14:09:54 -05:00
print(key + "\t" + languages[key] + "\t" + (languages[key] / total * 100).toFixed(2) + "%");
2014-12-15 16:53:08 -05:00
}