mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-02 16:21:01 -04:00
Added a script to count spoken language usage.
This commit is contained in:
parent
158560f42d
commit
d3707306cc
1 changed files with 36 additions and 0 deletions
36
scripts/analytics/mongodb/queries/spokenLanguageUsage.js
Normal file
36
scripts/analytics/mongodb/queries/spokenLanguageUsage.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Print out spoken language usage based on signed-in user data
|
||||
|
||||
// Usage:
|
||||
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
|
||||
|
||||
var total = 0;
|
||||
var languages = {};
|
||||
//var startDate = new ISODate("2014-12-01T00:00:00.000Z");
|
||||
var cursor = db['users'].aggregate(
|
||||
[
|
||||
{ $match : {
|
||||
//$and: [{codeLanguage: {$exists: true}}, {created : { $gte: startDate}}]
|
||||
anonymous: false
|
||||
}
|
||||
},
|
||||
{
|
||||
$group : {
|
||||
_id: "$preferredLanguage",
|
||||
total: {$sum: 1}
|
||||
}
|
||||
},
|
||||
{ $sort : { total : -1} }
|
||||
]);
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
var myDoc = cursor.next();
|
||||
total += myDoc.total;
|
||||
var lang = myDoc._id || 'en-US';
|
||||
if (!languages[myDoc._id])
|
||||
languages[myDoc._id] = 0
|
||||
languages[myDoc._id] += myDoc.total
|
||||
}
|
||||
print("Total registered users with spoken languages", total);
|
||||
for (key in languages) {
|
||||
print(languages[key] + "\t" + (languages[key] / total * 100).toFixed(2) + "%\t" + key);
|
||||
}
|
Loading…
Add table
Reference in a new issue