Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Search by course name, instructor, and course number #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@
import importlib
from flask import Flask, jsonify
# Grab the course data from the data.py processing script
from data import parse_courses, number_of_courses, number_of_pages
from data import parse_courses, number_of_courses, number_of_pages, search
# moduleName = input('utils')
# importlib.import_module(utils)

app = Flask(__name__)

@app.route("/")
def home_page():
return "Hello"

@app.route("/2021/search_instructor_by_name/<name>")
def search_instructor_by_name(name):
return search(Instructor=name).to_json(orient='records')

@app.route("/2021/search_course_by_name/<name>")
def search_course_by_name(name):
return search(Course_Name=name).to_json(orient='records')

@app.route("/2021/search_course_number_by_name/<num>")
def search_course_number_by_name(num):
return search(Course_Number=num).to_json(orient='records')

@app.route('/2021/courses_by_gpa/<page_number>')
def courses_by_gpa(page_number):
try:
Expand All @@ -26,6 +42,14 @@ def courses_by_name(page_number):
except AttributeError:
return 'Bad request!', 400

# @app.route('/2021/search_courses_by_name/<course_name>')
# def courses_by_name(course_name):
# try:
# course_list = parse_courses(page_number, '', '', '', 'Course Name').to_json(orient='records')
# return course_list
# except AttributeError:
# return 'Bad request!', 400

@app.route('/2021/courses_by_size/<page_number>')
def courses_by_size(page_number):
try:
Expand Down
11 changes: 11 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

import math
import pandas as pd
import numpy as np

# course_data = pd.read_csv('courses_2021_desc.csv')
course_data = pd.read_csv('courses_2021_desc.csv')
course_data.replace(np.nan, '')
course_data.fillna("", inplace=True)

# This is a very messy function
# What it tries to do is extract course data based on a number of variables
# Geneds: If you put in a gened requirement it will filter on that requirement
# Depts: It will get courses for specific departments
# Query: If you input a search query it will return that course
# Sort Order: Orders how you want the data to be filtered
def search(**kwargs):
output = course_data[['Course Name', 'GPA', 'Course Number', 'geneds', 'dept', 'size', 'Instructor']]
for key, value in kwargs.items():
key = key.replace("_", " ")
output = output[output[key].str.contains(value)]
return output


def parse_courses(page, geneds, depts, query, sort_order):

if(int(page) < 0):
Expand Down