Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
result_1 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$count" : "total_rows"
}
])
for i in result_1:
print(i)
result_2 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$match" : {
"checkout_price" : {
"$gt" : 130, "$lt" : 140
}
}
},
## stage 3
{
"$count" : "total_rows"
}
])
for i in result_2:
print(i)
result_3 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$group" : { "_id" : 0,
"average_checkout_price" : {
"$avg" : "$checkout_price"
}
}
}
])
for i in result_3:
print(i)
result_4 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$group" : { "_id" : 0,
"average_checkout_price" : {
"$avg" : "$checkout_price"
},
"total_checkout_price" : {
"$sum" : "$checkout_price"
}
}
}
])
for i in result_4:
print(i)
result_5 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$group" : { "_id" : "$homepage_featured" }
}
])
for i in result_5:
print(i)
result_6 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$group" : { "_id" : "$homepage_featured",
"average_checkout_price" : {
"$avg" : "$checkout_price"
}
}
}
])
for i in result_6:
print(i)
result_7 = weekly_demand_collection.aggregate([
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$group" : {
"_id" : {
"is_email_promotion" : "$emailer_for_promotion",
"is_homepage_featured" : "$homepage_featured"
},
"average_checkout_price" : {
"$avg" : "$checkout_price"
}
}
}
])
for i in result_7:
print(i)
result_8 = weekly_demand_collection.aggregate([
## stage 1
{
"$bucket" : {
"groupBy" : "$checkout_price",
"boundaries" : [ 0, 50, 100, 200, 400, 600, 800, 1000 ],
"default" : "Other",
"output" : {
"count" : { "$sum" : 1},
"average" : { "$avg" :"$num_orders" }
}
}
}
])
for i in result_8:
print(i)
result_9 = weekly_demand_collection.aggregate([
## stage 1
{
"$facet" : {
"average_checkout_price" : [
## stage 1
{
"$match" : {
"center_id" : {
"$eq" : 11
}
}
},
## stage 2
{
"$group" : {
"_id" : {
"is_email_promotion" : "$emailer_for_promotion",
"is_homepage_featured" : "$homepage_featured"
},
"average_checkout_price" : {
"$avg" : "$checkout_price"
}
}
}
],
"bucket_wise_data" : [
## stage 1
{
"$bucket" : {
"groupBy" : "$checkout_price",
"boundaries" : [ 0, 50, 100, 200, 400, 600, 800, 1000 ],
"default" : "Other",
"output" : {
"count" : { "$sum" : 1},
"average" : { "$avg" :"$num_orders" }
}
}
}
]
}
}
])
for i in result_9:
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment