Created
August 26, 2020 05:51
-
-
Save lakshay-arora/1db1369c3500287580baad10eba757a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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