Skip to content

Commit

Permalink
Fix issue when using company1 input data (#72)
Browse files Browse the repository at this point in the history
* Fix issue with providing courses with no data

* fixed test functions
  • Loading branch information
Erik-McKelvey authored Jul 28, 2023
1 parent 5666a41 commit a135246
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 4 deletions.
21 changes: 21 additions & 0 deletions prediction_service/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ def __init__(self, term, message="Invalid term"):
self.message = message
super().__init__(self.message + f': {self.term}')

def filter_courses_by_name(courses, names):
'''Takes courses in the following format:
[
{
"name": str, // e.g., “Fundamentals of Programming with Engineering Applications”
"shorthand": str, // e.g., “CSC111”
"prerequisites": str[][] // e.g., [[“CSC111”, “CSC115”], [“CSC116”]]
"corequisites": str[][] // e.g., [[“CSC111”, “CSC115”], [“CSC116”]]
“terms_offered”: str[] // “fall”, “spring”, “summer”
},
...
]
And returns the list of courses that have the given names'''

filtered_courses = []
for course in courses:
if course["course"] in names:
filtered_courses.append(course)
return filtered_courses

def filter_courses_by_term_and_subj(courses, term):
'''Takes courses in the following format:
[
Expand Down Expand Up @@ -137,6 +157,7 @@ def reformat_schedules(schedules):
courses.append({
"Term": str(schedule["year"]) + _term_plain_to_code(term["term"]),
"Subj": subj,
"Course": course["course"],
"Num": num,
"Sched Type": "LEC",
"Enrolled": enrolled
Expand Down
2 changes: 1 addition & 1 deletion prediction_service/scripts/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,4 @@
body = {'year':'2023', 'term':'summer', 'courses':courses}
response = requests.post(url, json = body, headers = {'Content-Type': 'application/json'})
print(response.status_code)
print(response._content)
print(response._content)
219 changes: 219 additions & 0 deletions prediction_service/scripts/test_endpointc1data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import requests
import json

# Test endpoint locally
base_url = 'http://localhost:8001'

# Test endpoint from dev deployment
# base_url = 'https://algs2-dev.onrender.com'

# Test endpoint from prod deployment
# base_url = 'https://algs2.onrender.com'

url = f'{base_url}/predict'
courses = [{
"name": "Software Development Methods",
"shorthand": "SENG265",
"course": "SENG265",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC115", "CSC116"]
],
"corequisites": []
}, {
"name": "Software Testing",
"shorthand": "SENG275",
"course": "SENG275",
"terms_offered": ["spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["SENG265"]
],
"corequisites": []
}, {
"name": "Human Computer Interaction",
"shorthand": "SENG310",
"course": "SENG310",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["SENG265", "ECE241"]
],
"corequisites": []
}, {
"name": "Software Quality Engineering",
"shorthand": "SENG426",
"course": "SENG426",
"terms_offered": ["summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["SENG275"],
["SENG321", "SENG371", "ECE356"]
],
"corequisites": []
}, {
"name": "Embedded Systems",
"shorthand": "SENG440",
"course": "SENG440",
"terms_offered": ["summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["ECE355", "CSC355"]
],
"corequisites": []
}, {
"name": "Design Project II",
"shorthand": "SENG499",
"course": "SENG499",
"terms_offered": ["summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["SENG350"],
["ECE363", "CSC361"],
["ENGR002"],
["CSC370"],
["SENG321"]
],
"corequisites": []
}, {
"name": "Fundamentals of Programming II",
"shorthand": "CSC115",
"course": "CSC115",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC110", "CSC111"]
],
"corequisites": []
}, {
"name": "Fundamentals of Programming with Engineering Applications II",
"shorthand": "CSC116",
"course": "CSC116",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC110", "CSC111"]
],
"corequisites": []
}, {
"name": "Introduction to Computer Architecture",
"shorthand": "CSC230",
"course": "CSC230",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC115", "CSC116"]
],
"corequisites": []
}, {
"name": "Algorithms and Data Structures I",
"shorthand": "CSC225",
"course": "CSC225",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC115", "CSC116"],
["MATH122"]
],
"corequisites": []
}, {
"name": "Algorithms and Data Structures II",
"shorthand": "CSC226",
"course": "CSC226",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC225"],
["GEOG226", "PSYC300A", "STAT254", "STAT255", "STAT260"]
],
"corequisites": ["GEOG226", "PSYC300A", "STAT254", "STAT255", "STAT260"]
}, {
"name": "Foundations of Computer Science",
"shorthand": "CSC320",
"course": "CSC320",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["CSC226"]
],
"corequisites": []
}, {
"name": "Operating Systems",
"shorthand": "CSC360",
"course": "CSC360",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["SENG265", "CSC225"],
["ECE255", "CSC230"]
],
"corequisites": []
}, {
"name": "Database Systems",
"shorthand": "CSC370",
"course": "CSC370",
"terms_offered": ["fall", "spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["SENG265", "CSC225"]
],
"corequisites": []
}, {
"name": "Continuous-Time Signals and Systems",
"shorthand": "ECE260",
"course": "ECE260",
"terms_offered": ["fall", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["MATH101"],
["MATH110", "MATH211"]
],
"corequisites": ["MATH211"]
}, {
"name": "Digital Signal Processing I",
"shorthand": "ECE310",
"course": "ECE310",
"terms_offered": ["spring", "summer"],
"peng": False,
"min_enroll": 5,
"hours": [3, 0, 0],
"prerequisites": [
["ECE260"]
],
"corequisites": []
}]
body = {'year':'2023', 'term':'summer', 'courses':courses}
response = requests.post(url, json = body, headers = {'Content-Type': 'application/json'})
print(response.status_code)
print(response._content)
8 changes: 5 additions & 3 deletions prediction_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def predict(request):

with open('data/client_data/schedules2.json', 'r', encoding='utf-8') as fh:
historic_schedules = json.load(fh)

# Reformat schedules for prediction
#historic_schedules = utils.reformat_schedules(historic_schedules)

# Get courses from request
courses = data.get('courses')
Expand All @@ -47,6 +44,11 @@ def predict(request):
courses = utils.fix_course_and_shorthand(courses)
courses = utils.filter_courses_by_term_and_subj(courses, term)
courses = utils.reformat_courses(courses, year, term)

# Fitler out courses with no data
formatted_historic_schedules = utils.reformat_schedules(historic_schedules)
course_names = [course["Course"] for course in formatted_historic_schedules]
courses = utils.filter_courses_by_name(courses, course_names)

"""# Perform prediction
predictions = enrollment_predictions(historic_schedules, courses)
Expand Down

0 comments on commit a135246

Please sign in to comment.