usos-api 0.3.4__tar.gz → 0.4.0__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.
Files changed (44) hide show
  1. {usos_api-0.3.4 → usos_api-0.4.0}/PKG-INFO +1 -1
  2. {usos_api-0.3.4 → usos_api-0.4.0}/docs/conf.py +9 -2
  3. {usos_api-0.3.4 → usos_api-0.4.0}/pyproject.toml +1 -1
  4. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/auth.py +2 -4
  5. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/client.py +3 -0
  6. usos_api-0.4.0/usos_api/helper.py +84 -0
  7. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/__init__.py +2 -0
  8. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/courses.py +23 -2
  9. usos_api-0.4.0/usos_api/services/exam_reports.py +599 -0
  10. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/groups.py +5 -3
  11. {usos_api-0.3.4 → usos_api-0.4.0}/uv.lock +1 -1
  12. usos_api-0.3.4/usos_api/helper.py +0 -45
  13. {usos_api-0.3.4 → usos_api-0.4.0}/.github/workflows/publish.yml +0 -0
  14. {usos_api-0.3.4 → usos_api-0.4.0}/.gitignore +0 -0
  15. {usos_api-0.3.4 → usos_api-0.4.0}/.readthedocs.yaml +0 -0
  16. {usos_api-0.3.4 → usos_api-0.4.0}/README.md +0 -0
  17. {usos_api-0.3.4 → usos_api-0.4.0}/docs/Makefile +0 -0
  18. {usos_api-0.3.4 → usos_api-0.4.0}/docs/full-docs.rst +0 -0
  19. {usos_api-0.3.4 → usos_api-0.4.0}/docs/index.rst +0 -0
  20. {usos_api-0.3.4 → usos_api-0.4.0}/docs/make.bat +0 -0
  21. {usos_api-0.3.4 → usos_api-0.4.0}/docs/quickstart.rst +0 -0
  22. {usos_api-0.3.4 → usos_api-0.4.0}/run.py +0 -0
  23. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/__init__.py +0 -0
  24. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/connection.py +0 -0
  25. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/exceptions.py +0 -0
  26. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/logger.py +0 -0
  27. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/__init__.py +0 -0
  28. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/api_documentation.py +0 -0
  29. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/consumer.py +0 -0
  30. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/course.py +0 -0
  31. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/grade.py +0 -0
  32. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/group.py +0 -0
  33. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/lang_dict.py +0 -0
  34. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/programme.py +0 -0
  35. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/registration.py +0 -0
  36. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/term.py +0 -0
  37. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/models/user.py +0 -0
  38. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/api_documentation.py +0 -0
  39. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/api_server.py +0 -0
  40. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/grades.py +0 -0
  41. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/registrations.py +0 -0
  42. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/terms.py +0 -0
  43. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/services/users.py +0 -0
  44. {usos_api-0.3.4 → usos_api-0.4.0}/usos_api/utils/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usos-api
3
- Version: 0.3.4
3
+ Version: 0.4.0
4
4
  Summary: Asynchronous USOS API for Python
5
5
  Project-URL: Homepage, https://github.com/Antoni-Czaplicki/usos-api
6
6
  Project-URL: Repository, https://github.com/Antoni-Czaplicki/usos-api
@@ -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
- copyright = "2024, Antoni Czaplicki"
17
+
15
18
  author = "Antoni Czaplicki"
16
- release = "0.1.0"
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "usos-api"
3
- version = "0.3.4"
3
+ version = "0.4.0"
4
4
  description = "Asynchronous USOS API for Python"
