python nosql代写-CS217 HW
时间:2021-12-01
Overview
In this assignment, we will exercise some basic skills on MongoDB. MongoDB is complicated,
and we only covered a very small fraction of it. Therefore, the main purpose of this assignment is
to let you have a taste of it.
Before you start on this assignment, please make sure that you watched the lecture video on
NoSQL. Follow the demo in the lecture to register a MongoDB account, create a cluster with
sample data, and setup password (do not use over-complex passward).
During the configuration step, make sure the IP address is set as 0.0.0.0 so that it is available
everywhere.
Do not change any contents in the database. Do not terminate the cluster since we will need to
run tests on your cluster.
To answer questions, please make sure to look at the documentation for sample datasets
(https://docs.atlas.mongodb.com/sample-data/available-sample-datasets/) and understand how
data is structured.

First we look at the SampleAirBnB Listings Dataset, the collection is
sample_airbnb.listingsAndReviews.
Q1 (1pt): Write a function test_monogoDB that returns the name of the first entry in
sample_airbnb.listingsAndReviews. (this is mostly the same as in the demo)
>>> test_mongoDB()
'Ribeira Charming Duplex'
>>> type(test_mongoDB())



Q2 (2pt): Write a function get_by_bd that takes two integers (a,b) as input and returns an
integer that represent the number of listings such that the number of bedrooms is between a and
b, inclusive. (do not count those that do not specify the number of bedrooms)
Some code for verification:
>>> get_by_bd (7,10)
14
>>> type(get_by_bd (7,10))



The next three questions are about the Sample Supply Store Dataset, the collection is
sample_supplies.sales. Please inspect the data format from MongoDB Atlas online
portal first.
Q3 (1pt): Write a function gender_dist that takes no input and returns a tuple of integers
indicating the number of transactions that are made by female and male respectively.

Q4 (1pt): We want to study the correlation between gender and their satisfaction of orders. Write
a function gender_stf that takes no input and returns a tuple of floats, indicating the average
satisfaction values made by female and male customers respectively.

Q5 (2pt): Write a function num_prod to query the total number of products sold on a specified
day. The function takes three integers (y, m, d) as inputs indicating the year, month and day.
It returns an integer of the total count of products.
Hint: check the data type for the field saleDate.
Documentation of datetime for reference: https://docs.python.org/3/library/datetime.html.



The next two questions are about Sample Restaurants Dataset. The collection is
sample_reataurants.reataurants. Please inspect the data format from MongoDB
Atlas online portal first.

Q6 (1pt): Write a function num_cuisine that takes no input and returns an integer indicating
the total number of distinct cuisines in this database.

Q7 (2pt): Write a function grades that takes two strings (restaurant name and zipcode) as
inputs and returns a list of all the letter grades this restaurant have ever received.
Some code for verification:
>>> grades("Lexler Deli","10174")
['A', 'A', 'A', 'A', 'A']
>>> grades ("Tov Kosher Kitchen","11374")
['Z', 'A', 'A', 'B']






Submission:
Submit the completed py file ONLY. DO not rename the file.
DO NOT call any function that you wrote in the py file. That is, please only keep the definition
of the functions.
DO NOT print any information in your functions.
DO NOT change any function names!


essay、essay代写