Add a few analytics scripts.

This commit is contained in:
Nick Winter 2015-09-18 05:02:18 -07:00
parent 7a56ecfe4d
commit b3f2b6d38a
3 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,10 @@
// Finds all email addresses of users, normalizes, and produces SHA1 hashes.
// Run while piping output to user_emails.txt.
// Then run python email-sha1s.py to get user_sha1s.txt.
var normalizedEmails = [];
var usersWithEmails = db.users.find({emailLower: {$exists: true}}, {emailLower: 1}).forEach(function(u) {
if(u.emailLower && u.emailLower.trim().length)
normalizedEmails.push(u.emailLower.trim().toLowerCase().replace('googlemail', 'gmail').replace(/\.(?=.*@)/g, '').replace(/\+.*@/g, '@'));
});
normalizedEmails.forEach(function(e) { print(e); });

View file

@ -0,0 +1,10 @@
from __future__ import with_statement
import hashlib
with open("user_emails.txt", "r") as f:
emails = f.read().strip().split('\n')
sha1s = [hashlib.sha1(e).hexdigest() for e in emails]
with open("user_sha1s.txt", "w") as f:
f.write("\n".join(sha1s) + "\n")

View file

@ -0,0 +1,24 @@
// Finds all human ladder sessions for given usernames and grab the code per player.
var usernames = ['Nick'];
usernames = usernames.map(function(u) { return u.toLowerCase(); });
var levelID = 'ace-of-coders';
usernames.sort(Math.random);
var users = db.users.find({nameLower: {$in: usernames}, anonymous: false}).toArray();
var userIDs = [];
for (var userIndex = 0; userIndex < users.length; ++userIndex) {
userIDs.push('' + users[userIndex]._id);
}
var sessions = db.level.sessions.find({creator: {$in: userIDs}, levelID: levelID, team: 'humans'}).toArray();
var userCode = {};
for (var i = 0; i < sessions.length; ++i) {
var session = sessions[i];
if (!session) continue;
if (!session.code || !session.levelName) continue;
userCode[session.creatorName] = session.code['hero-placeholder'].plan;
//var anonymizedUsername = 'user' + userIDs.indexOf(session.creator);
}
for (var username in userCode) {
print(username + "\n" + userCode[username] + "\n\n----------------------\n");
}