usos-api 0.3.4__tar.gz → 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {usos_api-0.3.4 → usos_api-0.4.1}/PKG-INFO +1 -1
- {usos_api-0.3.4 → usos_api-0.4.1}/docs/conf.py +9 -2
- {usos_api-0.3.4 → usos_api-0.4.1}/pyproject.toml +1 -1
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/auth.py +2 -4
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/client.py +3 -0
- usos_api-0.4.1/usos_api/helper.py +83 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/__init__.py +48 -0
- usos_api-0.4.1/usos_api/models/exam_report.py +265 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/grade.py +18 -4
- usos_api-0.4.1/usos_api/models/usos_bool.py +18 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/__init__.py +2 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/courses.py +23 -2
- usos_api-0.4.1/usos_api/services/exam_reports.py +500 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/groups.py +5 -3
- {usos_api-0.3.4 → usos_api-0.4.1}/uv.lock +1 -1
- usos_api-0.3.4/usos_api/helper.py +0 -45
- {usos_api-0.3.4 → usos_api-0.4.1}/.github/workflows/publish.yml +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/.gitignore +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/.readthedocs.yaml +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/README.md +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/docs/Makefile +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/docs/full-docs.rst +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/docs/index.rst +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/docs/make.bat +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/docs/quickstart.rst +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/run.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/__init__.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/connection.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/exceptions.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/logger.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/api_documentation.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/consumer.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/course.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/group.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/lang_dict.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/programme.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/registration.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/term.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/models/user.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/api_documentation.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/api_server.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/grades.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/registrations.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/terms.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/services/users.py +0 -0
- {usos_api-0.3.4 → usos_api-0.4.1}/usos_api/utils/__init__.py +0 -0
|
@@ -3,17 +3,24 @@
|
|
|
3
3
|
# For the full list of built-in configuration values, see the documentation:
|
|
4
4
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
5
|
|
|
6
|
+
import datetime
|
|
7
|
+
|
|
6
8
|
# -- Project information -----------------------------------------------------
|
|
7
9
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
8
10
|
import os
|
|
9
11
|
import sys
|
|
12
|
+
from importlib.metadata import version as get_version
|
|
10
13
|
|
|
11
14
|
sys.path.insert(0, os.path.abspath(".."))
|
|
12
15
|
|
|
13
16
|
project = "USOS API"
|
|
14
|
-
|
|
17
|
+
|
|
15
18
|
author = "Antoni Czaplicki"
|
|
16
|
-
release = "
|
|
19
|
+
release = get_version("usos-api")
|
|
20
|
+
version = release
|
|
21
|
+
|
|
22
|
+
current_year = datetime.datetime.now().year
|
|
23
|
+
copyright = f"{current_year}, {author}"
|
|
17
24
|
|
|
18
25
|
# -- General configuration ---------------------------------------------------
|
|
19
26
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
@@ -101,7 +101,7 @@ class AuthManager:
|
|
|
101
101
|
self._request_token_secret = data["oauth_token_secret"]
|
|
102
102
|
self._oauth_client.resource_owner_key = self._request_token
|
|
103
103
|
self._oauth_client.resource_owner_secret = self._request_token_secret
|
|
104
|
-
_LOGGER.debug(
|
|
104
|
+
_LOGGER.debug("New request token generated")
|
|
105
105
|
|
|
106
106
|
async def get_authorization_url(
|
|
107
107
|
self, callback_url: str, confirm_user: bool = False
|
|
@@ -139,9 +139,7 @@ class AuthManager:
|
|
|
139
139
|
await self._handle_response_errors(response)
|
|
140
140
|
data = dict(urllib.parse.parse_qsl(await response.text()))
|
|
141
141
|
self.load_access_token(data["oauth_token"], data["oauth_token_secret"])
|
|
142
|
-
_LOGGER.debug(
|
|
143
|
-
f"Authorization successful, received access token"
|
|
144
|
-
)
|
|
142
|
+
_LOGGER.debug("Authorization successful, received access token")
|
|
145
143
|
return self.access_token, self.access_token_secret
|
|
146
144
|
except AttributeError as e:
|
|
147
145
|
if e.args[0] == "'NoneType' object has no attribute 'post'":
|
|
@@ -7,6 +7,7 @@ from .services import (
|
|
|
7
7
|
APIDocumentationService,
|
|
8
8
|
APIServerService,
|
|
9
9
|
CourseService,
|
|
10
|
+
ExamReportService,
|
|
10
11
|
GradeService,
|
|
11
12
|
GroupService,
|
|
12
13
|
RegistrationService,
|
|
@@ -28,6 +29,7 @@ class USOSClient:
|
|
|
28
29
|
:var CourseService course_service: The course service.
|
|
29
30
|
:var TermService term_service: The term service.
|
|
30
31
|
:var GradeService grade_service: The grade service.
|
|
32
|
+
:var ExamReportService exam_report_service: The exam report service.
|
|
31
33
|
:var RegistrationService registration_service: The registration service.
|
|
32
34
|
|
|
33
35
|
:ivar USOSAPIConnection connection: The connection to the USOS API, used for making requests.
|
|
@@ -56,6 +58,7 @@ class USOSClient:
|
|
|
56
58
|
self.course_service = CourseService(self.connection)
|
|
57
59
|
self.term_service = TermService(self.connection)
|
|
58
60
|
self.grade_service = GradeService(self.connection)
|
|
61
|
+
self.exam_report_service = ExamReportService(self.connection)
|
|
59
62
|
self.api_server_service = APIServerService(self.connection)
|
|
60
63
|
self.api_documentation_service = APIDocumentationService(self.connection)
|
|
61
64
|
self.registration_service = RegistrationService(self.connection)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, List
|
|
2
|
+
|
|
3
|
+
from usos_api.models import CourseEdition, Grade, UserExamReportsByTerm
|
|
4
|
+
from usos_api.services.courses import CourseEctsByTerm
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from usos_api import USOSClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class APIHelper:
|
|
11
|
+
def __init__(self, client: "USOSClient"):
|
|
12
|
+
self.client = client
|
|
13
|
+
|
|
14
|
+
async def get_user_end_grades_with_weights(
|
|
15
|
+
self, current_term_only: bool = False
|
|
16
|
+
) -> List[Grade]:
|
|
17
|
+
"""
|
|
18
|
+
Get user end grades with weights.
|
|
19
|
+
|
|
20
|
+
:param current_term_only: If True, only consider the current term.
|
|
21
|
+
:return: A list of user end grades with weights.
|
|
22
|
+
"""
|
|
23
|
+
ects_by_term = await self.client.course_service.get_user_courses_ects()
|
|
24
|
+
terms = await self.client.term_service.get_terms(list(ects_by_term.keys()))
|
|
25
|
+
term_ids = [
|
|
26
|
+
term.id for term in terms if not current_term_only or term.is_ongoing
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
grades_by_term = await self.client.grade_service.get_grades_by_terms(term_ids)
|
|
30
|
+
|
|
31
|
+
user_grades = []
|
|
32
|
+
for term in terms:
|
|
33
|
+
if term.id not in term_ids:
|
|
34
|
+
continue
|
|
35
|
+
for course_id, ects in ects_by_term[term.id].items():
|
|
36
|
+
grades = (
|
|
37
|
+
grades_by_term[term.id].get(course_id, {}).get("course_grades", [])
|
|
38
|
+
)
|
|
39
|
+
for grade in grades:
|
|
40
|
+
grade.weight = ects
|
|
41
|
+
grade.course_edition = CourseEdition(
|
|
42
|
+
course_id=course_id, term_id=term.id
|
|
43
|
+
)
|
|
44
|
+
user_grades.append(grade)
|
|
45
|
+
|
|
46
|
+
return user_grades
|
|
47
|
+
|
|
48
|
+
async def get_user_exam_reports_with_ects(
|
|
49
|
+
self,
|
|
50
|
+
term_ids: list[str] | str | None = None,
|
|
51
|
+
fields: list[str] | str | None = None,
|
|
52
|
+
) -> tuple[CourseEctsByTerm, UserExamReportsByTerm]:
|
|
53
|
+
"""
|
|
54
|
+
Fetch raw user exam reports together with course ECTS weights.
|
|
55
|
+
|
|
56
|
+
This helper intentionally does not shape grades for a specific app. It only
|
|
57
|
+
coordinates the USOS calls that are usually needed together.
|
|
58
|
+
|
|
59
|
+
:param term_ids: Academic term IDs. If omitted, terms from ECTS data are used.
|
|
60
|
+
:param fields: Selector of exam report fields you are interested in.
|
|
61
|
+
:return: ``(ects_by_term, reports_by_term)`` for the selected terms.
|
|
62
|
+
"""
|
|
63
|
+
all_ects_by_term = await self.client.course_service.get_user_courses_ects()
|
|
64
|
+
selected_term_ids = _term_ids(term_ids) or list(all_ects_by_term.keys())
|
|
65
|
+
if not selected_term_ids:
|
|
66
|
+
return {}, {}
|
|
67
|
+
|
|
68
|
+
reports_by_term = await self.client.exam_report_service.get_user_exam_reports(
|
|
69
|
+
term_ids=selected_term_ids,
|
|
70
|
+
fields=fields,
|
|
71
|
+
)
|
|
72
|
+
ects_by_term = {
|
|
73
|
+
term_id: all_ects_by_term.get(term_id, {}) for term_id in selected_term_ids
|
|
74
|
+
}
|
|
75
|
+
return ects_by_term, reports_by_term
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _term_ids(term_ids: list[str] | str | None) -> list[str]:
|
|
79
|
+
if term_ids is None:
|
|
80
|
+
return []
|
|
81
|
+
if isinstance(term_ids, str):
|
|
82
|
+
return [term_ids]
|
|
83
|
+
return term_ids
|
|
@@ -16,6 +16,31 @@ from .course import (
|
|
|
16
16
|
CourseEditionConducted,
|
|
17
17
|
CourseUnit,
|
|
18
18
|
)
|
|
19
|
+
from .exam_report import (
|
|
20
|
+
ExamReport,
|
|
21
|
+
ExamReport2,
|
|
22
|
+
ExamReport2ClassGroup,
|
|
23
|
+
ExamReport2Session,
|
|
24
|
+
ExamReport2StudentGrade,
|
|
25
|
+
ExamReport2UserGrade,
|
|
26
|
+
ExamReportCourse,
|
|
27
|
+
ExamReportCourseUnit,
|
|
28
|
+
ExamReportGradeDistributionItem,
|
|
29
|
+
ExamReportIssuerGrade,
|
|
30
|
+
ExamReportSessionAccess,
|
|
31
|
+
ExamReportType,
|
|
32
|
+
ExternalObject,
|
|
33
|
+
ExamReportSession,
|
|
34
|
+
GradeType,
|
|
35
|
+
GradeValue,
|
|
36
|
+
LegacyCourseEditionExamReport,
|
|
37
|
+
LegacyUserExamReportsByTerm,
|
|
38
|
+
RawUserExamReportsByTerm,
|
|
39
|
+
UserExamReportsByTerm,
|
|
40
|
+
parse_legacy_course_edition_exam_report,
|
|
41
|
+
parse_legacy_user_exam_reports,
|
|
42
|
+
parse_user_exam_reports,
|
|
43
|
+
)
|
|
19
44
|
from .grade import Grade
|
|
20
45
|
from .group import Group
|
|
21
46
|
from .lang_dict import LangDict
|
|
@@ -72,9 +97,32 @@ __all__ = [
|
|
|
72
97
|
"Grade",
|
|
73
98
|
"Course",
|
|
74
99
|
"CourseEditionConducted",
|
|
100
|
+
"ExternalObject",
|
|
101
|
+
"ExamReport2",
|
|
102
|
+
"ExamReport2ClassGroup",
|
|
103
|
+
"ExamReport2Session",
|
|
104
|
+
"ExamReport2StudentGrade",
|
|
105
|
+
"ExamReport2UserGrade",
|
|
106
|
+
"ExamReport",
|
|
107
|
+
"ExamReportCourse",
|
|
108
|
+
"ExamReportCourseUnit",
|
|
109
|
+
"ExamReportGradeDistributionItem",
|
|
110
|
+
"ExamReportIssuerGrade",
|
|
111
|
+
"ExamReportSession",
|
|
112
|
+
"ExamReportSessionAccess",
|
|
113
|
+
"ExamReportType",
|
|
114
|
+
"GradeType",
|
|
115
|
+
"GradeValue",
|
|
75
116
|
"Term",
|
|
76
117
|
"Consumer",
|
|
77
118
|
"CourseUnit",
|
|
119
|
+
"UserExamReportsByTerm",
|
|
120
|
+
"RawUserExamReportsByTerm",
|
|
121
|
+
"LegacyUserExamReportsByTerm",
|
|
122
|
+
"LegacyCourseEditionExamReport",
|
|
123
|
+
"parse_user_exam_reports",
|
|
124
|
+
"parse_legacy_user_exam_reports",
|
|
125
|
+
"parse_legacy_course_edition_exam_report",
|
|
78
126
|
"AuthOptions",
|
|
79
127
|
"Argument",
|
|
80
128
|
"ResultField",
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any, Mapping, TypeAlias
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, ConfigDict, field_validator
|
|
5
|
+
|
|
6
|
+
from .lang_dict import LangDict
|
|
7
|
+
from .usos_bool import USOSBool
|
|
8
|
+
from .user import User
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ExternalObject(BaseModel):
|
|
12
|
+
model_config = ConfigDict(extra="allow")
|
|
13
|
+
|
|
14
|
+
id: str | int | None = None
|
|
15
|
+
name: LangDict | str | None = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class GradeValue(BaseModel):
|
|
19
|
+
grade_type: ExternalObject | None = None
|
|
20
|
+
order_key: str | int | None = None
|
|
21
|
+
symbol: str | None = None
|
|
22
|
+
passes: USOSBool | None = None
|
|
23
|
+
decimal_value: float | None = None
|
|
24
|
+
name: LangDict | None = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class GradeType(BaseModel):
|
|
28
|
+
id: str | None = None
|
|
29
|
+
name: LangDict | None = None
|
|
30
|
+
values: list[GradeValue] | None = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ExamReportType(BaseModel):
|
|
34
|
+
id: str | None = None
|
|
35
|
+
name: LangDict | None = None
|
|
36
|
+
grade_type: GradeType | None = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ExamReport2StudentGrade(BaseModel):
|
|
40
|
+
grade_value: GradeValue | None = None
|
|
41
|
+
comment: str | None = None
|
|
42
|
+
private_comment: str | None = None
|
|
43
|
+
user: ExternalObject | None = None
|
|
44
|
+
grader: ExternalObject | None = None
|
|
45
|
+
last_updated: datetime | None = None
|
|
46
|
+
is_editable: USOSBool | None = None
|
|
47
|
+
resignation: USOSBool | None = None
|
|
48
|
+
inactive_links: USOSBool | None = None
|
|
49
|
+
why_cannot_edit: str | None = None
|
|
50
|
+
date_acquisition: datetime | None = None
|
|
51
|
+
examrep_session: ExternalObject | None = None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ExamReport2UserGrade(BaseModel):
|
|
55
|
+
grade_value: GradeValue | None = None
|
|
56
|
+
comment: str | None = None
|
|
57
|
+
user: ExternalObject | None = None
|
|
58
|
+
grader: ExternalObject | None = None
|
|
59
|
+
last_updated: datetime | None = None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def grades_by_user(value: Any) -> dict[str, ExamReport2StudentGrade] | None:
|
|
63
|
+
if value is None or isinstance(value, dict):
|
|
64
|
+
return value
|
|
65
|
+
if isinstance(value, list):
|
|
66
|
+
parsed_grades: dict[str, ExamReport2StudentGrade] = {}
|
|
67
|
+
for index, raw_grade in enumerate(value):
|
|
68
|
+
grade = ExamReport2StudentGrade.model_validate(raw_grade)
|
|
69
|
+
user_id = grade.user.id if grade.user is not None else None
|
|
70
|
+
parsed_grades[str(user_id if user_id is not None else index)] = grade
|
|
71
|
+
return parsed_grades
|
|
72
|
+
raise ValueError("Expected grade dictionary, grade list or None.")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ExamReport2Session(BaseModel):
|
|
76
|
+
examrep_id: str | int | None = None
|
|
77
|
+
number: int | None = None
|
|
78
|
+
status: str | None = None
|
|
79
|
+
description: LangDict | None = None
|
|
80
|
+
deadline: datetime | None = None
|
|
81
|
+
is_open: USOSBool | None = None
|
|
82
|
+
is_acquisition_date_required: USOSBool | None = None
|
|
83
|
+
all_grades: dict[str, ExamReport2StudentGrade] | None = None
|
|
84
|
+
issuer_grade: ExamReport2UserGrade | None = None
|
|
85
|
+
read_access: list[ExternalObject] | None = None
|
|
86
|
+
write_access: list[ExternalObject] | None = None
|
|
87
|
+
|
|
88
|
+
@field_validator("all_grades", mode="before")
|
|
89
|
+
@classmethod
|
|
90
|
+
def _parse_all_grades(
|
|
91
|
+
cls, value: Any
|
|
92
|
+
) -> dict[str, ExamReport2StudentGrade] | None:
|
|
93
|
+
return grades_by_user(value)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class ExamReport2(BaseModel):
|
|
97
|
+
id: str | int | None = None
|
|
98
|
+
description: LangDict | None = None
|
|
99
|
+
counts_into_average: USOSBool | None = None
|
|
100
|
+
grade_type: GradeType | None = None
|
|
101
|
+
is_general_report: USOSBool | None = None
|
|
102
|
+
sessions: list[ExamReport2Session] | None = None
|
|
103
|
+
edit_access: list[ExternalObject] | None = None
|
|
104
|
+
course_edition: ExternalObject | None = None
|
|
105
|
+
course_unit: ExternalObject | None = None
|
|
106
|
+
active_sessions: list[ExamReport2Session] | None = None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class ExamReportSessionAccess(BaseModel):
|
|
110
|
+
cause: str | None = None
|
|
111
|
+
groups: list[ExternalObject] | None = None
|
|
112
|
+
exam_groups: list[ExternalObject] | None = None
|
|
113
|
+
unassigned: USOSBool | None = None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class ExamReport2ClassGroup(BaseModel):
|
|
117
|
+
class_group: ExternalObject | None = None
|
|
118
|
+
grades: dict[str, ExamReport2StudentGrade] | None = None
|
|
119
|
+
|
|
120
|
+
@field_validator("grades", mode="before")
|
|
121
|
+
@classmethod
|
|
122
|
+
def _parse_grades(cls, value: Any) -> dict[str, ExamReport2StudentGrade] | None:
|
|
123
|
+
return grades_by_user(value)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class ExamReportCourse(BaseModel):
|
|
127
|
+
id: str | None = None
|
|
128
|
+
name: LangDict | None = None
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class ExamReportCourseUnit(BaseModel):
|
|
132
|
+
id: str | None = None
|
|
133
|
+
course_id: str | None = None
|
|
134
|
+
course_name: LangDict | None = None
|
|
135
|
+
classtype_id: str | None = None
|
|
136
|
+
term_id: str | None = None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class ExamReportGradeDistributionItem(BaseModel):
|
|
140
|
+
grade_symbol: str | None = None
|
|
141
|
+
percentage: float | None = None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class ExamReportIssuerGrade(BaseModel):
|
|
145
|
+
value_symbol: str | None = None
|
|
146
|
+
passes: USOSBool | None = None
|
|
147
|
+
value_description: LangDict | None = None
|
|
148
|
+
exam_id: str | int | None = None
|
|
149
|
+
exam_session_number: int | None = None
|
|
150
|
+
counts_into_average: USOSBool | None = None
|
|
151
|
+
comment: str | None = None
|
|
152
|
+
private_comment: str | None = None
|
|
153
|
+
grade_type_id: str | None = None
|
|
154
|
+
date_modified: datetime | None = None
|
|
155
|
+
date_acquisition: datetime | None = None
|
|
156
|
+
modification_author: User | None = None
|
|
157
|
+
|
|
158
|
+
@field_validator("modification_author", mode="before")
|
|
159
|
+
@classmethod
|
|
160
|
+
def _parse_modification_author(cls, value: Any) -> User | None:
|
|
161
|
+
if value is None or isinstance(value, User):
|
|
162
|
+
return value
|
|
163
|
+
if isinstance(value, dict):
|
|
164
|
+
return User.model_validate(value)
|
|
165
|
+
if isinstance(value, str | int):
|
|
166
|
+
return User(id=value)
|
|
167
|
+
raise ValueError("Expected user object, user id or None.")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class ExamReportSession(BaseModel):
|
|
171
|
+
number: int | None = None
|
|
172
|
+
examrep_id: str | int | None = None
|
|
173
|
+
status: str | None = None
|
|
174
|
+
description: LangDict | None = None
|
|
175
|
+
deadline: datetime | None = None
|
|
176
|
+
is_editable: USOSBool | None = None
|
|
177
|
+
issuer_grades: list[ExamReportIssuerGrade] | None = None
|
|
178
|
+
|
|
179
|
+
@field_validator("issuer_grades", mode="before")
|
|
180
|
+
@classmethod
|
|
181
|
+
def _parse_issuer_grades(cls, value: Any) -> list[Any] | None:
|
|
182
|
+
if value is None or isinstance(value, list):
|
|
183
|
+
return value
|
|
184
|
+
if isinstance(value, dict):
|
|
185
|
+
return [value]
|
|
186
|
+
raise ValueError("Expected issuer grade object, issuer grade list or None.")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class ExamReport(BaseModel):
|
|
190
|
+
id: str | int | None = None
|
|
191
|
+
description: LangDict | None = None
|
|
192
|
+
type_id: str | None = None
|
|
193
|
+
type_description: LangDict | None = None
|
|
194
|
+
counts_into_average: USOSBool | None = None
|
|
195
|
+
term_id: str | None = None
|
|
196
|
+
is_editable: USOSBool | None = None
|
|
197
|
+
course_unit: ExamReportCourseUnit | None = None
|
|
198
|
+
course: ExamReportCourse | None = None
|
|
199
|
+
sessions: list[ExamReportSession] | None = None
|
|
200
|
+
grades_distribution: list[ExamReportGradeDistributionItem] | None = None
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
UserExamReportsByTerm: TypeAlias = dict[str, dict[str, list[ExamReport]]]
|
|
204
|
+
RawUserExamReportsByTerm: TypeAlias = dict[str, dict[str, list[dict[str, Any]]]]
|
|
205
|
+
LegacyUserExamReportsByTerm: TypeAlias = dict[
|
|
206
|
+
str, dict[str, dict[str, list[ExamReport]]]
|
|
207
|
+
]
|
|
208
|
+
LegacyCourseEditionExamReport: TypeAlias = dict[
|
|
209
|
+
str, ExamReport | list[ExamReport] | dict[str, list[ExamReport]] | None
|
|
210
|
+
]
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def parse_user_exam_reports(
|
|
214
|
+
reports_by_term: Mapping[str, Mapping[str, list[Mapping[str, Any]]]],
|
|
215
|
+
) -> UserExamReportsByTerm:
|
|
216
|
+
return {
|
|
217
|
+
term_id: {
|
|
218
|
+
course_id: [ExamReport.model_validate(report) for report in reports]
|
|
219
|
+
for course_id, reports in courses.items()
|
|
220
|
+
}
|
|
221
|
+
for term_id, courses in reports_by_term.items()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def parse_legacy_user_exam_reports(
|
|
226
|
+
reports_by_term: Mapping[
|
|
227
|
+
str, Mapping[str, Mapping[str, list[Mapping[str, Any]]]]
|
|
228
|
+
],
|
|
229
|
+
) -> LegacyUserExamReportsByTerm:
|
|
230
|
+
return {
|
|
231
|
+
term_id: {
|
|
232
|
+
course_id: {
|
|
233
|
+
group_id: [ExamReport.model_validate(report) for report in reports]
|
|
234
|
+
for group_id, reports in groups.items()
|
|
235
|
+
}
|
|
236
|
+
for course_id, groups in courses.items()
|
|
237
|
+
}
|
|
238
|
+
for term_id, courses in reports_by_term.items()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def parse_legacy_course_edition_exam_report(
|
|
243
|
+
exam_report_data: Mapping[str, Any],
|
|
244
|
+
) -> LegacyCourseEditionExamReport:
|
|
245
|
+
return {
|
|
246
|
+
key: _parse_legacy_course_edition_value(value)
|
|
247
|
+
for key, value in exam_report_data.items()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _parse_legacy_course_edition_value(
|
|
252
|
+
value: Any,
|
|
253
|
+
) -> ExamReport | list[ExamReport] | dict[str, list[ExamReport]] | None:
|
|
254
|
+
if value is None:
|
|
255
|
+
return None
|
|
256
|
+
if isinstance(value, list):
|
|
257
|
+
return [ExamReport.model_validate(report) for report in value]
|
|
258
|
+
if isinstance(value, dict):
|
|
259
|
+
if all(isinstance(reports, list) for reports in value.values()):
|
|
260
|
+
return {
|
|
261
|
+
group_id: [ExamReport.model_validate(report) for report in reports]
|
|
262
|
+
for group_id, reports in value.items()
|
|
263
|
+
}
|
|
264
|
+
return ExamReport.model_validate(value)
|
|
265
|
+
raise ValueError("Expected exam report object, exam report list, mapping or None.")
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from typing import TYPE_CHECKING, Any, Optional
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel
|
|
4
|
+
from pydantic import BaseModel, field_validator
|
|
5
5
|
|
|
6
6
|
from . import CourseEdition
|
|
7
7
|
from .course import CourseUnit
|
|
8
|
+
from .usos_bool import USOSBool
|
|
8
9
|
|
|
9
10
|
if TYPE_CHECKING:
|
|
10
11
|
from .user import User
|
|
@@ -15,17 +16,17 @@ from .lang_dict import LangDict
|
|
|
15
16
|
class Grade(BaseModel):
|
|
16
17
|
value: float | None = None
|
|
17
18
|
value_symbol: str | None = None
|
|
18
|
-
passes:
|
|
19
|
+
passes: USOSBool | None = None
|
|
19
20
|
value_description: LangDict | None = None
|
|
20
21
|
exam_id: int | None = None
|
|
21
22
|
exam_session_number: int | None = None
|
|
22
|
-
counts_into_average:
|
|
23
|
+
counts_into_average: USOSBool | None = None
|
|
23
24
|
comment: str | None = None
|
|
24
25
|
private_comment: str | None = None
|
|
25
26
|
grade_type_id: str | None = None
|
|
26
27
|
date_modified: datetime | None = None
|
|
27
28
|
date_acquisition: datetime | None = None
|
|
28
|
-
modification_author:
|
|
29
|
+
modification_author: Optional["User"] = None
|
|
29
30
|
course_edition: CourseEdition | None = None
|
|
30
31
|
unit: CourseUnit | None = None
|
|
31
32
|
exam_report: dict[str, Any] | None = None
|
|
@@ -41,3 +42,16 @@ class Grade(BaseModel):
|
|
|
41
42
|
self.value = float(self.value_symbol.replace(",", "."))
|
|
42
43
|
except ValueError:
|
|
43
44
|
pass # Invalid value, ignore it
|
|
45
|
+
|
|
46
|
+
@field_validator("modification_author", mode="before")
|
|
47
|
+
@classmethod
|
|
48
|
+
def _parse_modification_author(cls, value: Any) -> Optional["User"]:
|
|
49
|
+
from .user import User
|
|
50
|
+
|
|
51
|
+
if value is None or isinstance(value, User):
|
|
52
|
+
return value
|
|
53
|
+
if isinstance(value, dict):
|
|
54
|
+
return User.model_validate(value)
|
|
55
|
+
if isinstance(value, str | int):
|
|
56
|
+
return User(id=value)
|
|
57
|
+
raise ValueError("Expected user object, user id or None.")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Annotated, Any
|
|
2
|
+
|
|
3
|
+
from pydantic import BeforeValidator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def usos_bool(value: Any) -> Any:
|
|
7
|
+
if value is None or isinstance(value, bool):
|
|
8
|
+
return value
|
|
9
|
+
if isinstance(value, str):
|
|
10
|
+
normalized = value.strip().upper()
|
|
11
|
+
if normalized == "T":
|
|
12
|
+
return True
|
|
13
|
+
if normalized == "N":
|
|
14
|
+
return False
|
|
15
|
+
return value
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
USOSBool = Annotated[bool, BeforeValidator(usos_bool)]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from .api_documentation import APIDocumentationService
|
|
2
2
|
from .api_server import APIServerService
|
|
3
3
|
from .courses import CourseService
|
|
4
|
+
from .exam_reports import ExamReportService
|
|
4
5
|
from .grades import GradeService
|
|
5
6
|
from .groups import GroupService
|
|
6
7
|
from .registrations import RegistrationService
|
|
@@ -11,6 +12,7 @@ __all__ = [
|
|
|
11
12
|
"APIDocumentationService",
|
|
12
13
|
"APIServerService",
|
|
13
14
|
"CourseService",
|
|
15
|
+
"ExamReportService",
|
|
14
16
|
"GradeService",
|
|
15
17
|
"GroupService",
|
|
16
18
|
"TermService",
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
from typing import Optional
|
|
1
|
+
from typing import Optional, TypeAlias, TypedDict
|
|
2
2
|
|
|
3
3
|
from ..connection import USOSAPIConnection
|
|
4
4
|
from ..models import Course, CourseEdition, Term
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
class LangDictData(TypedDict, total=False):
|
|
8
|
+
pl: str | None
|
|
9
|
+
en: str | None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CourseClassTypeDescription(TypedDict, total=False):
|
|
13
|
+
name: LangDictData
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
CourseClassTypesIndex: TypeAlias = dict[str, CourseClassTypeDescription]
|
|
17
|
+
CourseEctsByTerm: TypeAlias = dict[str, dict[str, float | None]]
|
|
18
|
+
|
|
19
|
+
|
|
7
20
|
class CourseService:
|
|
8
21
|
"""
|
|
9
22
|
A service for course-related operations.
|
|
@@ -17,7 +30,7 @@ class CourseService:
|
|
|
17
30
|
"""
|
|
18
31
|
self.connection = connection
|
|
19
32
|
|
|
20
|
-
async def get_user_courses_ects(self) ->
|
|
33
|
+
async def get_user_courses_ects(self) -> CourseEctsByTerm:
|
|
21
34
|
"""
|
|
22
35
|
Get user courses ECTS.
|
|
23
36
|
|
|
@@ -85,3 +98,11 @@ class CourseService:
|
|
|
85
98
|
if not ongoing_terms_only or term_id in ongoing_terms
|
|
86
99
|
for course_edition in course_editions
|
|
87
100
|
]
|
|
101
|
+
|
|
102
|
+
async def get_class_types_index(self) -> CourseClassTypesIndex:
|
|
103
|
+
"""
|
|
104
|
+
Get class type descriptions indexed by class type ID.
|
|
105
|
+
|
|
106
|
+
:return: A dictionary mapping class type IDs to class type descriptions.
|
|
107
|
+
"""
|
|
108
|
+
return await self.connection.post("services/courses/classtypes_index")
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
from datetime import date, datetime
|
|
2
|
+
from typing import TypeAlias
|
|
3
|
+
|
|
4
|
+
from ..connection import USOSAPIConnection
|
|
5
|
+
from ..models.exam_report import (
|
|
6
|
+
ExamReport,
|
|
7
|
+
ExamReport2,
|
|
8
|
+
ExamReport2ClassGroup,
|
|
9
|
+
ExamReport2Session,
|
|
10
|
+
ExamReport2StudentGrade,
|
|
11
|
+
ExamReport2UserGrade,
|
|
12
|
+
ExamReportSession,
|
|
13
|
+
ExamReportSessionAccess,
|
|
14
|
+
ExamReportType,
|
|
15
|
+
GradeType,
|
|
16
|
+
GradeValue,
|
|
17
|
+
LegacyCourseEditionExamReport,
|
|
18
|
+
LegacyUserExamReportsByTerm,
|
|
19
|
+
RawUserExamReportsByTerm,
|
|
20
|
+
UserExamReportsByTerm,
|
|
21
|
+
parse_legacy_course_edition_exam_report,
|
|
22
|
+
parse_legacy_user_exam_reports,
|
|
23
|
+
parse_user_exam_reports,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
EmptyResponse: TypeAlias = dict[str, object]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _join_fields(fields: list[str] | str | None) -> str | None:
|
|
30
|
+
if isinstance(fields, list):
|
|
31
|
+
return "|".join(fields)
|
|
32
|
+
return fields
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _bool_param(value: bool) -> str:
|
|
36
|
+
return str(value).lower()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ExamReportService:
|
|
40
|
+
"""
|
|
41
|
+
A service for exam report-related operations.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, connection: USOSAPIConnection):
|
|
45
|
+
"""
|
|
46
|
+
Initialize the exam report service.
|
|
47
|
+
|
|
48
|
+
:param connection: The connection to use.
|
|
49
|
+
"""
|
|
50
|
+
self.connection = connection
|
|
51
|
+
|
|
52
|
+
async def get_class_group(
|
|
53
|
+
self,
|
|
54
|
+
examrep_id: str | int,
|
|
55
|
+
course_unit_id: str,
|
|
56
|
+
group_number: str | int,
|
|
57
|
+
fields: list[str] | str,
|
|
58
|
+
) -> ExamReport2ClassGroup:
|
|
59
|
+
"""
|
|
60
|
+
Get class group and grades in given group for given exam report.
|
|
61
|
+
|
|
62
|
+
:param examrep_id: ID of exam report.
|
|
63
|
+
:param course_unit_id: ID of course unit.
|
|
64
|
+
:param group_number: Group number.
|
|
65
|
+
:param fields: Selector of result fields you are interested in.
|
|
66
|
+
:return: A dictionary of selected fields and their values.
|
|
67
|
+
"""
|
|
68
|
+
response = await self.connection.post(
|
|
69
|
+
"services/examrep2/class_group",
|
|
70
|
+
examrep_id=examrep_id,
|
|
71
|
+
course_unit_id=course_unit_id,
|
|
72
|
+
group_number=group_number,
|
|
73
|
+
fields=_join_fields(fields),
|
|
74
|
+
)
|
|
75
|
+
return ExamReport2ClassGroup.model_validate(response)
|
|
76
|
+
|
|
77
|
+
async def get_examinee_exam_reports(
|
|
78
|
+
self,
|
|
79
|
+
user_id: str | int,
|
|
80
|
+
fields: list[str] | str | None = None,
|
|
81
|
+
) -> list[ExamReport2]:
|
|
82
|
+
"""
|
|
83
|
+
Get exam reports that allow the access token issuer to update a student's grades.
|
|
84
|
+
|
|
85
|
+
:param user_id: ID of the student.
|
|
86
|
+
:param fields: Selector of result fields you are interested in.
|
|
87
|
+
:return: List of exam report objects.
|
|
88
|
+
"""
|
|
89
|
+
response = await self.connection.post(
|
|
90
|
+
"services/examrep2/examinee",
|
|
91
|
+
user_id=user_id,
|
|
92
|
+
fields=_join_fields(fields),
|
|
93
|
+
)
|
|
94
|
+
return [ExamReport2.model_validate(report) for report in response]
|
|
95
|
+
|
|
96
|
+
async def get_exam_report(
|
|
97
|
+
self,
|
|
98
|
+
examrep_id: str | int,
|
|
99
|
+
fields: list[str] | str | None = None,
|
|
100
|
+
) -> ExamReport2:
|
|
101
|
+
"""
|
|
102
|
+
Get information about an exam report.
|
|
103
|
+
|
|
104
|
+
:param examrep_id: ID of exam report.
|
|
105
|
+
:param fields: Selector of result fields you are interested in.
|
|
106
|
+
:return: A dictionary of selected fields and their values.
|
|
107
|
+
"""
|
|
108
|
+
response = await self.connection.post(
|
|
109
|
+
"services/examrep2/examrep",
|
|
110
|
+
examrep_id=examrep_id,
|
|
111
|
+
fields=_join_fields(fields),
|
|
112
|
+
)
|
|
113
|
+
return ExamReport2.model_validate(response)
|
|
114
|
+
|
|
115
|
+
async def get_exam_report_session(
|
|
116
|
+
self,
|
|
117
|
+
examrep_id: str | int,
|
|
118
|
+
examrep_session_number: str | int,
|
|
119
|
+
fields: list[str] | str | None = None,
|
|
120
|
+
) -> ExamReport2Session:
|
|
121
|
+
"""
|
|
122
|
+
Get information about an exam report session.
|
|
123
|
+
|
|
124
|
+
:param examrep_id: ID of exam report.
|
|
125
|
+
:param examrep_session_number: Exam report session number.
|
|
126
|
+
:param fields: Selector of result fields you are interested in.
|
|
127
|
+
:return: A dictionary of selected fields and their values.
|
|
128
|
+
"""
|
|
129
|
+
response = await self.connection.post(
|
|
130
|
+
"services/examrep2/examrep_session",
|
|
131
|
+
examrep_id=examrep_id,
|
|
132
|
+
examrep_session_number=examrep_session_number,
|
|
133
|
+
fields=_join_fields(fields),
|
|
134
|
+
)
|
|
135
|
+
return ExamReport2Session.model_validate(response)
|
|
136
|
+
|
|
137
|
+
async def get_exam_report_session_access(
|
|
138
|
+
self,
|
|
139
|
+
examrep_id: str | int,
|
|
140
|
+
examrep_session_number: str | int,
|
|
141
|
+
access_type: str,
|
|
142
|
+
fields: list[str] | str | None = None,
|
|
143
|
+
) -> list[ExamReportSessionAccess]:
|
|
144
|
+
"""
|
|
145
|
+
Get access information for an exam report session.
|
|
146
|
+
|
|
147
|
+
:param examrep_id: ID of exam report.
|
|
148
|
+
:param examrep_session_number: Exam report session number.
|
|
149
|
+
:param access_type: Access type requested by the API parameter named ``type``.
|
|
150
|
+
:param fields: Selector of result fields you are interested in.
|
|
151
|
+
:return: A dictionary of selected fields and their values.
|
|
152
|
+
"""
|
|
153
|
+
response = await self.connection.post(
|
|
154
|
+
"services/examrep2/examrep_session_access",
|
|
155
|
+
examrep_id=examrep_id,
|
|
156
|
+
examrep_session_number=examrep_session_number,
|
|
157
|
+
type=access_type,
|
|
158
|
+
fields=_join_fields(fields),
|
|
159
|
+
)
|
|
160
|
+
return [ExamReportSessionAccess.model_validate(access) for access in response]
|
|
161
|
+
|
|
162
|
+
async def get_exam_report_type(
|
|
163
|
+
self,
|
|
164
|
+
examrep_type_id: str | int,
|
|
165
|
+
fields: list[str] | str | None = None,
|
|
166
|
+
) -> ExamReportType:
|
|
167
|
+
"""
|
|
168
|
+
Get information about an exam report type.
|
|
169
|
+
|
|
170
|
+
:param examrep_type_id: ID of exam report type.
|
|
171
|
+
:param fields: Selector of result fields you are interested in.
|
|
172
|
+
:return: A dictionary of selected fields and their values.
|
|
173
|
+
"""
|
|
174
|
+
response = await self.connection.post(
|
|
175
|
+
"services/examrep2/examrep_type",
|
|
176
|
+
examrep_type_id=examrep_type_id,
|
|
177
|
+
fields=_join_fields(fields),
|
|
178
|
+
)
|
|
179
|
+
return ExamReportType.model_validate(response)
|
|
180
|
+
|
|
181
|
+
async def get_grade_type(
|
|
182
|
+
self,
|
|
183
|
+
grade_type_id: str | int,
|
|
184
|
+
fields: list[str] | str | None = None,
|
|
185
|
+
) -> GradeType:
|
|
186
|
+
"""
|
|
187
|
+
Get information about a grade type.
|
|
188
|
+
|
|
189
|
+
:param grade_type_id: ID of grade type.
|
|
190
|
+
:param fields: Selector of result fields you are interested in.
|
|
191
|
+
:return: A dictionary of selected fields and their values.
|
|
192
|
+
"""
|
|
193
|
+
response = await self.connection.post(
|
|
194
|
+
"services/examrep2/grade_type",
|
|
195
|
+
grade_type_id=grade_type_id,
|
|
196
|
+
fields=_join_fields(fields),
|
|
197
|
+
)
|
|
198
|
+
return GradeType.model_validate(response)
|
|
199
|
+
|
|
200
|
+
async def get_grade_value(
|
|
201
|
+
self,
|
|
202
|
+
grade_type_id: str | int,
|
|
203
|
+
order_key: str | int,
|
|
204
|
+
fields: list[str] | str | None = None,
|
|
205
|
+
) -> GradeValue:
|
|
206
|
+
"""
|
|
207
|
+
Get information about a grade value.
|
|
208
|
+
|
|
209
|
+
:param grade_type_id: ID of grade type.
|
|
210
|
+
:param order_key: Grade value order key.
|
|
211
|
+
:param fields: Selector of result fields you are interested in.
|
|
212
|
+
:return: A dictionary of selected fields and their values.
|
|
213
|
+
"""
|
|
214
|
+
response = await self.connection.post(
|
|
215
|
+
"services/examrep2/grade_value",
|
|
216
|
+
grade_type_id=grade_type_id,
|
|
217
|
+
order_key=order_key,
|
|
218
|
+
fields=_join_fields(fields),
|
|
219
|
+
)
|
|
220
|
+
return GradeValue.model_validate(response)
|
|
221
|
+
|
|
222
|
+
async def get_grader_exam_reports(
|
|
223
|
+
self,
|
|
224
|
+
only_writable: bool = False,
|
|
225
|
+
active_terms_only: bool = True,
|
|
226
|
+
fields: list[str] | str | None = None,
|
|
227
|
+
) -> list[ExamReport2]:
|
|
228
|
+
"""
|
|
229
|
+
Get exam reports that the access token issuer can access.
|
|
230
|
+
|
|
231
|
+
:param only_writable: Whether to return only writable exam reports.
|
|
232
|
+
:param active_terms_only: Whether to return only exam reports from active terms.
|
|
233
|
+
:param fields: Selector of result fields you are interested in.
|
|
234
|
+
:return: List of exam report objects.
|
|
235
|
+
"""
|
|
236
|
+
response = await self.connection.post(
|
|
237
|
+
"services/examrep2/grader",
|
|
238
|
+
only_writable=_bool_param(only_writable),
|
|
239
|
+
active_terms_only=_bool_param(active_terms_only),
|
|
240
|
+
fields=_join_fields(fields),
|
|
241
|
+
)
|
|
242
|
+
return [ExamReport2.model_validate(report) for report in response]
|
|
243
|
+
|
|
244
|
+
async def get_student_grade(
|
|
245
|
+
self,
|
|
246
|
+
examrep_id: str | int,
|
|
247
|
+
examrep_session_number: str | int,
|
|
248
|
+
student_id: str | int,
|
|
249
|
+
fields: list[str] | str | None = None,
|
|
250
|
+
) -> ExamReport2StudentGrade:
|
|
251
|
+
"""
|
|
252
|
+
Get information about a student's grade in an exam report session.
|
|
253
|
+
|
|
254
|
+
:param examrep_id: ID of exam report.
|
|
255
|
+
:param examrep_session_number: Exam report session number.
|
|
256
|
+
:param student_id: ID of student.
|
|
257
|
+
:param fields: Selector of result fields you are interested in.
|
|
258
|
+
:return: A dictionary of selected fields and their values.
|
|
259
|
+
"""
|
|
260
|
+
response = await self.connection.post(
|
|
261
|
+
"services/examrep2/student_grade",
|
|
262
|
+
examrep_id=examrep_id,
|
|
263
|
+
examrep_session_number=examrep_session_number,
|
|
264
|
+
student_id=student_id,
|
|
265
|
+
fields=_join_fields(fields),
|
|
266
|
+
)
|
|
267
|
+
return ExamReport2StudentGrade.model_validate(response)
|
|
268
|
+
|
|
269
|
+
async def get_student_grades(
|
|
270
|
+
self,
|
|
271
|
+
examrep_id: str | int,
|
|
272
|
+
student_id: str | int,
|
|
273
|
+
fields: list[str] | str | None = None,
|
|
274
|
+
) -> list[ExamReport2StudentGrade]:
|
|
275
|
+
"""
|
|
276
|
+
Get information about all of a student's grades from a single exam report.
|
|
277
|
+
|
|
278
|
+
:param examrep_id: ID of exam report.
|
|
279
|
+
:param student_id: ID of student.
|
|
280
|
+
:param fields: Selector of result fields you are interested in.
|
|
281
|
+
:return: List of student grade objects.
|
|
282
|
+
"""
|
|
283
|
+
response = await self.connection.post(
|
|
284
|
+
"services/examrep2/student_grades",
|
|
285
|
+
examrep_id=examrep_id,
|
|
286
|
+
student_id=student_id,
|
|
287
|
+
fields=_join_fields(fields),
|
|
288
|
+
)
|
|
289
|
+
return [ExamReport2StudentGrade.model_validate(grade) for grade in response]
|
|
290
|
+
|
|
291
|
+
async def update_student_grade(
|
|
292
|
+
self,
|
|
293
|
+
student_id: str | int,
|
|
294
|
+
examrep_id: str | int,
|
|
295
|
+
examrep_session_number: str | int,
|
|
296
|
+
value_symbol: str | None = None,
|
|
297
|
+
comment: str | None = None,
|
|
298
|
+
private_comment: str | None = None,
|
|
299
|
+
date_modified: date | datetime | str | None = None,
|
|
300
|
+
date_acquisition: date | datetime | str | None = None,
|
|
301
|
+
) -> EmptyResponse:
|
|
302
|
+
"""
|
|
303
|
+
Update a student's grade in an exam report session.
|
|
304
|
+
|
|
305
|
+
:param student_id: ID of student.
|
|
306
|
+
:param examrep_id: ID of exam report.
|
|
307
|
+
:param examrep_session_number: Exam report session number.
|
|
308
|
+
:param value_symbol: Grade value symbol.
|
|
309
|
+
:param comment: Comment visible to the student.
|
|
310
|
+
:param private_comment: Comment visible to graders only.
|
|
311
|
+
:param date_modified: Grade modification date.
|
|
312
|
+
:param date_acquisition: Grade acquisition date.
|
|
313
|
+
:return: Empty dictionary on success.
|
|
314
|
+
"""
|
|
315
|
+
return await self.connection.post(
|
|
316
|
+
"services/examrep2/update_student_grade",
|
|
317
|
+
student_id=student_id,
|
|
318
|
+
examrep_id=examrep_id,
|
|
319
|
+
examrep_session_number=examrep_session_number,
|
|
320
|
+
value_symbol=value_symbol,
|
|
321
|
+
comment=comment,
|
|
322
|
+
private_comment=private_comment,
|
|
323
|
+
date_modified=date_modified,
|
|
324
|
+
date_acquisition=date_acquisition,
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
async def get_user_grade(
|
|
328
|
+
self,
|
|
329
|
+
examrep_id: str | int,
|
|
330
|
+
examrep_session_number: str | int,
|
|
331
|
+
fields: list[str] | str | None = None,
|
|
332
|
+
) -> ExamReport2UserGrade:
|
|
333
|
+
"""
|
|
334
|
+
Get the access token issuer's grade in an exam report session.
|
|
335
|
+
|
|
336
|
+
:param examrep_id: ID of exam report.
|
|
337
|
+
:param examrep_session_number: Exam report session number.
|
|
338
|
+
:param fields: Selector of result fields you are interested in.
|
|
339
|
+
:return: A dictionary of selected fields and their values.
|
|
340
|
+
"""
|
|
341
|
+
response = await self.connection.post(
|
|
342
|
+
"services/examrep2/user_grade",
|
|
343
|
+
examrep_id=examrep_id,
|
|
344
|
+
examrep_session_number=examrep_session_number,
|
|
345
|
+
fields=_join_fields(fields),
|
|
346
|
+
)
|
|
347
|
+
return ExamReport2UserGrade.model_validate(response)
|
|
348
|
+
|
|
349
|
+
async def get_course_edition_exam_report(
|
|
350
|
+
self,
|
|
351
|
+
course_id: str,
|
|
352
|
+
term_id: str,
|
|
353
|
+
fields: list[str] | str | None = None,
|
|
354
|
+
) -> LegacyCourseEditionExamReport:
|
|
355
|
+
"""
|
|
356
|
+
Get legacy exam report information related to a course edition.
|
|
357
|
+
|
|
358
|
+
This wraps ``services/examrep/course_edition``.
|
|
359
|
+
|
|
360
|
+
:param course_id: Course ID.
|
|
361
|
+
:param term_id: Academic term ID.
|
|
362
|
+
:param fields: Selector of result fields you are interested in.
|
|
363
|
+
:return: A dictionary of selected fields and their values.
|
|
364
|
+
"""
|
|
365
|
+
response = await self.connection.post(
|
|
366
|
+
"services/examrep/course_edition",
|
|
367
|
+
course_id=course_id,
|
|
368
|
+
term_id=term_id,
|
|
369
|
+
fields=_join_fields(fields),
|
|
370
|
+
)
|
|
371
|
+
return parse_legacy_course_edition_exam_report(response)
|
|
372
|
+
|
|
373
|
+
async def get_course_edition_exam_reports(
|
|
374
|
+
self,
|
|
375
|
+
course_id: str,
|
|
376
|
+
term_id: str,
|
|
377
|
+
fields: list[str] | str | None = None,
|
|
378
|
+
) -> LegacyCourseEditionExamReport:
|
|
379
|
+
"""
|
|
380
|
+
Get legacy exam reports related to a course edition.
|
|
381
|
+
|
|
382
|
+
This wraps ``services/examrep/course_edition2``.
|
|
383
|
+
|
|
384
|
+
:param course_id: Course ID.
|
|
385
|
+
:param term_id: Academic term ID.
|
|
386
|
+
:param fields: Selector of result fields you are interested in.
|
|
387
|
+
:return: A dictionary of selected fields and their values.
|
|
388
|
+
"""
|
|
389
|
+
response = await self.connection.post(
|
|
390
|
+
"services/examrep/course_edition2",
|
|
391
|
+
course_id=course_id,
|
|
392
|
+
term_id=term_id,
|
|
393
|
+
fields=_join_fields(fields),
|
|
394
|
+
)
|
|
395
|
+
return parse_legacy_course_edition_exam_report(response)
|
|
396
|
+
|
|
397
|
+
async def get_legacy_exam_report(
|
|
398
|
+
self,
|
|
399
|
+
exam_id: str | int,
|
|
400
|
+
fields: list[str] | str | None = None,
|
|
401
|
+
) -> ExamReport:
|
|
402
|
+
"""
|
|
403
|
+
Get legacy exam report information.
|
|
404
|
+
|
|
405
|
+
This wraps ``services/examrep/exam``.
|
|
406
|
+
|
|
407
|
+
:param exam_id: Exam report ID.
|
|
408
|
+
:param fields: Selector of result fields you are interested in.
|
|
409
|
+
:return: A dictionary of selected fields and their values.
|
|
410
|
+
"""
|
|
411
|
+
response = await self.connection.post(
|
|
412
|
+
"services/examrep/exam",
|
|
413
|
+
id=exam_id,
|
|
414
|
+
fields=_join_fields(fields),
|
|
415
|
+
)
|
|
416
|
+
return ExamReport.model_validate(response)
|
|
417
|
+
|
|
418
|
+
async def get_legacy_exam_session(
|
|
419
|
+
self,
|
|
420
|
+
exam_id: str | int,
|
|
421
|
+
number: str | int,
|
|
422
|
+
fields: list[str] | str | None = None,
|
|
423
|
+
) -> ExamReportSession:
|
|
424
|
+
"""
|
|
425
|
+
Get legacy exam report session information.
|
|
426
|
+
|
|
427
|
+
This wraps ``services/examrep/exam_session``.
|
|
428
|
+
|
|
429
|
+
:param exam_id: Exam report ID.
|
|
430
|
+
:param number: Exam session number.
|
|
431
|
+
:param fields: Selector of result fields you are interested in.
|
|
432
|
+
:return: A dictionary of selected fields and their values.
|
|
433
|
+
"""
|
|
434
|
+
response = await self.connection.post(
|
|
435
|
+
"services/examrep/exam_session",
|
|
436
|
+
exam_id=exam_id,
|
|
437
|
+
number=number,
|
|
438
|
+
fields=_join_fields(fields),
|
|
439
|
+
)
|
|
440
|
+
return ExamReportSession.model_validate(response)
|
|
441
|
+
|
|
442
|
+
async def get_legacy_user_exam_reports(
|
|
443
|
+
self,
|
|
444
|
+
term_ids: list[str] | str,
|
|
445
|
+
fields: list[str] | str | None = None,
|
|
446
|
+
) -> LegacyUserExamReportsByTerm:
|
|
447
|
+
"""
|
|
448
|
+
Get the current user's legacy exam reports for selected terms.
|
|
449
|
+
|
|
450
|
+
This wraps ``services/examrep/user``.
|
|
451
|
+
|
|
452
|
+
:param term_ids: Academic term IDs.
|
|
453
|
+
:param fields: Selector of result fields you are interested in.
|
|
454
|
+
:return: A dictionary mapping term IDs to course IDs to exam report groups.
|
|
455
|
+
"""
|
|
456
|
+
response = await self.connection.post(
|
|
457
|
+
"services/examrep/user",
|
|
458
|
+
term_ids=_join_fields(term_ids),
|
|
459
|
+
fields=_join_fields(fields),
|
|
460
|
+
)
|
|
461
|
+
return parse_legacy_user_exam_reports(response)
|
|
462
|
+
|
|
463
|
+
async def get_raw_user_exam_reports(
|
|
464
|
+
self,
|
|
465
|
+
term_ids: list[str] | str | None = None,
|
|
466
|
+
fields: list[str] | str | None = None,
|
|
467
|
+
) -> RawUserExamReportsByTerm:
|
|
468
|
+
"""
|
|
469
|
+
Get the current user's legacy exam reports as raw API dictionaries.
|
|
470
|
+
|
|
471
|
+
This wraps ``services/examrep/user2``.
|
|
472
|
+
|
|
473
|
+
:param term_ids: Academic term IDs. If omitted, the API default is used.
|
|
474
|
+
:param fields: Selector of result fields you are interested in.
|
|
475
|
+
:return: Raw dictionary mapping term IDs to course IDs to exam report lists.
|
|
476
|
+
"""
|
|
477
|
+
return await self.connection.post(
|
|
478
|
+
"services/examrep/user2",
|
|
479
|
+
term_ids=_join_fields(term_ids),
|
|
480
|
+
fields=_join_fields(fields),
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
async def get_user_exam_reports(
|
|
484
|
+
self,
|
|
485
|
+
term_ids: list[str] | str | None = None,
|
|
486
|
+
fields: list[str] | str | None = None,
|
|
487
|
+
) -> UserExamReportsByTerm:
|
|
488
|
+
"""
|
|
489
|
+
Get the current user's legacy exam reports for selected terms.
|
|
490
|
+
|
|
491
|
+
This wraps ``services/examrep/user2`` and parses the response into
|
|
492
|
+
Pydantic models.
|
|
493
|
+
|
|
494
|
+
:param term_ids: Academic term IDs. If omitted, the API default is used.
|
|
495
|
+
:param fields: Selector of exam report fields you are interested in.
|
|
496
|
+
:return: A dictionary mapping term IDs to course IDs to exam report models.
|
|
497
|
+
"""
|
|
498
|
+
return parse_user_exam_reports(
|
|
499
|
+
await self.get_raw_user_exam_reports(term_ids=term_ids, fields=fields)
|
|
500
|
+
)
|
|
@@ -60,7 +60,6 @@ class GroupService:
|
|
|
60
60
|
)
|
|
61
61
|
return [_deserialize_group(group) for group in response.values()]
|
|
62
62
|
|
|
63
|
-
|
|
64
63
|
async def get_group_by_id(
|
|
65
64
|
self, group_id: str, course_unit_id: str, fields: list[str] = None
|
|
66
65
|
) -> list[Group]:
|
|
@@ -75,14 +74,17 @@ class GroupService:
|
|
|
75
74
|
if not group_id or not course_unit_id:
|
|
76
75
|
return []
|
|
77
76
|
if not fields:
|
|
78
|
-
fields = ["course_unit_id", "group_number", "course_name","participants"]
|
|
77
|
+
fields = ["course_unit_id", "group_number", "course_name", "participants"]
|
|
79
78
|
if "course_unit_id" not in fields:
|
|
80
79
|
fields.append("course_unit_id")
|
|
81
80
|
if "group_number" not in fields:
|
|
82
81
|
fields.append("group_number")
|
|
83
82
|
fields = "|".join(fields)
|
|
84
83
|
response = await self.connection.post(
|
|
85
|
-
"services/groups/group",
|
|
84
|
+
"services/groups/group",
|
|
85
|
+
group_number=group_id,
|
|
86
|
+
course_unit_id=course_unit_id,
|
|
87
|
+
fields=fields,
|
|
86
88
|
)
|
|
87
89
|
print(response)
|
|
88
90
|
return [_deserialize_group(group) for group in response.values()]
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, List
|
|
2
|
-
|
|
3
|
-
from usos_api.models import CourseEdition, Grade
|
|
4
|
-
|
|
5
|
-
if TYPE_CHECKING:
|
|
6
|
-
from usos_api import USOSClient
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class APIHelper:
|
|
10
|
-
def __init__(self, client: "USOSClient"):
|
|
11
|
-
self.client = client
|
|
12
|
-
|
|
13
|
-
async def get_user_end_grades_with_weights(
|
|
14
|
-
self, current_term_only: bool = False
|
|
15
|
-
) -> List[Grade]:
|
|
16
|
-
"""
|
|
17
|
-
Get user end grades with weights.
|
|
18
|
-
|
|
19
|
-
:param current_term_only: If True, only consider the current term.
|
|
20
|
-
:return: A list of user end grades with weights.
|
|
21
|
-
"""
|
|
22
|
-
ects_by_term = await self.client.course_service.get_user_courses_ects()
|
|
23
|
-
terms = await self.client.term_service.get_terms(list(ects_by_term.keys()))
|
|
24
|
-
term_ids = [
|
|
25
|
-
term.id for term in terms if not current_term_only or term.is_ongoing
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
grades_by_term = await self.client.grade_service.get_grades_by_terms(term_ids)
|
|
29
|
-
|
|
30
|
-
user_grades = []
|
|
31
|
-
for term in terms:
|
|
32
|
-
if term.id not in term_ids:
|
|
33
|
-
continue
|
|
34
|
-
for course_id, ects in ects_by_term[term.id].items():
|
|
35
|
-
grades = (
|
|
36
|
-
grades_by_term[term.id].get(course_id, {}).get("course_grades", [])
|
|
37
|
-
)
|
|
38
|
-
for grade in grades:
|
|
39
|
-
grade.weight = ects
|
|
40
|
-
grade.course_edition = CourseEdition(
|
|
41
|
-
course_id=course_id, term_id=term.id
|
|
42
|
-
)
|
|
43
|
-
user_grades.append(grade)
|
|
44
|
-
|
|
45
|
-
return user_grades
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|