5
5
  authors = [
6
6
  { name = "Antoni-Czaplicki", email = "56671347+Antoni-Czaplicki@users.noreply.github.com" }
@@ -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(f"New request token generated")
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,84 @@
1
+ from typing import TYPE_CHECKING, List
2
+
3
+ from usos_api.models import CourseEdition, Grade
4
+ from usos_api.services.courses import CourseEctsByTerm
5
+ from usos_api.services.exam_reports import UserExamReportsByTerm
6
+
7
+ if TYPE_CHECKING:
8
+ from usos_api import USOSClient
9
+
10
+
11
+ class APIHelper:
12
+ def __init__(self, client: "USOSClient"):
13
+ self.client = client
14
+
15
+ async def get_user_end_grades_with_weights(
16
+ self, current_term_only: bool = False
17
+ ) -> List[Grade]:
18
+ """
19
+ Get user end grades with weights.
20
+
21
+ :param current_term_only: If True, only consider the current term.
22
+ :return: A list of user end grades with weights.
23
+ """
24
+ ects_by_term = await self.client.course_service.get_user_courses_ects()
25
+ terms = await self.client.term_service.get_terms(list(ects_by_term.keys()))
26
+ term_ids = [
27
+ term.id for term in terms if not current_term_only or term.is_ongoing
28
+ ]
29
+
30
+ grades_by_term = await self.client.grade_service.get_grades_by_terms(term_ids)
31
+
32
+ user_grades = []
33
+ for term in terms:
34
+ if term.id not in term_ids:
35
+ continue
36
+ for course_id, ects in ects_by_term[term.id].items():
37
+ grades = (
38
+ grades_by_term[term.id].get(course_id, {}).get("course_grades", [])
39
+ )
40
+ for grade in grades:
41
+ grade.weight = ects
42
+ grade.course_edition = CourseEdition(
43
+ course_id=course_id, term_id=term.id
44
+ )
45
+ user_grades.append(grade)
46
+
47
+ return user_grades
48
+
49
+ async def get_user_exam_reports_with_ects(
50
+ self,
51
+ term_ids: list[str] | str | None = None,
52
+ fields: list[str] | str | None = None,
53
+ ) -> tuple[CourseEctsByTerm, UserExamReportsByTerm]:
54
+ """
55
+ Fetch raw user exam reports together with course ECTS weights.
56
+
57
+ This helper intentionally does not shape grades for a specific app. It only
58
+ coordinates the USOS calls that are usually needed together.
59
+
60
+ :param term_ids: Academic term IDs. If omitted, terms from ECTS data are used.
61
+ :param fields: Selector of exam report fields you are interested in.
62
+ :return: ``(ects_by_term, reports_by_term)`` for the selected terms.
63
+ """
64
+ all_ects_by_term = await self.client.course_service.get_user_courses_ects()
65
+ selected_term_ids = _term_ids(term_ids) or list(all_ects_by_term.keys())
66
+ if not selected_term_ids:
67
+ return {}, {}
68
+
69
+ reports_by_term = await self.client.exam_report_service.get_user_exam_reports(
70
+ term_ids=selected_term_ids,
71
+ fields=fields,
72
+ )
73
+ ects_by_term = {
74
+ term_id: all_ects_by_term.get(term_id, {}) for term_id in selected_term_ids
75
+ }
76
+ return ects_by_term, reports_by_term
77
+
78
+
79
+ def _term_ids(term_ids: list[str] | str | None) -> list[str]:
80
+ if term_ids is None:
81
+ return []
82
+ if isinstance(term_ids, str):
83
+ return [term_ids]
84
+ return term_ids
@@ -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) -> dict[str, dict[str, Optional[float]]]:
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,599 @@
1
+ from datetime import date, datetime
2
+ from typing import TypeAlias, TypedDict
3
+
4
+ from ..connection import USOSAPIConnection
5
+
6
+ ExternalObject: TypeAlias = dict[str, object]
7
+ EmptyResponse: TypeAlias = dict[str, object]
8
+
9
+
10
+ class LangDictData(TypedDict, total=False):
11
+ pl: str | None
12
+ en: str | None
13
+
14
+
15
+ class GradeValue(TypedDict, total=False):
16
+ grade_type: ExternalObject
17
+ order_key: str | int
18
+ symbol: str
19
+ passes: bool
20
+ decimal_value: float | None
21
+ name: LangDictData
22
+
23
+
24
+ class GradeType(TypedDict, total=False):
25
+ id: str
26
+ name: LangDictData
27
+ values: list[GradeValue]
28
+
29
+
30
+ class ExamReportType(TypedDict, total=False):
31
+ id: str
32
+ name: LangDictData
33
+ grade_type: GradeType
34
+
35
+
36
+ class ExamReport2StudentGrade(TypedDict, total=False):
37
+ grade_value: GradeValue | None
38
+ comment: str | None
39
+ private_comment: str | None
40
+ user: ExternalObject
41
+ grader: ExternalObject
42
+ last_updated: str | None
43
+ is_editable: bool
44
+ resignation: bool
45
+ inactive_links: bool
46
+ why_cannot_edit: str | None
47
+ date_acquisition: str | None
48
+ examrep_session: ExternalObject
49
+
50
+
51
+ class ExamReport2UserGrade(TypedDict, total=False):
52
+ grade_value: GradeValue | None
53
+ comment: str | None
54
+ user: ExternalObject
55
+ grader: ExternalObject
56
+ last_updated: str | None
57
+
58
+
59
+ class ExamReport2Session(TypedDict, total=False):
60
+ examrep_id: str | int
61
+ number: int
62
+ status: str
63
+ description: LangDictData
64
+ deadline: str | None
65
+ is_open: bool
66
+ is_acquisition_date_required: bool
67
+ all_grades: dict[str, ExamReport2StudentGrade]
68
+ issuer_grade: ExamReport2UserGrade
69
+ read_access: list[ExternalObject]
70
+ write_access: list[ExternalObject]
71
+
72
+
73
+ class ExamReport2(TypedDict, total=False):
74
+ id: str | int
75
+ description: LangDictData
76
+ counts_into_average: bool
77
+ grade_type: GradeType
78
+ is_general_report: bool
79
+ sessions: list[ExamReport2Session]
80
+ edit_access: list[ExternalObject]
81
+ course_edition: ExternalObject
82
+ course_unit: ExternalObject
83
+ active_sessions: list[ExamReport2Session]
84
+
85
+
86
+ class ExamReportSessionAccess(TypedDict, total=False):
87
+ cause: str | None
88
+ groups: list[ExternalObject]
89
+ exam_groups: list[ExternalObject]
90
+ unassigned: list[ExternalObject]
91
+
92
+
93
+ class ExamReport2ClassGroup(TypedDict, total=False):
94
+ class_group: ExternalObject
95
+ grades: dict[str, ExamReport2StudentGrade]
96
+
97
+
98
+ class ExamReportCourse(TypedDict, total=False):
99
+ id: str
100
+ name: LangDictData
101
+
102
+
103
+ class ExamReportCourseUnit(TypedDict, total=False):
104
+ id: str
105
+ course_id: str
106
+ course_name: LangDictData
107
+ classtype_id: str | None
108
+ term_id: str
109
+
110
+
111
+ class ExamReportGradeDistributionItem(TypedDict, total=False):
112
+ grade_symbol: str
113
+ percentage: float
114
+
115
+
116
+ class ExamReportIssuerGrade(TypedDict, total=False):
117
+ value_symbol: str | None
118
+ passes: bool
119
+ value_description: LangDictData
120
+ exam_id: str | int
121
+ exam_session_number: int
122
+ counts_into_average: bool
123
+ comment: str | None
124
+ private_comment: str | None
125
+ grade_type_id: str
126
+ date_modified: str | None
127
+ date_acquisition: str | None
128
+ modification_author: str | int | None
129
+
130
+
131
+ class ExamReportSession(TypedDict, total=False):
132
+ number: int
133
+ examrep_id: str | int
134
+ status: str
135
+ description: LangDictData
136
+ deadline: str | None
137
+ is_editable: bool
138
+ issuer_grades: ExamReportIssuerGrade | list[ExamReportIssuerGrade]
139
+
140
+
141
+ class ExamReport(TypedDict, total=False):
142
+ id: str | int
143
+ description: LangDictData
144
+ type_id: str
145
+ type_description: LangDictData
146
+ counts_into_average: bool
147
+ term_id: str
148
+ is_editable: bool
149
+ course_unit: ExamReportCourseUnit | None
150
+ course: ExamReportCourse
151
+ sessions: list[ExamReportSession]
152
+ grades_distribution: list[ExamReportGradeDistributionItem]
153
+
154
+
155
+ UserExamReportsByTerm: TypeAlias = dict[str, dict[str, list[ExamReport]]]
156
+ LegacyUserExamReportsByTerm: TypeAlias = dict[
157
+ str, dict[str, dict[str, list[ExamReport]]]
158
+ ]
159
+ LegacyCourseEditionExamReport: TypeAlias = dict[
160
+ str, ExamReport | list[ExamReport] | dict[str, list[ExamReport]] | None
161
+ ]
162
+
163
+
164
+ def _join_fields(fields: list[str] | str | None) -> str | None:
165
+ if isinstance(fields, list):
166
+ return "|".join(fields)
167
+ return fields
168
+
169
+
170
+ def _bool_param(value: bool) -> str:
171
+ return str(value).lower()
172
+
173
+
174
+ class ExamReportService:
175
+ """
176
+ A service for exam report-related operations.
177
+ """
178
+
179
+ def __init__(self, connection: USOSAPIConnection):
180
+ """
181
+ Initialize the exam report service.
182
+
183
+ :param connection: The connection to use.
184
+ """
185
+ self.connection = connection
186
+
187
+ async def get_class_group(
188
+ self,
189
+ examrep_id: str | int,
190
+ course_unit_id: str,
191
+ group_number: str | int,
192
+ fields: list[str] | str,
193
+ ) -> ExamReport2ClassGroup:
194
+ """
195
+ Get class group and grades in given group for given exam report.
196
+
197
+ :param examrep_id: ID of exam report.
198
+ :param course_unit_id: ID of course unit.
199
+ :param group_number: Group number.
200
+ :param fields: Selector of result fields you are interested in.
201
+ :return: A dictionary of selected fields and their values.
202
+ """
203
+ return await self.connection.post(
204
+ "services/examrep2/class_group",
205
+ examrep_id=examrep_id,
206
+ course_unit_id=course_unit_id,
207
+ group_number=group_number,
208
+ fields=_join_fields(fields),
209
+ )
210
+
211
+ async def get_examinee_exam_reports(
212
+ self,
213
+ user_id: str | int,
214
+ fields: list[str] | str | None = None,
215
+ ) -> list[ExamReport2]:
216
+ """
217
+ Get exam reports that allow the access token issuer to update a student's grades.
218
+
219
+ :param user_id: ID of the student.
220
+ :param fields: Selector of result fields you are interested in.
221
+ :return: List of exam report objects.
222
+ """
223
+ return await self.connection.post(
224
+ "services/examrep2/examinee",
225
+ user_id=user_id,
226
+ fields=_join_fields(fields),
227
+ )
228
+
229
+ async def get_exam_report(
230
+ self,
231
+ examrep_id: str | int,
232
+ fields: list[str] | str | None = None,
233
+ ) -> ExamReport2:
234
+ """
235
+ Get information about an exam report.
236
+
237
+ :param examrep_id: ID of exam report.
238
+ :param fields: Selector of result fields you are interested in.
239
+ :return: A dictionary of selected fields and their values.
240
+ """
241
+ return await self.connection.post(
242
+ "services/examrep2/examrep",
243
+ examrep_id=examrep_id,
244
+ fields=_join_fields(fields),
245
+ )
246
+
247
+ async def get_exam_report_session(
248
+ self,
249
+ examrep_id: str | int,
250
+ examrep_session_number: str | int,
251
+ fields: list[str] | str | None = None,
252
+ ) -> ExamReport2Session:
253
+ """
254
+ Get information about an exam report session.
255
+
256
+ :param examrep_id: ID of exam report.
257
+ :param examrep_session_number: Exam report session number.
258
+ :param fields: Selector of result fields you are interested in.
259
+ :return: A dictionary of selected fields and their values.
260
+ """
261
+ return await self.connection.post(
262
+ "services/examrep2/examrep_session",
263
+ examrep_id=examrep_id,
264
+ examrep_session_number=examrep_session_number,
265
+ fields=_join_fields(fields),
266
+ )
267
+
268
+ async def get_exam_report_session_access(
269
+ self,
270
+ examrep_id: str | int,
271
+ examrep_session_number: str | int,
272
+ access_type: str,
273
+ fields: list[str] | str | None = None,
274
+ ) -> list[ExamReportSessionAccess]:
275
+ """
276
+ Get access information for an exam report session.
277
+
278
+ :param examrep_id: ID of exam report.
279
+ :param examrep_session_number: Exam report session number.
280
+ :param access_type: Access type requested by the API parameter named ``type``.
281
+ :param fields: Selector of result fields you are interested in.
282
+ :return: A dictionary of selected fields and their values.
283
+ """
284
+ return await self.connection.post(
285
+ "services/examrep2/examrep_session_access",
286
+ examrep_id=examrep_id,
287
+ examrep_session_number=examrep_session_number,
288
+ type=access_type,
289
+ fields=_join_fields(fields),
290
+ )
291
+
292
+ async def get_exam_report_type(
293
+ self,
294
+ examrep_type_id: str | int,
295
+ fields: list[str] | str | None = None,
296
+ ) -> ExamReportType:
297
+ """
298
+ Get information about an exam report type.
299
+
300
+ :param examrep_type_id: ID of exam report type.
301
+ :param fields: Selector of result fields you are interested in.
302
+ :return: A dictionary of selected fields and their values.
303
+ """
304
+ return await self.connection.post(
305
+ "services/examrep2/examrep_type",
306
+ examrep_type_id=examrep_type_id,
307
+ fields=_join_fields(fields),
308
+ )
309
+
310
+ async def get_grade_type(
311
+ self,
312
+ grade_type_id: str | int,
313
+ fields: list[str] | str | None = None,
314
+ ) -> GradeType:
315
+ """
316
+ Get information about a grade type.
317
+
318
+ :param grade_type_id: ID of grade type.
319
+ :param fields: Selector of result fields you are interested in.
320
+ :return: A dictionary of selected fields and their values.
321
+ """
322
+ return await self.connection.post(
323
+ "services/examrep2/grade_type",
324
+ grade_type_id=grade_type_id,
325
+ fields=_join_fields(fields),
326
+ )
327
+
328
+ async def get_grade_value(
329
+ self,
330
+ grade_type_id: str | int,
331
+ order_key: str | int,
332
+ fields: list[str] | str | None = None,
333
+ ) -> GradeValue:
334
+ """
335
+ Get information about a grade value.
336
+
337
+ :param grade_type_id: ID of grade type.
338
+ :param order_key: Grade value order key.
339
+ :param fields: Selector of result fields you are interested in.
340
+ :return: A dictionary of selected fields and their values.
341
+ """
342
+ return await self.connection.post(
343
+ "services/examrep2/grade_value",
344
+ grade_type_id=grade_type_id,
345
+ order_key=order_key,
346
+ fields=_join_fields(fields),
347
+ )
348
+
349
+ async def get_grader_exam_reports(
350
+ self,
351
+ only_writable: bool = False,
352
+ active_terms_only: bool = True,
353
+ fields: list[str] | str | None = None,
354
+ ) -> list[ExamReport2]:
355
+ """
356
+ Get exam reports that the access token issuer can access.
357
+
358
+ :param only_writable: Whether to return only writable exam reports.
359
+ :param active_terms_only: Whether to return only exam reports from active terms.
360
+ :param fields: Selector of result fields you are interested in.
361
+ :return: List of exam report objects.
362
+ """
363
+ return await self.connection.post(
364
+ "services/examrep2/grader",
365
+ only_writable=_bool_param(only_writable),
366
+ active_terms_only=_bool_param(active_terms_only),
367
+ fields=_join_fields(fields),
368
+ )
369
+
370
+ async def get_student_grade(
371
+ self,
372
+ examrep_id: str | int,
373
+ examrep_session_number: str | int,
374
+ student_id: str | int,
375
+ fields: list[str] | str | None = None,
376
+ ) -> ExamReport2StudentGrade:
377
+ """
378
+ Get information about a student's grade in an exam report session.
379
+
380
+ :param examrep_id: ID of exam report.
381
+ :param examrep_session_number: Exam report session number.
382
+ :param student_id: ID of student.
383
+ :param fields: Selector of result fields you are interested in.
384
+ :return: A dictionary of selected fields and their values.
385
+ """
386
+ return await self.connection.post(
387
+ "services/examrep2/student_grade",
388
+ examrep_id=examrep_id,
389
+ examrep_session_number=examrep_session_number,
390
+ student_id=student_id,
391
+ fields=_join_fields(fields),
392
+ )
393
+
394
+ async def get_student_grades(
395
+ self,
396
+ examrep_id: str | int,
397
+ student_id: str | int,
398
+ fields: list[str] | str | None = None,
399
+ ) -> list[ExamReport2StudentGrade]:
400
+ """
401
+ Get information about all of a student's grades from a single exam report.
402
+
403
+ :param examrep_id: ID of exam report.
404
+ :param student_id: ID of student.
405
+ :param fields: Selector of result fields you are interested in.
406
+ :return: List of student grade objects.
407
+ """
408
+ return await self.connection.post(
409
+ "services/examrep2/student_grades",
410
+ examrep_id=examrep_id,
411
+ student_id=student_id,
412
+ fields=_join_fields(fields),
413
+ )
414
+
415
+ async def update_student_grade(
416
+ self,
417
+ student_id: str | int,
418
+ examrep_id: str | int,
419
+ examrep_session_number: str | int,
420
+ value_symbol: str | None = None,
421
+ comment: str | None = None,
422
+ private_comment: str | None = None,
423
+ date_modified: date | datetime | str | None = None,
424
+ date_acquisition: date | datetime | str | None = None,
425
+ ) -> EmptyResponse:
426
+ """
427
+ Update a student's grade in an exam report session.
428
+
429
+ :param student_id: ID of student.
430
+ :param examrep_id: ID of exam report.
431
+ :param examrep_session_number: Exam report session number.
432
+ :param value_symbol: Grade value symbol.
433
+ :param comment: Comment visible to the student.
434
+ :param private_comment: Comment visible to graders only.
435
+ :param date_modified: Grade modification date.
436
+ :param date_acquisition: Grade acquisition date.
437
+ :return: Empty dictionary on success.
438
+ """
439
+ return await self.connection.post(
440
+ "services/examrep2/update_student_grade",
441
+ student_id=student_id,
442
+ examrep_id=examrep_id,
443
+ examrep_session_number=examrep_session_number,
444
+ value_symbol=value_symbol,
445
+ comment=comment,
446
+ private_comment=private_comment,
447
+ date_modified=date_modified,
448
+ date_acquisition=date_acquisition,
449
+ )
450
+
451
+ async def get_user_grade(
452
+ self,
453
+ examrep_id: str | int,
454
+ examrep_session_number: str | int,
455
+ fields: list[str] | str | None = None,
456
+ ) -> ExamReport2UserGrade:
457
+ """
458
+ Get the access token issuer's grade in an exam report session.
459
+
460
+ :param examrep_id: ID of exam report.
461
+ :param examrep_session_number: Exam report session number.
462
+ :param fields: Selector of result fields you are interested in.
463
+ :return: A dictionary of selected fields and their values.
464
+ """
465
+ return await self.connection.post(
466
+ "services/examrep2/user_grade",
467
+ examrep_id=examrep_id,
468
+ examrep_session_number=examrep_session_number,
469
+ fields=_join_fields(fields),
470
+ )
471
+
472
+ async def get_course_edition_exam_report(
473
+ self,
474
+ course_id: str,
475
+ term_id: str,
476
+ fields: list[str] | str | None = None,
477
+ ) -> LegacyCourseEditionExamReport:
478
+ """
479
+ Get legacy exam report information related to a course edition.
480
+
481
+ This wraps ``services/examrep/course_edition``.
482
+
483
+ :param course_id: Course ID.
484
+ :param term_id: Academic term ID.
485
+ :param fields: Selector of result fields you are interested in.
486
+ :return: A dictionary of selected fields and their values.
487
+ """
488
+ return await self.connection.post(
489
+ "services/examrep/course_edition",
490
+ course_id=course_id,
491
+ term_id=term_id,
492
+ fields=_join_fields(fields),
493
+ )
494
+
495
+ async def get_course_edition_exam_reports(
496
+ self,
497
+ course_id: str,
498
+ term_id: str,
499
+ fields: list[str] | str | None = None,
500
+ ) -> LegacyCourseEditionExamReport:
501
+ """
502
+ Get legacy exam reports related to a course edition.
503
+
504
+ This wraps ``services/examrep/course_edition2``.
505
+
506
+ :param course_id: Course ID.
507
+ :param term_id: Academic term ID.
508
+ :param fields: Selector of result fields you are interested in.
509
+ :return: A dictionary of selected fields and their values.
510
+ """
511
+ return await self.connection.post(
512
+ "services/examrep/course_edition2",
513
+ course_id=course_id,
514
+ term_id=term_id,
515
+ fields=_join_fields(fields),
516
+ )
517
+
518
+ async def get_legacy_exam_report(
519
+ self,
520
+ exam_id: str | int,
521
+ fields: list[str] | str | None = None,
522
+ ) -> ExamReport:
523
+ """
524
+ Get legacy exam report information.
525
+
526
+ This wraps ``services/examrep/exam``.
527
+
528
+ :param exam_id: Exam report ID.
529
+ :param fields: Selector of result fields you are interested in.
530
+ :return: A dictionary of selected fields and their values.
531
+ """
532
+ return await self.connection.post(
533
+ "services/examrep/exam",
534
+ id=exam_id,
535
+ fields=_join_fields(fields),
536
+ )
537
+
538
+ async def get_legacy_exam_session(
539
+ self,
540
+ exam_id: str | int,
541
+ number: str | int,
542
+ fields: list[str] | str | None = None,
543
+ ) -> ExamReportSession:
544
+ """
545
+ Get legacy exam report session information.
546
+
547
+ This wraps ``services/examrep/exam_session``.
548
+
549
+ :param exam_id: Exam report ID.
550
+ :param number: Exam session number.
551
+ :param fields: Selector of result fields you are interested in.
552
+ :return: A dictionary of selected fields and their values.
553
+ """
554
+ return await self.connection.post(
555
+ "services/examrep/exam_session",
556
+ exam_id=exam_id,
557
+ number=number,
558
+ fields=_join_fields(fields),
559
+ )
560
+
561
+ async def get_legacy_user_exam_reports(
562
+ self,
563
+ term_ids: list[str] | str,
564
+ fields: list[str] | str | None = None,
565
+ ) -> LegacyUserExamReportsByTerm:
566
+ """
567
+ Get the current user's legacy exam reports for selected terms.
568
+
569
+ This wraps ``services/examrep/user``.
570
+
571
+ :param term_ids: Academic term IDs.
572
+ :param fields: Selector of result fields you are interested in.
573
+ :return: A dictionary mapping term IDs to course IDs to exam report groups.
574
+ """
575
+ return await self.connection.post(
576
+ "services/examrep/user",
577
+ term_ids=_join_fields(term_ids),
578
+ fields=_join_fields(fields),
579
+ )
580
+
581
+ async def get_user_exam_reports(
582
+ self,
583
+ term_ids: list[str] | str | None = None,
584
+ fields: list[str] | str | None = None,
585
+ ) -> UserExamReportsByTerm:
586
+ """
587
+ Get the current user's legacy exam reports for selected terms.
588
+
589
+ This wraps ``services/examrep/user2``.
590
+
591
+ :param term_ids: Academic term IDs. If omitted, the API default is used.
592
+ :param fields: Selector of result fields you are interested in.
593
+ :return: A dictionary mapping term IDs to course IDs to exam report lists.
594
+ """
595
+ return await self.connection.post(
596
+ "services/examrep/user2",
597
+ term_ids=_join_fields(term_ids),
598
+ fields=_join_fields(fields),
599
+ )
@@ -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", group_number=group_id, course_unit_id=course_unit_id, fields=fields
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()]
@@ -1490,7 +1490,7 @@ wheels = [
1490
1490
 
1491
1491
  [[package]]
1492
1492
  name = "usos-api"
1493
- version = "0.3.4"
1493
+ version = "0.4.0"
1494
1494
  source = { editable = "." }
1495
1495
  dependencies = [
1496
1496
  { name = "aiohttp" },
@@ -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