M101p Homework 6 Grade

 [Solution] Week 3 :Schema Design : M101P: MongoDB for Developers

Homework 3.1 : 

Download the students.json file from the Download Handout link and import it into your local Mongo instance with this command:

mongoimport --drop -d school -c students students.json
This dataset holds the same type of data as last week's grade collection, but it's modeled differently. You might want to start by inspecting it in the Mongo shell.

Write a program in the language of your choice that will remove the lowest homework score for each student. Since there is a single document for each student containing an array of scores, you will need to update the scores array and remove the homework.

Remember, just remove a homework score. Don't remove a quiz or an exam!

Hint/spoiler: With the new schema, this problem is a lot harder and that is sort of the point. One way is to find the lowest homework in code and then update the scores array with the low homework pruned.

To confirm you are on the right track, here are some queries to run after you process the data with the correct answer shown:

Let us count the number of students we have:

use school db.students.count() The answer will be 200.

Let's see what Tamika Schildgen's record looks like once you have removed the lowest score:

db.students.find( { _id : 137 } ).pretty( ) This should be the output:

{ "_id" : 137, "name" : "Tamika Schildgen", "scores" : [ { "type" : "exam", "score" : 4.433956226109692 }, { "type" : "quiz", "score" : 65.50313785402548 }, { "type" : "homework", "score" : 89.5950384993947 } ] }

To verify that you have completed this task correctly, provide the identity (in the form of their _id) of the student with the highest average in the class with following query that uses the aggregation framework. The answer will appear in the _id field of the resulting document.

db.students.aggregate( [ { '$unwind': '$scores' }, { '$group': { '_id': '$_id', 'average': { $avg: '$scores.score' } } }, { '$sort': { 'average' : -1 } }, { '$limit': 1 } ] )

Solution : 13

Homework 3.2 : 

In this homework you will be enhancing the blog project to insert entries into the posts collection. After this, the blog will work. It will allow you to add blog posts with a title, body and tags and have it be added to the posts collection properly.

We have provided the code that creates users and allows you to login (the assignment from last week). To get started, please download hw3-2and3-3.zip from the Download Handout link and unpack. You will be using these files for this homework, and for HW 3.3.

The areas where you need to add code are marked with XXX. You need only touch the BlogPostDAO.py file. There are three locations for you to add code for this problem. Scan that file for XXX to see where to work.

As a reminder, to run your blog you type

python blog.py
To play with the blog you can navigate to the following URLs

http://localhost:8082/ http://localhost:8082/signup http://localhost:8082/login http://localhost:8082/newpost You will be proving that it works by running our validation script as follows:

python validate.py You need to run this in a separate terminal window while your blog is running and while the database is running. It makes connections to both to determine if your program works properly. Validate connects to localhost:8082 and expects that mongod is running on localhost on port 27017.

As before, validate will take some optional arguments if you want to run mongod on a different host or a use an external webserver.

This project requires Python 2.7. The code is not 3.X compliant.

Ok, once you get the blog posts working, validate.py will print out a validation code for HW 3.2.
Please enter it below, exactly as shown with no spaces.

Solution : 89jklfsjrlk209jfks2j2ek

Homework 3.3 :

In this homework you will add code to your blog so that it accepts comments. You will be using the same code as you downloaded for HW 3.2.

Once again, the area where you need to work is marked with an XXX in the blogPostDAO.py file. There is just one location that you need to modify. You don't need to figure out how to retrieve comments for this homework because the code you did in 3.2 already pulls the entire blog post (unless you specifically projected to eliminate the comments) and we gave you the code that pulls them out of the JSON document.

This assignment has fairly little code, but it's a little more subtle than the previous assignment because you are going to be manipulating an array within the Mongo document. For the sake of clarity, here is a document out of the posts collection from a working project.

{ "_id" : ObjectId("509df76fbcf1bf5b27b4a23e"), "author" : "erlichson", "body" : "This is a blog entry", "comments" : [ { "body" : "This is my comment", "author" : "Andrew Erlichson" }, { "body" : "Give me liberty or give me death.", "author" : "Patrick Henry" } ], "date" : ISODate("2012-11-10T06:42:55.733Z"), "permalink" : "This_is_a_blog_post_title", "tags" : [ "cycling", "running", "swimming" ], "title" : "This is a blog post title" } where post_slug is the permalink. For the sake of eliminating doubt, the permalink for the example blog post above is http://localhost:8082/post/This_is_a_blog_post_title

You will run validation.py to check your work, much like the last problem. Validation.py will run through and check the requirements of HW 3.2 and then will check to make sure it can add blog comments, as required by this problem, HW 3.3. It checks the web output as well as the database documents.

