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

Backend state migration #1101

Open
wants to merge 139 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
80e8c25
init auth
imagine-hussain Jun 30, 2022
ff3192a
merge dev
imagine-hussain Jul 1, 2022
5a6a5f5
skeleton sign in
imagine-hussain Jul 1, 2022
5fb0cfa
add auth route
imagine-hussain Jul 3, 2022
ae93bf0
o
imagine-hussain Jul 7, 2022
38fab1e
script on FE
imagine-hussain Jul 7, 2022
b3c8c85
workign loging with [email protected]'s client
imagine-hussain Jul 7, 2022
fc1e791
pyjwt to requirements
imagine-hussain Jul 7, 2022
94c5b3a
auth reset=
imagine-hussain Jul 7, 2022
402f023
ummm, need user
imagine-hussain Jul 7, 2022
e9a3461
document login
imagine-hussain Jul 8, 2022
5bf3c45
decorator for protection
imagine-hussain Jul 8, 2022
49cf480
note userData refactor
imagine-hussain Jul 8, 2022
891b71f
add prompt to app.jsx if not logged in
imagine-hussain Jul 8, 2022
5c0d491
post demo
imagine-hussain Jul 8, 2022
3d41dda
stub for user create and validate
imagine-hussain Jul 8, 2022
7540ed8
move clientID
imagine-hussain Jul 8, 2022
0e690a0
merge dev -> circles-331
imagine-hussain Jul 9, 2022
3fcfe72
merge dev -> circles-331
imagine-hussain Jul 9, 2022
734ec34
merge dev -> CIRCLES-331
imagine-hussain Jul 15, 2022
19fa449
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Aug 15, 2022
c4eec52
merged and made stuff not break
Peedee2002 Aug 15, 2022
e0d0ee9
removed node modules
Peedee2002 Aug 15, 2022
f4d2515
removed random
Peedee2002 Aug 15, 2022
1858b79
Merge branch 'dev' into CIRCLES-331/user-data-to-backend
Peedee2002 Aug 18, 2022
d2e0841
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Aug 20, 2022
dd2fd4a
merging
Peedee2002 Aug 20, 2022
e205475
Merge branch 'CIRCLES-331/user-data-to-backend' of github.com:csesoc/…
Peedee2002 Aug 20, 2022
74cf05c
sorta working database?
Peedee2002 Aug 20, 2022
869dbd5
CIRCLES-335: fixed mongodb schema to be rigid
Peedee2002 Aug 21, 2022
edf3bc5
merged dev
Aug 28, 2022
e4ccc12
Merge branch 'dev' into CIRCLES-331/user-data-to-backend
Peedee2002 Aug 29, 2022
d627064
Merge branch 'dev' into CIRCLES-331/user-data-to-backend
Peedee2002 Aug 29, 2022
f653e92
Mae/circles 346 local storage (#709)
hdphuong Sep 13, 2022
93838cd
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Sep 19, 2022
0c1f1b1
Merge branch 'dev' into CIRCLES-331/user-data-to-backend
Peedee2002 Sep 19, 2022
3453e58
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Sep 25, 2022
ca89db6
Merge branch 'CIRCLES-331/user-data-to-backend' of github.com:csesoc/…
Peedee2002 Sep 25, 2022
dab21d5
fix mypy
Peedee2002 Sep 25, 2022
6125f79
hotfix(database): fix validation errors
Peedee2002 Sep 25, 2022
8d13c3e
hotfix(database): fix planner tests
Peedee2002 Sep 25, 2022
f4c068a
hotfix(database): force PR checks to run when merging to this branch
Peedee2002 Sep 25, 2022
290df02
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Sep 26, 2022
fca08e9
hotfix(database): fix localstorage data to correctly match what the F…
Peedee2002 Sep 26, 2022
ca902e7
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Sep 26, 2022
60b2db1
Merge branch 'dev' into CIRCLES-331/user-data-to-backend
Peedee2002 Sep 28, 2022
fd89301
chore(migration): implemented toggleSummerTerm and fixed bad issues w…
Peedee2002 Sep 28, 2022
0f801ed
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Oct 18, 2022
e19b0d9
fix type
Peedee2002 Oct 18, 2022
08792ae
fix type
Peedee2002 Oct 18, 2022
d3bc4e5
fix ts
Peedee2002 Oct 18, 2022
6d9d59d
fix style
Peedee2002 Oct 18, 2022
fbb0d61
fix test
Peedee2002 Oct 18, 2022
281574b
Circles 349/migrate rest of planner slice (#846)
Peedee2002 Oct 19, 2022
ec26e6e
Merge branch 'dev' of github.com:csesoc/Circles into CIRCLES-331/user…
Peedee2002 Oct 25, 2022
312fca5
Elliot/circles 348 - planned/unplanned planner migration to backend (…
sixohtoo Nov 5, 2022
7464d8e
comment future practice
imagine-hussain Feb 20, 2023
acf328b
jank fix for default users
imagine-hussain Feb 27, 2023
6d1ebd1
add login route into the header
imagine-hussain Feb 27, 2023
b9ce29c
make login an indev feature and give the login a page wrapper
imagine-hussain Feb 27, 2023
13667f5
chore Feb 28 sync with dev for CIRCLES-331 - data migration (#977)
imagine-hussain Feb 28, 2023
5e32efd
dev sync - 6 march
imagine-hussain Mar 6, 2023
5b60d61
feat: Added pseudo routes for backend based on FE degree slices (#983)
ui-Auxilary Mar 22, 2023
b3bff94
feat: Replace unschedule reducer with API. (#984)
Bahnschrift Mar 22, 2023
e6138f2
feat: Replace unscheduleAll reducer with API (#985)
Bahnschrift Mar 22, 2023
4cad3f1
Christian/circles 347 create endpoints for degree slice (#1007)
ui-Auxilary Mar 22, 2023
5f40f3d
remove accidental 2 file
imagine-hussain Mar 22, 2023
7bc58ed
Merge branch 'chore/remove-2-file' into CIRCLES-331/user-data-to-backend
imagine-hussain Mar 22, 2023
be6569a
feat(BE/FE): replace updateDegreeLength reducer with API (#981) [CF-414]
lhvy Mar 22, 2023
af02218
chore(tests)/remove autoplanning tests (#1013)
imagine-hussain Mar 22, 2023
f86ebe7
Merge branch 'dev' into CIRCLES-331/user-data-to-backend
imagine-hussain Mar 22, 2023
2662c0d
style(backend): address pylint issues (#1015)
Bahnschrift Mar 23, 2023
c28f3ef
feat: replace addToUnplanned with API (#989)
LukePrior Mar 25, 2023
19df966
react query setup + addToUnscheduled example migration (#1038)
imagine-hussain Apr 2, 2023
405e54c
feat: replace setPlannedCourseToTerm with API [CF-405]
LukePrior Apr 6, 2023
e868243
feat: initial (#999)
LukePrior Apr 8, 2023
4fde722
feat(BE/FE): replace updateStartYear reducer with API [CF-413] (#1010)
lhvy Apr 11, 2023
5bd4930
feat(BE/FE): replace toggleSummer reducer with API [CF-412] (#991)
lhvy Apr 12, 2023
7fc8ee9
Cf 407/replace update course mark reducer (#990)
martanman Apr 19, 2023
bc4894c
feat: CF-393: Replaced setProgram dispatches with axios requests (#1033)
ui-Auxilary Jun 26, 2023
cc05d77
Migrate Degree Wizard to React Query (#1063)
lhvy Jul 14, 2023
799d40a
React query course selector (#1068)
Basialo Sep 6, 2023
6628c6e
Remove courses dict from planner in backend (#1072)
lhvy Sep 6, 2023
e996e57
add (basically) working backend route (#1090)
martanman Oct 25, 2023
a5e25f1
REAL working staging build! (#1094)
Peedee2002 Feb 4, 2024
7f1acf6
Bring to dev (#1108)
Peedee2002 Mar 29, 2024
fe73070
Merge remote-tracking branch 'origin/dev' into 331-staging
lhvy Apr 5, 2024
5895f20
fix: revert change to ARCHIVED_YEARS
ollibowers Apr 5, 2024
be80df5
Merge pull request #1115 from devsoc-unsw/331-staging-merge
ollibowers Apr 5, 2024
4f5bcf6
fix(backend) Update Python deps and Docker Compose (#1110)
lhvy Apr 6, 2024
dd14866
feat(frontend) Add Unilectives reviews to course selector (#1109)
lhvy Apr 7, 2024
8645869
Fix term planner getting course info across years (#1134)
lhvy Apr 21, 2024
4c7af94
chore(frontend): Upgrade to React Query v5 (#1136)
lhvy Apr 21, 2024
4fd3326
feat/fe/fuzzy to degree search 331 edition (#1133)
imagine-hussain May 8, 2024
f156d7e
feat(backend): Upgrade Python and backend dependencies (#1137)
lhvy May 9, 2024
b6327d3
Feat/fe/quick course add button in search (#1139)
imagine-hussain May 11, 2024
6aed051
feat(frontend): bump antd icons version to 5.3.7 (#1138)
ollibowers May 11, 2024
86b9af8
chore(all): Update dependencies (#1143)
lhvy Jun 9, 2024
d857a1d
Fix term planner for newly created courses (#1146)
lhvy Jun 9, 2024
a4d0d92
Fix imports and types to ensure tests run in CI (#1147)
lhvy Jun 10, 2024
57dd5ce
fix(ci): Bump Python to 3.12 in CI (#1148)
lhvy Jun 10, 2024
a599307
Fix mypy results and enable CI for PRs into 331 (#1149)
lhvy Jun 10, 2024
0976b31
Update Tiktok Link (#1117)
jeremyle56 Jun 19, 2024
02844fb
Add stronger warnings for WAM and exclusion validation (#1142)
lhvy Jun 19, 2024
46a300e
removing the bug feedback button on the degree wizard to make it look…
jacksonwanggg Jun 21, 2024
6c49c0c
clicking progression checker now opens new tab (#1152)
chanfaileui Jun 21, 2024
9e92eb1
fix(fe): Fix 422 errors when changing degree settings (#1155)
lhvy Jul 1, 2024
ae95820
feat/infra/add-env-setup-script (#1159)
imagine-hussain Jul 3, 2024
5c147ae
fix(all): Fix toggle for past term warnings (#1158)
lhvy Jul 3, 2024
9108b32
chore(fe): Fix deprecations and breaking changes in deps (#1154)
lhvy Jul 3, 2024
620cf27
adding the view on unilective on the context menu (#1140)
jacksonwanggg Jul 4, 2024
13de062
fix(course selector): fixed ui of disproportional loading status on f…
pikapiku Jul 5, 2024
1317ffb
Feat/fe/1131/adding link course outline on course selector (#1135)
jacksonwanggg Jul 8, 2024
07c7b1d
fill in missing years in course info (#1160)
martanman Jul 12, 2024
c963065
fix(frontend): added start year resrtrictions (#1161)
Salina-H Jul 12, 2024
843f718
feature(global): auth?!?! USER AUTHENTICATION?!?!?!?! (#1156)
ollibowers Jul 12, 2024
f142dab
fix: boolean check in term planner to ensure types pass (#1162)
ollibowers Jul 12, 2024
abf05fd
style(all): fixing pipelines (#1163)
ollibowers Jul 26, 2024
fe22a61
fix(be): Fix backend tests (#1164)
lhvy Jul 26, 2024
cd736b4
chore(fe): cleanup leftover api requests (#1166)
ollibowers Jul 30, 2024
cb9592e
Split settings across frontend and backend (#1183)
lhvy Aug 18, 2024
5e5eb78
Add support for removing marks from a course (#1186)
lhvy Aug 18, 2024
5efb89a
adding the logout button inline with the welcome to Circles (#1190)
jacksonwanggg Sep 1, 2024
f243acc
fix(api): refactor utility functions to detangle dependencies and red…
ollibowers Sep 1, 2024
851997b
updated scraper to use new api (#1150)
martanman Sep 5, 2024
0305c75
feat(dw): Replace degree wizard dropdown with antd select (#1192)
lhvy Sep 12, 2024
72801cf
feat(api): convert last few routes to use token instead of old models…
ollibowers Sep 12, 2024
ab273fd
infer years forward for term planner for years we don't have data for…
martanman Sep 19, 2024
43a007a
feat(all): Add JSON import and export support (#1194)
lhvy Oct 16, 2024
a3b127a
feat(be): Add support for new degrees (#1151)
lhvy Oct 17, 2024
0d90f2d
2025 scraping wooo (#1198)
martanman Oct 24, 2024
556eb69
feat: Add support for user data migration from local storage (#1199)
lhvy Oct 24, 2024
37d4e0f
fix ethics prereqs (#1201)
martanman Oct 24, 2024
3a4ce84
fix: Disable guest accounts (#1203)
lhvy Nov 11, 2024
d9440ad
frontend(queries): refactor to unified query interface to help mainta…
ollibowers Nov 14, 2024
b819165
hotfix(tp+oidc): fixed the wrong keys in optimistic mutations and add…
ollibowers Nov 17, 2024
d30ef21
Added ci pipeline for staging branch
ChinoGoblino Nov 17, 2024
aa7aa00
Merge branch '331-staging' of github.com:devsoc-unsw/circles into 331…
ChinoGoblino Nov 17, 2024
6114cc7
fix: Altered deployment label from prod to staging
ChinoGoblino Nov 17, 2024
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
627 changes: 0 additions & 627 deletions .github/workflows/.pylintrc

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unit Tests

on:
pull_request:
branches: [dev, main]
branches: [dev, main, CIRCLES-331/user-data-to-backend, 331-staging]

jobs:
event_file:
Expand All @@ -23,10 +23,10 @@ jobs:
steps:
- name: Checking out repository
uses: actions/checkout@v3
- name: Set up Python (latest)
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.10.5"
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -59,10 +59,10 @@ jobs:
steps:
- name: Checking out repository
uses: actions/checkout@v3
- name: Set up Python (latest)
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.12"
- name: Run frontend tests
run: |
cd frontend
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pylinter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: Pylint

on:
pull_request:
branches: [dev, main]
branches: [dev, main, CIRCLES-331/user-data-to-backend]

jobs:
build:
Expand All @@ -23,10 +23,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.12"

- name: Install dependencies
run: |
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ eggs/
.eggs/
lib/
lib64/
lib64
parts/
sdist/
var/
Expand Down Expand Up @@ -72,5 +73,9 @@ tmp.*
.idea
**/Session.vim

# secret
SECRET
secret.json
secret.env
# "sensitive" data (i.e. raw zID)
backend/data/scrapers/enrolmentDataRaw.json
9 changes: 6 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ disable=import-error, # allow import from folder.file instea
global-statement, # allow use of globals. Used for filepaths and configs
too-few-public-methods, # need classes with zero public methods as abstract objects
duplicate-code, # Code duplication due to progtype1. TODO: Fix on complete refactor
no-name-in-module # seems to be similar to import-error
no-name-in-module, # seems to be similar to import-error
missing-module-docstring, # allow for missing module docstrings, democratially ignored
useless-parent-delegation # allow for methods that just return super().method()
# parameter-unpacking,
# unpacking-in-except,
# old-raise-syntax,
Expand Down Expand Up @@ -449,11 +451,12 @@ good-names=i,
k,
ex,
Run,
_
_,
f

# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
good-names-rgxs=
good-names-rgxs=^([A-Z]{4})_FIXES

# Include a hint for the correct naming format with invalid-name.
include-naming-hint=no
Expand Down
1 change: 1 addition & 0 deletions .tokeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**.json
10 changes: 5 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"eslint.workingDirectories": [
"frontend"
],
"VitestRunner.executionArg": "npx --prefix frontend",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.cwd": "${workspaceFolder}/backend",
Expand All @@ -10,10 +11,9 @@
"**/.hypothesis": true,
"**/.pytest_cache": true
},
"python.linting.mypyEnabled": true,
"python.linting.mypyArgs": [
"--config-file=${workspaceFolder}/backend/mypy.ini"
],
"python.analysis.typeCheckingMode": "basic",
"files.eol": "\n"
"[python]": {
"editor.formatOnSave": false
},
"python.analysis.autoImportCompletions": true
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ We are a team that is part of DevSoc! See [TEAM.md](./TEAM.md) for more informat

Also, special thanks to James Ji, Vincent Xiao, Hayes Choy for being the first team to work on and inspire Circles :)

[For further development documentation, visit our confluence page!](https://devsoc.atlassian.net/wiki/spaces/C/pages/756966/About+Circles)
Information to run Circles on your local machine are available in the [frontend](./frontend/README.md) and [backend](./backend/README.md) `README.md` files.

For further development documentation, visit our [confluence page](https://devsoc.atlassian.net/wiki/spaces/C/pages/756966/About+Circles)!
22 changes: 11 additions & 11 deletions backend/algorithms/autoplanning.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
""" an autoplanning solver which takes in courses and spits a plan """
from pprint import pprint
from typing import Tuple
from ortools.sat.python import cp_model # type: ignore

from algorithms.objects.course import Course
from algorithms.objects.user import User
from ortools.sat.python import cp_model # type: ignore
from server.routers.model import CONDITIONS

# Inspired by AbdallahS's code here: https://github.com/AbdallahS/planner
# with help from Martin and MJ :)

Expand Down Expand Up @@ -51,13 +53,13 @@ def autoplan(courses: list[Course], user: User, start: Tuple[int, int], end: Tup
model.Add(v == index).OnlyEnforceIf(b)
model.Add(v != index).OnlyEnforceIf(b.Not())
boolean_indexes.append(b)
# if the course is in term 'index', only allow 0 to m UOC to exist in that term.
# if the course is in term 'index', only allow 0 to m UOC to exist in that term.
model.AddReservoirConstraintWithActive(
variables,
list(map_var_to_course(courses, var).uoc for var in variables), # this fills the resovoir by UoC units if active
boolean_indexes, # a course is only active if in term 'index'
list(map_var_to_course(courses, var).uoc for var in variables), # this fills the resovoir by UoC units if active
boolean_indexes, # a course is only active if in term 'index'
0,
m # uoc_max
m # uoc_max
)

# 4. enforce prereqs, only if not locked by user
Expand All @@ -73,11 +75,10 @@ def autoplan(courses: list[Course], user: User, start: Tuple[int, int], end: Tup
map_course_to_var(course, variables)
)
solver = cp_model.CpSolver()
status: int = solver.Solve(model)
if status == 3 or status == 1:
raise Exception(f'your courses are impossible to put in these terms! Error code: {status}')
else:
return [(v.Name(), convert_to_term_year(solver.Value(v), start)) for v in variables]
status = solver.Solve(model)
if status in [cp_model.MODEL_INVALID, cp_model.INFEASIBLE]:
raise ValueError(f'your courses are impossible to put in these terms! Error code: {status}')
return [(v.Name(), convert_to_term_year(solver.Value(v), start)) for v in variables]


if __name__ == '__main__':
Expand Down Expand Up @@ -115,4 +116,3 @@ def autoplan(courses: list[Course], user: User, start: Tuple[int, int], end: Tup
(2023, 3),
[12, 20, 20, 20, 12, 20, 20, 20, 10, 20, 20, 20]
))

40 changes: 18 additions & 22 deletions backend/algorithms/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@
This should be run from the backend directory or via runprocessors
"""

from functools import reduce
import operator
import re
from functools import reduce
from typing import Any, Literal

from algorithms.cache.cache_config import (CACHE_CONFIG, CACHED_EQUIVALENTS_FILE,
CACHED_EXCLUSIONS_FILE,
CACHED_WARNINGS_FILE,
CONDITIONS_PROCESSED_FILE,
COURSE_MAPPINGS_FILE,
COURSES_PROCESSED_FILE,
MAPPINGS_FILE,
PROGRAM_MAPPINGS_FILE,
from algorithms.cache.cache_config import (CACHE_CONFIG, CACHED_EQUIVALENTS_FILE, CACHED_EXCLUSIONS_FILE,
CACHED_WARNINGS_FILE, CONDITIONS_PROCESSED_FILE, COURSE_MAPPINGS_FILE,
COURSES_PROCESSED_FILE, MAPPINGS_FILE, PROGRAM_MAPPINGS_FILE,
PROGRAMS_FORMATTED_FILE)
from data.utility.data_helpers import read_data, write_data


def cache_equivalents():
"""
Reads from processed courses and stores the exclusions in a map mapping
Expand Down Expand Up @@ -95,36 +91,36 @@ def cache_mappings():
def tokeniseFaculty(Faculty):
faculty_token = "F "
if re.search("Faculty of.+", Faculty):
match_object = re.search("(?<=Faculty\sof\s)[^\s\n\,]+", Faculty)
match_object = re.search(r"(?<=Faculty\sof\s)[^\s\n\,]+", Faculty)
elif re.search("UNSW", Faculty):
match_object = re.search(r"(?<=UNSW\s)[^\s\n\,]+", Faculty)
else:
match_object = re.search("^([\w]+)", Faculty)
match_object = re.search(r"^([\w]+)", Faculty)
if match_object is None:
raise Exception(f'no match found for faculty: {Faculty}')
raise KeyError(f'no match found for faculty: {Faculty}')
match = match_object.group()
faculty_token += match
return faculty_token

# Tokenise faculty using regex, e.g 'School of Psychology' -> 'S Psychology'
def tokeniseSchool(School):
school_token = "S "
if re.search("School\sof\sthe.+", School):
match_object = re.search("(?<=School\sof\sthe\s)[^\s\n\,]+", School)
elif re.search("School\sof\s.+", School):
match_object = re.search("(?<=School\sof\s)[^\s\n\,]+", School)
if re.search(r"School\sof\sthe.+", School):
match_object = re.search(r"(?<=School\sof\sthe\s)[^\s\n\,]+", School)
elif re.search(r"School\sof\s.+", School):
match_object = re.search(r"(?<=School\sof\s)[^\s\n\,]+", School)
elif re.search("^(UC)", School):
match_object = re.search("(?<=UC\s)[^\s\n\,]+", School)
match_object = re.search(r"(?<=UC\s)[^\s\n\,]+", School)
if match_object is None:
raise Exception(f'no match found for school: {School}')
raise KeyError(f'no match found for school: {School}')
match = school_token + "UC-" + match_object.group()
return match
elif re.search("UNSW", School):
match_object = re.search("(?<=UNSW\s)[^\s\n\,]+", School)
match_object = re.search(r"(?<=UNSW\s)[^\s\n\,]+", School)
else:
match_object = re.search("^([\w]+)", School)
match_object = re.search(r"^([\w]+)", School)
if match_object is None:
raise Exception(f'no match found for school: {School}')
raise KeyError(f'no match found for school: {School}')
match = match_object.group()
school_token += match
return school_token
Expand Down Expand Up @@ -172,7 +168,7 @@ def cache_program_mappings():

keyword_codes: dict[str, list[str]] = read_data(CACHE_CONFIG)

mappings : dict = { # TODO: make more strict
mappings : dict = { # TODO: make more strict
code: {} for code
in reduce(operator.add, keyword_codes.values())
}
Expand Down
51 changes: 10 additions & 41 deletions backend/algorithms/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,22 @@
import re
from typing import Optional, Tuple

from algorithms.objects.categories import (
Category,
CompositeCategory,
ClassCategory,
CourseCategory,
FacultyCategory,
LevelCategory,
LevelCourseCategory,
SchoolCategory,
)
from algorithms.objects.conditions import (
CompositeCondition,
CoresCondition,
CoreqCourseCondition,
CourseCondition,
CourseExclusionCondition,
GradeCondition,
ProgramCondition,
ProgramExclusionCondition,
ProgramTypeCondition,
SpecialisationCondition,
UOCCondition,
WAMCondition,
)
from algorithms.objects.helper import (
Logic,
get_grade,
get_uoc,
get_wam,
is_course,
is_grade,
is_program,
is_program_type,
is_specialisation,
is_uoc,
is_wam,
get_level_category,
get_course_category
)
from algorithms.objects.categories import (Category, ClassCategory, CompositeCategory, CourseCategory, FacultyCategory,
LevelCategory, LevelCourseCategory, SchoolCategory)
from algorithms.objects.conditions import (CompositeCondition, CoreqCourseCondition, CoresCondition, CourseCondition,
CourseExclusionCondition, GradeCondition, ProgramCondition,
ProgramExclusionCondition, ProgramTypeCondition, SpecialisationCondition,
UOCCondition, WAMCondition)
from algorithms.objects.helper import (Logic, get_course_category, get_grade, get_level_category, get_uoc, get_wam,
is_course, is_grade, is_program, is_program_type, is_specialisation, is_uoc,
is_wam)

# Load in cached exclusions
CACHED_EXCLUSIONS_PATH = "algorithms/cache/exclusions.json"
with open(CACHED_EXCLUSIONS_PATH, "r", encoding="utf8") as f:
CACHED_EXCLUSIONS = json.load(f)

def create_category(tokens) -> Tuple[Optional[Category], int]: # pylint: disable=too-many-return-statements
def create_category(tokens) -> Tuple[Optional[Category], int]: # pylint: disable=too-many-return-statements
"""
Given a list of tokens starting from after the connector keyword, create
and return the category object matching the category, as well as the current index
Expand Down Expand Up @@ -268,4 +238,3 @@ def make_condition(tokens, first=False, course=None) -> Tuple[Optional[Composite
result.add_condition(cond)

return result, index

10 changes: 5 additions & 5 deletions backend/algorithms/create_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pickle
import re
from typing import Dict, List

from algorithms.objects.categories import Category, GenEdCategory, LevelCategory, LevelCourseCategory
from algorithms.objects.conditions import Condition, CoresCondition, UOCCondition
from algorithms.objects.helper import read_data
Expand All @@ -21,7 +22,7 @@ class UnparseableError(Exception):
The given token cannot be parsed
"""
def __init__(self, tokens: List[str] | Dict):
super().__init__("Unparseable tokens: {}".format(tokens))
super().__init__(f"Unparseable tokens: {tokens}")

def process_program_conditions() -> None:
"""
Expand Down Expand Up @@ -84,7 +85,7 @@ def create_maturity_restriction(tokens: Dict[str, List[str]]) -> ProgramRestrict
)

def create_dependency_condition(tokens: List[str]) -> Condition:
"""
r"""
Creates a dependent condition from the tokens.

Dependency Types:
Expand All @@ -107,7 +108,7 @@ def create_dependency_condition(tokens: List[str]) -> Condition:
# Maybe assert that this is the end?

# Matching LevelCategory
if re.match("L\d", base_token):
if re.match(r"L\d", base_token):
index += 1
level = int(base_token[1:])
level_category = LevelCategory(level)
Expand Down Expand Up @@ -135,7 +136,7 @@ def create_dependency_condition(tokens: List[str]) -> Condition:


def create_dependent_condition(tokens: List[str]) -> Category:
"""
r"""
Creates a dependency condition from the tokens.

Need to worry about:
Expand All @@ -160,4 +161,3 @@ def create_dependent_condition(tokens: List[str]) -> Category:

if __name__ == "__main__":
create_all_program_conditions()

Loading
Loading