mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
Update level played before sub script
This commit is contained in:
parent
a6043ca1be
commit
35cf7afb8d
1 changed files with 39 additions and 33 deletions
|
@ -5,8 +5,11 @@
|
||||||
// Usage restricted to HoC Dates:
|
// Usage restricted to HoC Dates:
|
||||||
// mongo <address>:<port>/<database> -eval "var startDate='2014-12-08T00:00:00.000Z', endDate='2014-12-14T00:00:00.000Z';" <script file> -u <username> -p <password>
|
// mongo <address>:<port>/<database> -eval "var startDate='2014-12-08T00:00:00.000Z', endDate='2014-12-14T00:00:00.000Z';" <script file> -u <username> -p <password>
|
||||||
|
|
||||||
|
// TODO: query against _id instead of created
|
||||||
// TODO: Must be a better way to query for this data all at once.
|
// TODO: Must be a better way to query for this data all at once.
|
||||||
|
|
||||||
|
var startTime = new Date();
|
||||||
|
|
||||||
var lastLevelCompleted = {};
|
var lastLevelCompleted = {};
|
||||||
var paymentsCursor;
|
var paymentsCursor;
|
||||||
|
|
||||||
|
@ -20,49 +23,52 @@ if (typeof startDate !== "undefined" && startDate !== null && typeof endDate !==
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
print("No date range specified.");
|
print("No date range specified");
|
||||||
paymentsCursor = db.payments.find({"stripe.subscriptionID" : { "$exists" : true }});
|
paymentsCursor = db.payments.find({"stripe.subscriptionID": { "$exists" : true }});
|
||||||
}
|
}
|
||||||
|
|
||||||
while (paymentsCursor.hasNext()) {
|
while (paymentsCursor.hasNext()) {
|
||||||
var doc = paymentsCursor.next();
|
var doc = paymentsCursor.next();
|
||||||
var ID = doc._id;
|
var purchaseDate = doc.created;
|
||||||
var purchaseDate = doc.created;
|
var user = doc.purchaser.valueOf();
|
||||||
|
|
||||||
// Find last level session completed
|
// print("Processing purchase on " + purchaseDate + " for " + user);
|
||||||
var levelSessionCursor = db['level.sessions'].find({
|
|
||||||
$and: [{"state.complete" : true}, {creator : doc.purchaser.valueOf()}, {changed: {$lt: ISODate(purchaseDate)}}]
|
|
||||||
}).sort({created: -1});
|
|
||||||
if (levelSessionCursor.hasNext()) {
|
|
||||||
var lastLevelSessionCompleted = levelSessionCursor.next();
|
|
||||||
|
|
||||||
// Find last level completed
|
// Find last level session completed
|
||||||
var levelCursor = db.levels.find({"original" : ObjectId(lastLevelSessionCompleted.level.original), "version.isLatestMajor": true, "version.isLatestMinor": true})
|
var levelSessionCursor = db['level.sessions'].find({
|
||||||
if (levelCursor.hasNext()) {
|
$and: [{"state.complete" : true}, {creator : user}, {changed: {$lt: ISODate(purchaseDate)}}]
|
||||||
var lastLevel = levelCursor.next();
|
}).sort({created: -1});
|
||||||
if (!lastLevelCompleted[lastLevel.name])
|
if (levelSessionCursor.hasNext()) {
|
||||||
lastLevelCompleted[lastLevel.name] = 0;
|
var lastLevelSessionCompleted = levelSessionCursor.next();
|
||||||
lastLevelCompleted[lastLevel.name]++;
|
|
||||||
}
|
// Find last level completed
|
||||||
else {
|
var levelCursor = db.levels.find({"original" : ObjectId(lastLevelSessionCompleted.level.original), "version.isLatestMajor": true, "version.isLatestMinor": true})
|
||||||
if (!lastLevelCompleted['unknown'])
|
if (levelCursor.hasNext()) {
|
||||||
lastLevelCompleted['unknown'] = 0;
|
var lastLevel = levelCursor.next();
|
||||||
lastLevelCompleted['unknown']++;
|
if (!lastLevelCompleted[lastLevel.name]) lastLevelCompleted[lastLevel.name] = 0;
|
||||||
}
|
lastLevelCompleted[lastLevel.name]++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!lastLevelCompleted['unknown'])
|
if (!lastLevelCompleted['unknown']) lastLevelCompleted['unknown'] = 0;
|
||||||
lastLevelCompleted['unknown'] = 0;
|
lastLevelCompleted['unknown']++;
|
||||||
lastLevelCompleted['unknown']++;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!lastLevelCompleted['unknown']) lastLevelCompleted['unknown'] = 0;
|
||||||
|
lastLevelCompleted['unknown']++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort descending count and print
|
// Sort descending count and print
|
||||||
var sorted = [];
|
var sorted = [];
|
||||||
|
var total = 0;
|
||||||
for (key in lastLevelCompleted) {
|
for (key in lastLevelCompleted) {
|
||||||
sorted.push({name: key, count: lastLevelCompleted[key]});
|
sorted.push({name: key, count: lastLevelCompleted[key]});
|
||||||
|
total += lastLevelCompleted[key];
|
||||||
}
|
}
|
||||||
sorted.sort(function(a,b) { return b.count - a.count});
|
sorted.sort(function(a,b) { return b.count - a.count});
|
||||||
for (var i = 0; i < sorted.length; i++) {
|
for (var i = 0; i < sorted.length; i++) {
|
||||||
print(sorted[i].count + "\t" + sorted[i].name);
|
print(sorted[i].count + "\t" + (sorted[i].count / total * 100).toFixed(2) + "%\t" + sorted[i].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("Runtime: " + (new Date() - startTime) + "ms");
|
||||||
|
|
Loading…
Reference in a new issue