Question with proper formatting here: http://imgur.com/a/vHWu0 Background Agains
ID: 3833073 • Letter: Q
Question
Question with proper formatting here: http://imgur.com/a/vHWu0
Background
Against all bureaucratic stereotypes, the Social Security Administration, provides a neat web site showing the distribution of names chosen for kids over the last 100 years in the US (https://www.ssa.gov/OACT/babynames/).
Every 10 years, the data gives the 1000 most popular boy and girl names for kids born in the US. The data can be boiled down to a single text file as shown below. On each line we have the name, followed by the rank of that name in 1900, 1910, 1920, ... 2000 (11 numbers). A rank of 1 was the most popular name that year, while a rank of 997 was not very popular. A 0 means the name did not appear in the top 1000 that year at all. The elements on each line are separated from each other by a single space. The lines are in alphabetical order, although we will not depend on that.
...
Sam 58 69 99 131 168 236 278 380 467 408 466
Samantha 0 0 0 0 0 0 272 107 26 5 7
Samara 0 0 0 0 0 0 0 0 0 0 886
Samir 0 0 0 0 0 0 0 0 920 0 798
Sammie 537 545 351 325 333 396 565 772 930 0 0
Sammy 0 887 544 299 202 262 321 395 575 639 755
Samson 0 0 0 0 0 0 0 0 0 0 915
Samuel 31 41 46 60 61 71 83 61 52 35 28
Sandi 0 0 0 0 704 864 621 695 0 0 0
Sandra 0 942 606 50 6 12 11 39 94 168 257
...
We see that "Sam" was #58 in 1900 and is slowly moving down. "Samantha" popped on the scene in 1960 and is moving up strong to #7. "Samir" barely appears in 1980, but by 2000 is up to #798. The database is for children born in the US, so ethnic trends show up when immigrants have kids.
Ultimately, we want to organize that data to graph it as shown below with the names Sam and Samantha...
One of the neat things about this project is that it uses real data (and lots of it!). There are over 4,500 names in the database. The data just records literally what people put on the forms, so there are things like "A" and "Baby" recorded as names (the data is more cleaned up in the later years). We will not worry about that, and we will not combine names that are similar in some sense – "Cathy" and "Catherine" and "Kathryn" and "Katie" and "Kati" will all count as different names. Looking at the data, long names ("Michael") are becoming more popular compared to their short versions ("Mike").
Requirements
For this assignment you will build a database-backed Node.js/Express/Jade/Mongoose web app to allow people to explore the baby names dataset.
You must use the datafile given (see Datafile section below) for populating your MongoDB database. Include in the root of your project folder a file named populate-database.txt that includes the full mongoimport command you used to load the data into your database.
Your code must convert the 0's to 1001 (see note in Datafile section below), not necessarily replacing them in the database, you may do this in your client-side Javascript.
The graphing will use Javascript and whatever Javascript graphing library you wish.
The graphing must be done as shown, namely, with the most popular (rank 1) at the top.
When the user enters a name your Javascript code must make an AJAX request (I strongly suggest you use jQuery) back to your Node.js/Express/Jade/Mongoose web app to get the data for that particular name.
The Node.js/Express/Jade/Mongoose web app will then look the name up in a MongoDB database and return the data or if not found an appropriate message.
Once the Javascript web page gets the response back it will either add the data to the existing graph (if the name was found) or let the user know that the name was not found.
You will have at least 2 routes in your web app -- the root, that is, /, will contain the web app itself. The other route will allow for names to be looked up in the database.
You must sanitize both the input from Javascript web page, as well as, the data coming out of the database.
Your HTML must validate as HTML5.
Any styling must be done as an external stylesheet that must validate as CSS3.
You must use Bootstrap (from CDN) to format your page.
Datafile
Here is a tab-separated text file containing the data. NOTE: A 0 occurring as a rank means that the name did not appear in the top 1000 for that decade -- so, your code will need to convert those to a 1001 to have the graph work correctly and accurately.
names-data.csvPreview the document
What to submit
Zip the folder containing your Node.js/Express/Jade/Mongoose web app into a zip file named NameSurferApp.zip and submit as an attachment below.
Explanation / Answer
/** This homework is derived from an assignment at Stanford in an introductory course. We are given a file names-data.txt which lists in alphabetic order lines with names and the ranking of that name in the census in 1900, 1910, .. 2000. For example the following is a fragment of the file ... Sam 58 69 99 131 168 236 278 380 467 408 466 Samantha 0 0 0 0 0 0 272 107 26 5 7 Samara 0 0 0 0 0 0 0 0 0 0 886 Samir 0 0 0 0 0 0 0 0 920 0 798 Sammie 537 545 351 325 333 396 565 772 930 0 0 Sammy 0 887 544 299 202 262 321 395 575 639 755 Samson 0 0 0 0 0 0 0 0 0 0 915 Samuel 31 41 46 60 61 71 83 61 52 35 28 Sandi 0 0 0 0 704 864 621 695 0 0 0 Sandra 0 942 606 50 6 12 11 39 94 168 257 ... Here for example Samantha was not in the top 1000 most popular names in 1900, and it remained so until 1960 when it became the 272 most popular name. And it kept improving until in 1990 it was the 5th most popular name in the USA. You will first define the class NameRecord encapsulating the information about a name with the following outline class NameRecord { private String _name; // The name being considered private int[] _rankings;// Its rankings in the 11 censuses public NameRecord(); public NameRecord(String name, int[] ranks); public String getName(); public int getRank(int rank); // use 0 for 1990, 1 for 1910, .. public int bestYear(); // returns the year with best rank public NameRecord[] getAllNameRecords(String filename); // Returns an array with the NameRecord of each name in the file //filename .... } Then in the class NameSurfer you will have a main program that in a loop will prompt the user for a name and, if one that we know, it will display a graph as follows, for example for Sam 1990 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 58 1910 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 69 1920 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 99 1930 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 131 1940 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 168 1950 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 236 1960 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 278 1970 xxxxxxxxxxxxxxxxxxxxxxxxx 380 1980 xxxxxxxxxxxxxxxxxxxxx 467 1990 xxxxxxxxxxxxxxxxxxxxxxx 408 2000 xxxxxxxxxxxxxxxxxxxxx 466 The loop terminates when the user enters the empty string. In a new loop the program asks the user to enter a string and prints out (case insensitive) all the names that contain that string, each with its best year. For example, if the user enters sam, it will display: Isamar 1990 Rosamond 1910 Sam 1900 Samantha 1990 Samara 2000 Samir 2000 Sammie 1930 Sammy 1940 Samson 2000 Samuel 2000 Again the loop terminates when the user enters the empty string. */ import java.util.Scanner; import java.util.ArrayList; import java.io.*; class NameRecord { private String _name; // The name being considered private int[] _rankings;// Its rankings in the 11 censuses public NameRecord() {} public NameRecord(String name, int[] ranks) { _name = name; _rankings = ranks; } public String getName() { return _name; } public int[] getRankings() { return _rankings; } public int getRank(int rank) {// use 0 for 1990, 1 for 1910, .. return _rankings[rank]; } /** Return year of best ranking with 0 for 1900, .. */ public int bestYear() { // returns the year with best rank int best = 0; int value = Integer.MAX_VALUE; for (int k = 0; k < _rankings.length; k++) { int r = _rankings[k]; if (r > 0 && r 0) { double v = (int)((1000-r)*6.0/100); for (int j = 1; j = 0) { int year = x.bestYear(); System.out.println(name.toUpperCase() + " " + (1900+10*year)); } } } public static void main(String[] args) { String filename = "names-data.txt"; records = NameRecord.getAllNameRecords(filename); Scanner scan = new Scanner(System.in); // Ask for names and show their record while (true) { System.out.print("Enter name to search: "); String name = scan.nextLine().trim(); if (name.length() == 0) break; displayName(name); } // Ask for strings and show all names with that string while (true) { System.out.print("Enter string to search for: "); String s = scan.nextLine().trim(); if (s.length() == 0) break; displayNames(s); } } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.