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(all): Add JSON import and export support #1194

Merged
merged 6 commits into from
Oct 16, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ secret.json
secret.env
# "sensitive" data (i.e. raw zID)
backend/data/scrapers/enrolmentDataRaw.json

# People keep making these by accident
package-lock.json
9 changes: 9 additions & 0 deletions backend/server/db/helpers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class UserDegreeStorage(BaseModel):
programCode: str
specs: List[str]

class UserCourseMinimal(BaseModel):
mark: Union[Literal['SY', 'FL', 'PS', 'CR', 'DN', 'HD'], int, None]
ignoreFromProgression: bool

class UserCourseStorage(BaseModel):
code: str
Expand Down Expand Up @@ -52,6 +55,12 @@ class _BaseUserStorage(BaseModel):
# NOTE: could also put uid here if we want
guest: bool

class UserImport(BaseModel):
degree: UserDegreeStorage
courses: dict[str, UserCourseMinimal]
planner: UserPlannerStorage
settings: UserSettingsStorage

class UserStorage(_BaseUserStorage):
setup: Literal[True] = True
degree: UserDegreeStorage
Expand Down
210 changes: 202 additions & 8 deletions backend/server/example_input/example_local_storage_data.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"empty_year": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [ "COMPA1" ]
},
"planner": {
Expand All @@ -28,11 +28,16 @@
"startYear": 2020,
"isSummerEnabled": true,
"lockedTerms": {}
},
"courses": {},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"summer_term": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [ "COMPA1" ]
},
"planner": {
Expand All @@ -58,11 +63,29 @@
"startYear": 2020,
"isSummerEnabled": true,
"lockedTerms": {}
},
"courses": {
"COMP1511": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1141": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1081": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"no_uoc": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [ "COMPA1" ]
},
"planner": {
Expand All @@ -84,11 +107,41 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"COMP1511": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1141": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1081": {
"mark": null,
"ignoreFromProgression": false
},
"COMP1521": {
"mark": null,
"ignoreFromProgression": false
},
"COMP2511": {
"mark": null,
"ignoreFromProgression": false
},
"COMP4128": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"suppress_warning": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [ "COMPA1" ]
},
"planner": {
Expand All @@ -110,11 +163,41 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"COMP1511": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1141": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1081": {
"mark": null,
"ignoreFromProgression": false
},
"COMP1521": {
"mark": null,
"ignoreFromProgression": false
},
"COMP2511": {
"mark": null,
"ignoreFromProgression": false
},
"COMP4128": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"simple_year": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [ "COMPA1" ]
},
"planner": {
Expand Down Expand Up @@ -149,11 +232,49 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"COMP1511": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1141": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1081": {
"mark": null,
"ignoreFromProgression": false
},
"COMP1521": {
"mark": null,
"ignoreFromProgression": false
},
"COMP1531": {
"mark": null,
"ignoreFromProgression": false
},
"COMP2521": {
"mark": null,
"ignoreFromProgression": false
},
"ENGG2600": {
"mark": null,
"ignoreFromProgression": false
},
"COMP6447": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"out_of_order": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [ "COMPA1" ]
},
"planner": {
Expand Down Expand Up @@ -184,6 +305,20 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"MATH1241": {
"mark": null,
"ignoreFromProgression": false
},
"MATH1141": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"sample_user_1": {
Expand Down Expand Up @@ -218,6 +353,20 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"COMP1511": {
"mark": 90,
"ignoreFromProgression": false
},
"COMP1521": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"sample_user_2": {
Expand Down Expand Up @@ -252,11 +401,41 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"COMP1511": {
"mark": 90,
"ignoreFromProgression": false
},
"COMP1521": {
"mark": 90,
"ignoreFromProgression": false
},
"COMP1531": {
"mark": 90,
"ignoreFromProgression": false
},
"COMP2521": {
"mark": 85,
"ignoreFromProgression": false
},
"COMP3231": {
"mark": 80,
"ignoreFromProgression": false
},
"COMP9242": {
"mark": 75,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"sample_user_one_math": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [
"COMPA1",
"ACCTA2"
Expand Down Expand Up @@ -286,11 +465,21 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {
"MATH1131": {
"mark": null,
"ignoreFromProgression": false
}
},
"settings": {
"showMarks": false,
"hiddenYears": []
}
},
"sample_user_no_courses": {
"degree": {
"programCode": "3707",
"programCode": "3778",
"specs": [
"COMPA1",
"ACCTA2"
Expand Down Expand Up @@ -320,6 +509,11 @@
"startYear": 2020,
"isSummerEnabled": false,
"lockedTerms": {}
},
"courses": {},
"settings": {
"showMarks": false,
"hiddenYears": []
}
}
}
6 changes: 0 additions & 6 deletions backend/server/routers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ class Storage(TypedDict):
courses: dict[str, CourseStorage]
settings: SettingsStorage

class LocalStorage(BaseModel):
model_config = ConfigDict(extra='forbid')

degree: DegreeLocalStorage
planner: PlannerLocalStorage

class StartYear(BaseModel):
model_config = ConfigDict(extra='forbid')

Expand Down
Loading
Loading