python validate.py Once you have the validation code, please copy and paste in the box below, no spaces.

Solution : jk1310vn2lkv0j2kf0jkfs


Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

 [Solution] Week 5 :Aggregation Framework : M101P: MongoDB for Developers

Homework 5.1 : 

Finding the most frequent author of comments on your blog

In this assignment you will use the aggregation framework to find the most frequent author of comments on your blog. We will be using a data set similar to ones we've used before.

Start by downloading the handout zip file for this problem. Then import into your blog database as follows:

mongoimport --drop -d blog -c posts posts.json

Now use the aggregation framework to calculate the author with the greatest number of comments.

To help you verify your work before submitting, the author with the fewest comments is Mariela Sherer and she commented 387 times.

Please choose your answer below for the most prolific comment author:

Homework 5.2 : 

Crunching the Zipcode dataset
Please calculate the average population of cities in California (abbreviation CA) and New York (NY) (taken together) with populations over 25,000.
For this problem, assume that a city name that appears in more than one state represents two separate cities.
Please round the answer to a whole number.
Hint: The answer for CT and NJ (using this data set) is 38177.
Please note:
Different states might have the same city name.
A city might have multiple zip codes.

For this problem, we have used a subset of the data you previously used in zips.json, not the full set. For this set, there are only 200 documents (and 200 zip codes), and all of them are in New York, Connecticut, New Jersey, and California.
You can download the handout and perform your analysis on your machine with

mongoimport --drop -d test -c zips small_zips.json Note

This is raw data from the United States Postal Service. If you notice that while importing, there are a few duplicates fear not, this is expected and will not affect your answer.

Once you've generated your aggregation query and found your answer, select it from the choices below.
Please use the Aggregation pipeline to solve this problem.

Homework 5.3 :

Solution : 1

Homework 5.4 :

Removing Rural Residents

In this problem you will calculate the number of people who live in a zip code in the US where the city starts with a digit. We will take that to mean they don't really live in a city. Once again, you will be using the zip code collection, which you will find in the 'handouts' link in this page. Import it into your mongod using the following command from the command line:

mongoimport --drop -d test -c zips zips.json

This is raw data from the United States Postal Service. If you notice that while importing, there are a few duplicates fear not, this is expected and will not affect your answer.

If you imported it correctly, you can go to the test database in the mongo shell and conform that

> db.zips.count()

yields 29,467 documents.

The project operator can extract the first digit from any field. For example, to extract the first digit from the city field, you could write this query:

db.zips.aggregate([ {$project: { first_char: {$substr : ["$city",0,1]}, } } ])

Using the aggregation framework, calculate the sum total of people who are living in a zip code where the city starts with a digit. Choose the answer below.

You will need to probably change your projection to send more info through than just that first character. Also, you will need a filtering step to get rid of all documents where the city does not start with a digital (0-9).

                                                Solution :298016


Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Related Post :

- Week 1 : Introduction : M101P: MongoDB for Developers

- Week 2 : CRUD : M101P: MongoDB for Developers

- Week 3 : Schema Design : M101P: MongoDB for Developers

- Week 4 : Performance : M101P: MongoDB for Developers

Who's the easiest grader on campus?
Download the handout and mongoimport.
The documents look like this:

{ "_id" : ObjectId("50b59cd75bed76f46522c392"), "student_id" : 10, "class_id" : 5, "scores" : [ { "type" : "exam", "score" : 69.17634380939022 }, { "type" : "quiz", "score" : 61.20182926719762 }, { "type" : "homework", "score" : 73.3293624199466 }, { "type" : "homework", "score" : 15.206314042622903 }, { "type" : "homework", "score" : 36.75297723087603 }, { "type" : "homework", "score" : 64.42913107330241 } ] } There are documents for each student (student_id) across a variety of classes (class_id). Note that not all students in the same class have the same exact number of assessments. Some students have three homework assignments, etc.

Your task is to calculate the class with the best average student performance. This involves calculating an average for each student in each class of all non-quiz assessments and then averaging those numbers to get a class average. To be clear, each student's average includes only exams and homework grades. Don't include their quiz scores in the calculation.

What is the class_id which has the highest average student performance?
Hint/Strategy: You need to group twice to solve this problem. You must figure out the GPA that each student has achieved in a class and then average those numbers to get a class average. After that, you just need to sort. The class with the lowest average is the class with class_id=2. Those students achieved a class average of 37.6
mongoimport --drop -d test -c grades grades.json Below, choose the class_id with the highest average student average.
Categories: 1

0 Replies to “M101p Homework 6 Grade”

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *