1/24/2020 1/5 Course Search Engine: Backend Once you follow these instructions, your repository will contain a directory named pa2. That directory will contain: README.txt: description of the contents...

1 answer below »
please let Prasun,Expert to help me.


1/24/2020 1/5 Course Search Engine: Backend Once you follow these instructions, your repository will contain a directory named pa2. That directory will contain: README.txt: description of the contents of the directory. ui: a sub-directory containing the Django user interface code. You will modify a file named courses.py in this directory. Do not modify any of the other files. Data For this assignment, you will use a sqlite3 database, named ui/course_information.sqlite3, that we constructed using the index gathered by our catalog scraper from PA #1 and data scraped from the timeschedules web page. To download this database, run the following command from within your pa2/ui directory: $ sh get_files.sh You can use the sqlite3 command-line interface to explore the database and run sample queries. Recall that the command .tables will list the names of the tables stored in the database, the .schema command will list the schema (definition) for particular table, and the .quit command will exit sqlite3. For exam- ple, you can run the following from within your pa2/ui directory: Note that the string sqlite> is the sqlite command-line prompt. Warm up exercise #1 Before you start writing code for this assignment, we strongly recommend getting comfortable with query- ing the database using the sqlite3 command-line interface. Here are some queries that it would be helpful to understand: Find the titles of all courses with department code “CMSC” in the course table. Find the department names, course numbers, and section numbers for courses being offered on MWF at 10:30am (represented as 1030) $ sqlite3 course_information.sqlite3 SQLite version 3.19.3 2017-06-27 16:48:08 Enter ".help" for usage hints. sqlite> .tables catalog_index gps sections courses meeting_patterns sqlite> .schema courses CREATE TABLE courses ( course_id integer, -- unique ID assigned to each course dept varchar(4), -- 4 character department code course_num varchar(5), -- 5 digit course number, represented as a 5 character title varchar(100) -- course title, represented as a string with up to 100 ); sqlite> .quit Due: January 30st at 6pm Getting started In this assignment, you will be building the backend for a course search tool. You combine information gathered from the University’s course catalog and the time schedules web page to respond to searches such as: “Find all courses that have Plato in their description, meet on Tuesdays between 10:30am and 3pm, and are within a 10 minute walk of Ryerson.” 1/24/2020 2/5 Find the department names and course numbers for courses being offered in Ryerson on MWF be- tween 10:30am and 3pm (represented as 1500). Find the department names, course numbers, and course titles for courses being offered on MWF at 9:30am (represented as 930) that have the words “programming” and “abstraction” in their title/course description. Place these results inside warmup1.sql. These will not be graded. However, they provide evidence that you attempted to complete the warmup exercises. Using Python and sqlite3 The library sqlite3 allows a Python program to connect to a sqlite3 database and make queries. You will use the following functions from this library: sqlite3.connect(db_filename): takes the name of a database as a string and opens or creates a sqlite3 database of that name and returns a connection object. conn.cursor(): returns a cursor object that can be used to execute queries on the connected database (conn) and get information about the schema for a query result. conn is a connection object. c.execute(q, args): takes q, a string containing a SQL query in which parameters are specified with question marks (?), and a list of values for the parameters (one per ? in the query string) and returns an object that can be used to access the resulting table. c is a cursor object. r.fetchall(): returns a list of lists with one entry per tuple in the result. r is the result of a call to execute. conn.close(): closes the connection to the database. conn is a connection object. Warm up Exercise #2 Write parameterized versions of the queries from warm up exercise #1 from within ipython3 using the sqlite3 library. Place these results inside warmup2.py. These will not be graded. However, they provide evidence that you attempted to complete the warmup exercises. Django Web Interface We have provided a Django web interface for your search tool. To run it, you’ll need to install the appropri- ate version of Django using the Linux commands: $ cd; pip install -Iv django==2.0.2 --user To start the interface go to the directory pa5/ui in your repository and run the command: $ python3 manage.py runserver It will be helpful to run this command in its own terminal window. When the user hits the submit button, the interface will call the function find_courses in the file pa2/ui/courses.py with a dictionary containing values corresponding to the completed fields. Here is a list of the possible keys for the dictionary and the types of their associated values: dept: department code (string) day: meeting pattern (list of strings) time_start: earliest starting time (integer in range 0 to 2359) time_end: latest ending time (integer in range 0 to 2359) building_code: building code (string) walking_time: maximum walking time from specified building (integer). You will always get building and walking_time together. enrollment: lower and upper bound (inclusive) on the size of the class (pair of integers) terms: catalog search terms (list of strings) A few notes: Once the interface is started, you can use it by pointing a browser on the machine your are using (your VM) to http://127.0.0.1:8000/. 1/24/2020 3/5 If the user’s input includes a value for day, a class will match it if it meets on any one of the specified meeting patterns. For example, the input {"day":["MWF", "TR"]} matches classes that meet on a MWF schedule or a TR schedule. The SQL operator IN will be useful for this field. time_start / time_end should be considered as inclusive bounds. Furthermore, you should not as- sume that you receive both time fields. For example, if the user interface passes along a dictionary with a field for time_start but does not include a field for time_end, your program should take the speci- fied starting time as a lower bound and return all courses that meet at that time or after it. The bounds specified in the enrollment pair should be considered inclusive. The SQL operator BEWTEEN x AND y will be useful for this field. A specific course matches a string of terms only if all of the terms occur in the catalog index with the course_id for that course. For example, the terms [“economics”, “sciences”, “mathematics”] match “CMSC 12200” (course id: 611), because the tuples (611,"sciences"), (611, "economics"), AND (611, mathematics) occur in the catalog_index table. If you check the “show args_to_ui” box, the interface will show the dictionary that will be passed to find_courses. Your task Your task is to implement the function find_courses(args_to_ui), which takes a dictionary as de- scribed above and performs a search to find courses/sections that match the user’s input. The result of this search process will be a relation. Your function must return a tuple with the attribute (column) names for the relation and a list of the tuples in the relation. For example, if the input from the user contains: { "terms": ["science", "mathematics", "economics"], "day": ["MWF"], "time_start": 900, "time_end": 1500 } the output of the function would be: When the interface first starts up, it will call find_courses with the empty dictionary. If the input dictio- nary is empty, find_courses should return ([], []). We have provided you with a function to ease the task of retrieving the column names for the table gener- ated by your query. After you have run your query, pass your cursor object into the function get_header(cursor) to retrieve the column names for your generated table (in list format). Querying the Database Your function will need to gather information from course_information.sqlite3 to process the user’s input. There are many possible combinations of inputs and you should not hard-code them all into your implementation. Instead, your code should construct a query from the parameters specified by the user. For example, given the dictionary: { "time_start": 1030, "time_end": 1500, "day": ["MWF"] } Your implementation should construct a query similar to: SELECT courses.dept, courses.course_num, courses.title, sections.section_num, meeting_patterns.day, meeting_patterns.time_start, meeting_patterns.time_end, sections.enrollment FROM courses JOIN sections JOIN meeting_patterns (['dept', 'course_num', 'title', 'section_num', 'day', 'time_start', 'time_end', 'en [('CMSC', '12200', 'Computer Science with Applications II.', '01', 'MWF', 930, 1020 ('CMSC', '12200', 'Computer Science with Applications II.', '02', 'MWF', 1330, 142 1/24/2020 4/5 ON courses.course_id = sections.course_id AND sections.meeting_pattern_id = meeting_patterns.meeting_pattern_id WHERE meeting_patterns.time_start >= ? AND meeting_patterns.time_end <= ? and meeting_patterns.day in (?) along with an argument tuple containing (1030, 1500, 'mwf'). (note: the formatting of the query is merely for clarity.) the join method for strings will be very useful for generating a query string. for example: l = ["a", "b", "c"] ", ".join(l) #yields the string "a, b, c" what attributes should be included in the output? the attributes included in the output will depend on the parameters specified by the user. the table below shows the attributes (columns) that should be included for each possible type of input (rows). the output should include the union of the attributes for each of the specified inputs.   dept course_num title section_num day time_start time_end enrollment building_code walkin terms x x x               dept x x x               day x x x x x x x x     enrollment x x x x and="" meeting_patterns.day="" in="" (?)="" along="" with="" an="" argument="" tuple="" containing="" (1030,="" 1500,="" 'mwf').="" (note:="" the="" formatting="" of="" the="" query="" is="" merely="" for="" clarity.)="" the="" join="" method="" for="" strings="" will="" be="" very="" useful="" for="" generating="" a="" query="" string.="" for="" example:="" l="["a"," "b",="" "c"]="" ",="" ".join(l)="" #yields="" the="" string="" "a,="" b,="" c"="" what="" attributes="" should="" be="" included="" in="" the="" output?="" the="" attributes="" included="" in="" the="" output="" will="" depend="" on="" the="" parameters="" specified="" by="" the="" user.="" the="" table="" below="" shows="" the="" attributes="" (columns)="" that="" should="" be="" included="" for="" each="" possible="" type="" of="" input="" (rows).="" the="" output="" should="" include="" the="" union="" of="" the="" attributes="" for="" each="" of="" the="" specified="" inputs.=""  ="" dept="" course_num="" title="" section_num="" day="" time_start="" time_end="" enrollment="" building_code="" walkin="" terms="" x="" x="" x=""  =""  =""  =""  =""  =""  =""  ="" dept="" x="" x="" x=""  =""  =""  =""  =""  =""  =""  ="" day="" x="" x="" x="" x="" x="" x="" x="" x=""  =""  ="" enrollment="" x="" x="" x="">
Answered Same DayJan 24, 2021

Answer To: 1/24/2020 1/5 Course Search Engine: Backend Once you follow these instructions, your repository will...

Prasun Kumar answered on Jan 30 2021
149 Votes
Download the solution from https://bit.ly/EdSolution2. Unzip the file and follow instructions given in the report.pdf file. https://bit.ly/EdSolution2
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here