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

feat(be): Add support for new degrees #1151

Merged
merged 5 commits into from
Oct 17, 2024
Merged
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
Binary file modified backend/data/final_data/conditions.pkl
Binary file not shown.
4 changes: 2 additions & 2 deletions backend/data/final_data/conditionsProcessed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3643,7 +3643,7 @@
},
"COMP4920": {
"original": "Completion of 18 UOC in Computer Science.<br/><br/>",
"processed": "(COMP2511 || COMP2911) && 96UOC && COMP?1"
"processed": "(COMP2511 || COMP2911) && 96UOC && (COMP?1 || COMP?H)"
},
"COMP4951": {
"original": "Prerequisite: Enrolled in a CSE BE (Hons) programs, completion of 126 UOC and completion of 3rd year core.<br/><br/>",
Expand All @@ -3660,7 +3660,7 @@
},
"COMP4961": {
"original": "Prerequisite: Enrolment in 4515 Computer Science (Hons) or 3779 Advanced Computer Science (Hons)<br/><br/>",
"processed": "4515 || 3648"
"processed": "4515 || 3779"
},
"COMP4962": {
"original": "Prerequisite: COMP4961<br/><br/>",
Expand Down
6 changes: 5 additions & 1 deletion backend/data/final_data/conditionsTokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -8059,7 +8059,11 @@
"&&",
"96UOC",
"&&",
"(",
"COMP?1",
"||",
"COMP?H",
")",
")"
],
"COMP4951": [
Expand Down Expand Up @@ -8089,7 +8093,7 @@
"(",
"4515",
"||",
"3648",
"3779",
")"
],
"COMP4962": [
Expand Down
8 changes: 4 additions & 4 deletions backend/data/processors/manual_fixes/COMPFixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def COMP_4920():
"original": "Prerequisite: (COMP2511 or COMP2911) and completion of 96 UOC in Computer Science.<br/><br/>",
"processed": "(COMP2511 || COMP2911) && 96UOC in Computer Science"
"""
return "(COMP2511 || COMP2911) && 96UOC && COMP?1"
return "(COMP2511 || COMP2911) && 96UOC && (COMP?1 || COMP?H)"

def COMP_4951(conditions):
"""
Expand Down Expand Up @@ -170,11 +170,11 @@ def COMP_4953():

def COMP_4961():
"""
"original": "Prerequisite: Students enrolled in program 4515 Bachelor of Computer Science (Hons) or program 3648.<br/><br/>",
"original": "Prerequisite: Enrolment in 4515 Computer Science (Hons) or 3779 Advanced Computer Science (Hons)<br/><br/>",

"processed": "4515 || 3648"
"processed": "4515 || 3779"
"""
return "4515 || 3648"
return "4515 || 3779"


def COMP_6445():
Expand Down
6 changes: 3 additions & 3 deletions backend/data/processors/specialisations_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def get_courses(
for course, title in container_courses.items():
description = description + "" # prevent unused variable error

if "any course" in course:
if "any course" in course.lower():
course_processed = {"any course": "1"}
elif "any level" in course:
elif "any level" in course.lower():
# e.g. modify "any level 4 COMP course" to "COMP4"
course_processed = process_any_level(course)
else:
Expand All @@ -249,7 +249,7 @@ def process_any_level(unprocessed_course: str) -> dict[str, str]:
# group 1 contains level number and group 2 contains program title
# Note '?:' means inner parentheses is non-capturing group
# COMP4XXx
res = re.search(r"level (\d) ((?:[^ ]+ )+)(course)?", unprocessed_course)
res = re.search(r"[lL]evel (\d) ((?:[^ ]+ )+)(course)?", unprocessed_course)
if not res:
print("ERRR BY: ", unprocessed_course)
# TODO: THIS IS BROKEN by `any level 1/2 ...`
Expand Down
3 changes: 2 additions & 1 deletion backend/server/routers/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ def get_programs() -> dict[str, dict[str, str]]:
# return {"programs": {q["code"]: q["title"] for q in programsCOL.find()}}
return {
"programs": {
# "3362": "City Planning (Honours)",
"3778": "Computer Science",
# "3779": "Advanced Computer Science (Honours)", # TODO: Fix the electives
"3779": "Advanced Computer Science (Honours)",
"3502": "Commerce",
"3970": "Science",
"3543": "Economics",
Expand Down
8 changes: 6 additions & 2 deletions backend/server/routers/specialisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_specialisation_types(programCode: str) -> Dict[str, list[SpecType]]:
if not result:
raise HTTPException(
status_code=400, detail="Program code was not found")
return {"types": [*result["components"]["spec_data"].keys()]}
return {"types": [*result["components"].get("spec_data", {}).keys()]}


@router.get(
Expand Down Expand Up @@ -75,7 +75,11 @@ def get_specialisations(programCode: str, typeSpec: SpecType):
raise HTTPException(
status_code=400, detail="Program code was not found")

specRes = result["components"]["spec_data"].get(typeSpec)
specData = result["components"].get("spec_data")
if not specData:
# This is for programs without specialisations, e.g. 3362
return {"spec": {}}
specRes = specData.get(typeSpec)
if not specRes:
raise HTTPException(
status_code=404, detail=f"this program has no {typeSpec}")
Expand Down
4 changes: 3 additions & 1 deletion backend/server/routers/utility/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def get_all_specialisations(program_code: str) -> Optional[SpecsData]:
return None

# TODO: this can be done in a single aggregate
raw_specs = program["components"]["spec_data"]
raw_specs = program["components"].get("spec_data")
if raw_specs is None:
return {}
for spec_type_container in raw_specs.values():
spec_type_container = cast(dict[str, SpecData], spec_type_container)
for program_specs in spec_type_container.values():
Expand Down
8 changes: 5 additions & 3 deletions backend/server/tests/programs/test_get_structure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# assumes that getPrograms, getMajors, and getMinors isnt borked.
import copy
import requests
from hypothesis import given, settings
from hypothesis.strategies import composite, sampled_from
Expand All @@ -13,7 +14,10 @@

@composite
def major_minor_for_program(draw):
program = draw(sampled_from(programs))
possible_programs = copy.deepcopy(programs)
# possible_programs.remove("3362") # City Planning (Honours) does not have majors/minors

program = draw(sampled_from(possible_programs))
possible_specs: list[str] = []
for t in requests.get(f"http://127.0.0.1:8000/specialisations/getSpecialisationTypes/{program}").json()["types"]:
majorsRequest = requests.get(f"http://127.0.0.1:8000/specialisations/getSpecialisations/{program}/{t}")
Expand All @@ -35,8 +39,6 @@ def major_minor_for_program(draw):
@given(sampled_from(programs))
@settings(deadline=5000)
def test_all_programs_fetched(program):
if program == "3779": # adv cs broken
return
structure = requests.get(f"http://127.0.0.1:8000/programs/getStructure/{program}")
assert structure != 500
assert structure.json()["structure"]["General"] != {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const StartBrowsingStep = ({ degreeInfo }: Props) => {
};

const handleSaveUserSettings = async () => {
// TODO: Are these checks necessary?
// TODO: Rewrite these checks in the backend
// The check below is not always required, i.e. 3362
// If we do this at the backend, we can check everything, and only when needed
if (!degreeInfo.programCode) {
openNotification({
type: 'error',
Expand Down
Loading