Skip to content
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# course-selection
# course-selection
# Running the Program -- Frontend.
To run the program, cd into the front_end directory.
Run ```npm install``` to install the required packages.
Use ```npm start``` to run the program. It will run on localhost:3000


# Running the Program -- Backend.
To run the program, ensure that your .env files are set up. See back_end README.md for instructions.

Then, use ```flask run``` to run the program. It will run on localhost:5000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting this! We should probably expand this readme even further at some point with more specific instructions, as well as an overview of the project (in a future pull request, of course, not here!).

13 changes: 12 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_database():
logger.info("Reached /api/test-database")
return jsonify(db.get_all_test())


@app.route("/search", methods=["GET"])
def search():
args = request.args
Expand Down Expand Up @@ -91,4 +92,14 @@ def search():

# See database_api.py for structure of input query
res = do_search(query_dict)
return jsonify(res)
return jsonify(res)


@app.route("/api/get-course-info", methods=["GET"])
def course_info():
logger.info("Reached /api/course-info")
args = request.args
course_id = args.get("course_id", "")
semester = args.get("semester", "")
res = db.get_course_info(course_id, semester)
return jsonify(res)
58 changes: 55 additions & 3 deletions database_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask import jsonify
from pymongo import MongoClient
from dotenv import load_dotenv
import logging
Expand Down Expand Up @@ -27,9 +28,11 @@ def __init__(self):
self.db = self.client.course_selection

def connect(self):
self.client = MongoClient(os.getenv("MONGO"), tlsCAFile=certifi.where())
self.client = MongoClient(os.getenv("MONGO"),
tlsCAFile=certifi.where())
self.db_admin = self.client.admin
logger.info(f"MongoDB server status: {self.db_admin.command('serverStatus')}")
logger.info(
f"MongoDB server status: {self.db_admin.command('serverStatus')}")

def get_all_test(self):
# note that when you are returning, you want it to be jsonify-able,
Expand All @@ -48,11 +51,60 @@ def get_all_test(self):
ret = None
return ret

def get_course_info(self, course_id, semester):
"""
Retrieves course info from the database for a specific
course_id, from a given semester

Semester is of format Spring/Summer/Fall Year

This information includes all course evaluation data across
different terms for this course_id

params: query = {
"course_id": "the course_id",
"semester = "semester_in_words"
Comment on lines +65 to +66
Copy link
Collaborator

@bnehoran bnehoran Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting of one of these two lines is off. I know this is just documentation so it doesn't affect the functionality, but best to clean it before merging in.

}

Example from COS 126, Fall 2021:
query = { "course_id": "002051", "semester": "Fall 2021" }
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also specify what the format of the returned value is? I can find it by running it, but it's good to document the format.
Am I understanding correctly that the result is a list where the first element (position 0) is the information on the course, and the other elements of the list are evaluations? If so, is there possibly a neater way to format it? Perhaps as a dictionary with one key for info and the other key for evals? What do you think?

if course_id == "":
return [], []

try:
# Assume semester is passed in as "[Fall/Spring/Summer] [Year]"
term_data = self.db.semesters.find_one(
{"name": semester}, {"_id": 0, "code": 1}
)
if term_data is not None:
term = term_data["code"]

course_db = self.db.courses
evals_db = self.db.evaluations
course_query_string = {'course_id': course_id, 'term': term}
course_res = course_db.find(course_query_string,
{"_id": 0})
eval_query_string = {'course_id': course_id}
eval_res = evals_db.find(eval_query_string, {"_id": 0})
course_res = list(course_res)
eval_res = list(eval_res)
ret = course_res + eval_res
except Exception as e:
logger.error(
f"Failed to get information for course_id {course_id}. "
f"Error displayed below:\n{e}"
)
ret = None
# Note, right now this returns a ton of information
# If this information is difficult to use on the front end
# This code can be modified going forward to meet this need
return ret

def close(self):
self.client.close()



if __name__ == "__main__":
# a basic example of how to use, can remove later
db = DatabaseAPI()
Expand Down