mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Analytics mongdb queries
This commit is contained in:
parent
30c1b7b31a
commit
604bc48506
4 changed files with 168 additions and 0 deletions
26
scripts/analytics/mongodb/queries/GemsPerDay.js
Normal file
26
scripts/analytics/mongodb/queries/GemsPerDay.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Print out gem counts bucketed by day and amount
|
||||
// NOTE: created is a string and not an ISODate in the database
|
||||
|
||||
var match={
|
||||
"$match" : {
|
||||
"stripe.subscriptionID" : { "$exists" : false }
|
||||
}
|
||||
};
|
||||
var proj0 = {"$project": {
|
||||
"amount": 1,
|
||||
"created": { "$concat": [{"$substr" : ["$created", 0, 4]}, "-", {"$substr" : ["$created", 5, 2]}, "-", {"$substr" : ["$created", 8, 2]}]}
|
||||
}
|
||||
};
|
||||
|
||||
var group={"$group" : {
|
||||
"_id" : {
|
||||
"m" : "$amount",
|
||||
"d" : "$created"
|
||||
},
|
||||
"count" : {
|
||||
"$sum" : 1
|
||||
}
|
||||
}
|
||||
};
|
||||
var sort = {$sort: { "_id.d" : -1}};
|
||||
db.payments.aggregate(match, proj0, group, sort).result.forEach( function (myDoc) { print({day: myDoc._id.d, amount: myDoc._id.m, count: myDoc.count}) })
|
29
scripts/analytics/mongodb/queries/SignupConversions.js
Normal file
29
scripts/analytics/mongodb/queries/SignupConversions.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Print out signup conversions since a start Date
|
||||
|
||||
var started = finished = 0.0
|
||||
var startDate = new ISODate("2014-12-07T00:00:00.000Z")
|
||||
db['analytics.log.events'].aggregate(
|
||||
[
|
||||
{ $match :
|
||||
{ $and: [
|
||||
{created : { $gte: startDate}},
|
||||
{$or: [ {"event" : 'Started Signup'}, {"event" : 'Finished Signup'}]}
|
||||
]}
|
||||
},
|
||||
{
|
||||
$group : {
|
||||
_id: "$event",
|
||||
total: {$sum: 1}
|
||||
}
|
||||
},
|
||||
{ $sort : { total : -1} }
|
||||
]
|
||||
).result.forEach( function (myDoc) {
|
||||
//print(myDoc)
|
||||
if (myDoc._id === "Started Signup")
|
||||
started += myDoc.total;
|
||||
else
|
||||
finished += myDoc.total;
|
||||
})
|
||||
print("Signups", started, finished);
|
||||
print("Signup Conversion:", (finished / started * 100), "%");
|
85
scripts/analytics/mongodb/queries/SignupsPerDay.js
Normal file
85
scripts/analytics/mongodb/queries/SignupsPerDay.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
// Print out signup conversions per day
|
||||
|
||||
var match={
|
||||
"$match" : {
|
||||
$or: [ {"event" : 'Started Signup'}, {"event" : 'Finished Signup'}]
|
||||
}
|
||||
};
|
||||
|
||||
proj1={"$project" : {
|
||||
"_id" : 0,
|
||||
"created" : 1,
|
||||
"event" : 1,
|
||||
"h" : {
|
||||
"$hour" : "$created"
|
||||
},
|
||||
"m" : {
|
||||
"$minute" : "$created"
|
||||
},
|
||||
"s" : {
|
||||
"$second" : "$created"
|
||||
},
|
||||
"ml" : {
|
||||
"$millisecond" : "$created"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var proj2={"$project" : {
|
||||
"_id" : 0,
|
||||
"event" : 1,
|
||||
"created" : {
|
||||
"$subtract" : [
|
||||
"$created",
|
||||
{
|
||||
"$add" : [
|
||||
"$ml",
|
||||
{
|
||||
"$multiply" : [
|
||||
"$s",
|
||||
1000
|
||||
]
|
||||
},
|
||||
{
|
||||
"$multiply" : [
|
||||
"$m",
|
||||
60,
|
||||
1000
|
||||
]
|
||||
},
|
||||
{
|
||||
"$multiply" : [
|
||||
"$h",
|
||||
60,
|
||||
60,
|
||||
1000
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
var group={"$group" : {
|
||||
"_id" : {
|
||||
"m" : "$event",
|
||||
"d" : "$created"
|
||||
},
|
||||
"count" : {
|
||||
"$sum" : 1
|
||||
}
|
||||
}
|
||||
};
|
||||
var conversionsPerDay = {};
|
||||
var sort = {$sort: { "_id.d" : -1}};
|
||||
db['analytics.log.events'].aggregate(match, proj1, proj2, group, sort).result.forEach( function (myDoc) {
|
||||
// print({day: myDoc._id.d, amount: myDoc._id.m, count: myDoc.count})
|
||||
if (!conversionsPerDay[myDoc._id.d])
|
||||
conversionsPerDay[myDoc._id.d] = {}
|
||||
conversionsPerDay[myDoc._id.d][myDoc._id.m] = myDoc.count;
|
||||
})
|
||||
for (key in conversionsPerDay) {
|
||||
print(key, conversionsPerDay[key]['Started Signup'], conversionsPerDay[key]['Finished Signup'], conversionsPerDay[key]['Finished Signup'] / conversionsPerDay[key]['Started Signup']);
|
||||
// print("Signup Conversion:", (finished / started * 100), "%");
|
||||
}
|
28
scripts/analytics/mongodb/queries/SubscriptionsPerDay.js
Normal file
28
scripts/analytics/mongodb/queries/SubscriptionsPerDay.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Print out subscription counts bucketed by day and amount
|
||||
// NOTE: created is a string and not an ISODate in the database
|
||||
|
||||
var match={
|
||||
"$match" : {
|
||||
"stripe.subscriptionID" : { "$exists" : true }
|
||||
}
|
||||
};
|
||||
var proj0 = {"$project": {
|
||||
"amount": 1,
|
||||
"created": { "$concat": [{"$substr" : ["$created", 0, 4]}, "-", {"$substr" : ["$created", 5, 2]}, "-", {"$substr" : ["$created", 8, 2]}]}
|
||||
}
|
||||
};
|
||||
var group={"$group" : {
|
||||
"_id" : {
|
||||
"m" : "$amount",
|
||||
"d" : "$created"
|
||||
},
|
||||
"count" : {
|
||||
"$sum" : 1
|
||||
}
|
||||
}
|
||||
};
|
||||
var sort = {$sort: { "_id.d" : -1}};
|
||||
//db.payments.aggregate(match, proj0, proj1, proj2, group)
|
||||
db.payments.aggregate(match, proj0, group, sort).result.forEach( function (myDoc) { print({day: myDoc._id.d, amount: myDoc._id.m, count: myDoc.count}) })
|
||||
//db.payments.aggregate(match)
|
||||
//db.payments.find()
|
Loading…
Reference in a new issue