-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fetching grades, terms, courses and api documentation
- Loading branch information
1 parent
b0d8c7f
commit b06d084
Showing
19 changed files
with
546 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,9 @@ Services | |
:members: | ||
|
||
|
||
Helper | ||
^^^^^^ | ||
|
||
.. autoclass:: usos_api.helper.APIHelper | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import TYPE_CHECKING, List | ||
|
||
from usos_api.models import CourseEdition, Grade | ||
|
||
if TYPE_CHECKING: | ||
from usos_api import USOSClient | ||
|
||
|
||
class APIHelper: | ||
def __init__(self, client: "USOSClient"): | ||
self.client = client | ||
|
||
async def get_user_end_grades_with_weights( | ||
self, current_term_only: bool = False | ||
) -> List[Grade]: | ||
""" | ||
Get user end grades with weights. | ||
:param current_term_only: If True, only consider the current term. | ||
:return: A list of user end grades with weights. | ||
""" | ||
ects_by_term = await self.client.course_service.get_user_courses_ects() | ||
terms = await self.client.term_service.get_terms(list(ects_by_term.keys())) | ||
term_ids = [ | ||
term.id for term in terms if not current_term_only or term.is_current | ||
] | ||
course_ids = [ | ||
course_id | ||
for term_id in term_ids | ||
for course_id in ects_by_term[term_id].keys() | ||
] | ||
|
||
courses = { | ||
course.id: course | ||
for course in await self.client.course_service.get_courses(course_ids) | ||
} | ||
grades_by_term = await self.client.grade_service.get_grades_by_terms(term_ids) | ||
|
||
user_grades = [] | ||
for term in terms: | ||
if term.id not in term_ids: | ||
continue | ||
for course_id, ects in ects_by_term[term.id].items(): | ||
grades = ( | ||
grades_by_term[term.id].get(course_id, {}).get("course_grades", []) | ||
) | ||
for grade in grades: | ||
grade.weight = ects | ||
grade.course_edition = CourseEdition( | ||
course=courses[course_id], term=term | ||
) | ||
user_grades.append(grade) | ||
|
||
return user_grades |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import Any | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class AuthOptions(BaseModel): | ||
consumer: str | None = None | ||
token: str | None = None | ||
administrative_only: bool | None = None | ||
ssl_required: bool | None = None | ||
|
||
|
||
class Argument(BaseModel): | ||
name: str | None = None | ||
is_required: bool | None = None | ||
is_deprecated: bool | None = None | ||
default_value: Any | None = None | ||
description: str | None = None | ||
|
||
|
||
class ResultField(BaseModel): | ||
name: str | None = None | ||
description: str | None = None | ||
is_primary: bool | None = None | ||
is_secondary: bool | None = None | ||
|
||
|
||
class DeprecatedInfo(BaseModel): | ||
deprecated_by: str | None = None | ||
present_until: str | None = None | ||
|
||
|
||
class APIMethodInfo(BaseModel): | ||
name: str | None = None | ||
short_name: str | None = None | ||
description: str | None = None | ||
brief_description: str | None = None | ||
ref_url: str | None = None | ||
auth_options: AuthOptions | None = None | ||
scopes: list[str] | None = None | ||
arguments: list[Argument] | None = None | ||
returns: str | None = None | ||
errors: str | None = None | ||
result_fields: list[ResultField] | None = None | ||
beta: bool | None = None | ||
deprecated: DeprecatedInfo | None = None | ||
admin_access: bool | None = None | ||
is_internal: bool | None = None | ||
|
||
|
||
class APIMethodIndexItem(BaseModel): | ||
name: str | None = None | ||
brief_description: str | None = None | ||
|
||
|
||
class APIModuleInfo(BaseModel): | ||
name: str | None = None | ||
title: str | None = None | ||
brief_description: str | None = None | ||
description: str | None = None | ||
submodules: list[str] | None = None | ||
methods: list[str] | None = None | ||
beta: bool | None = None | ||
|
||
|
||
class ScopeInfo(BaseModel): | ||
key: str | None = None | ||
developers_description: str | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.