Skip to content

Commit ef4f30b

Browse files
sveco86ivanhrabcak
andauthored
Add more_details field and class average grade to grade data structure (#98)
* Add more_details field to grade data structure Added 'more_details' field to grade data structure and populated it from Edupage metadata. * Add class_grade_avg to EduGrade class Added class_grade_avg attribute to EduGrade and updated its assignment in the grade processing logic. * Apply code review suggestions --------- Co-authored-by: Ivan Hrabcak <ivan@hrabcak.eu>
1 parent 5dc225b commit ef4f30b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

edupage_api/grades.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from enum import Enum
55
from typing import Optional, Union
66

7+
from edupage_api import grades
78
from edupage_api.dbi import DbiHelper
89
from edupage_api.exceptions import FailedToParseGradeDataError
910
from edupage_api.module import Module, ModuleHelper
@@ -21,10 +22,11 @@ class EduGrade:
2122
subject_name: Optional[str]
2223
teacher: Optional[EduTeacher]
2324
max_points: Optional[float]
25+
more_details: Optional[list[str]]
2426
importance: float
2527
verbal: bool
2628
percent: float
27-
29+
class_grade_avg: Optional[float]
2830

2931
class Term(Enum):
3032
FIRST = "P1"
@@ -121,6 +123,14 @@ def get_grades(self, term: Optional[Term], year: Optional[int]) -> list[EduGrade
121123
max_points = float(details.get("p_vaha_body"))
122124
importance = float(details.get("p_vaha")) / 20
123125

126+
# More details coming from Edupage metadata
127+
more_details_raw = details.get("moredata")
128+
if isinstance(more_details_raw, list):
129+
more_details = [str(item) for item in more_details_raw]
130+
elif more_details_raw is None:
131+
more_details = None
132+
else:
133+
more_details = [str(more_details_raw)]
124134
# Grade
125135
grade_raw = grade.get("data").split(" (", 1)
126136
if grade_raw[0].isdigit():
@@ -146,6 +156,8 @@ def get_grades(self, term: Optional[Term], year: Optional[int]) -> list[EduGrade
146156
except:
147157
verbal = True
148158

159+
class_grade_avg = None if details.get("priemer") is None else float(details.get("priemer"))
160+
149161
grade = EduGrade(
150162
event_id,
151163
title,
@@ -156,9 +168,11 @@ def get_grades(self, term: Optional[Term], year: Optional[int]) -> list[EduGrade
156168
subject_name,
157169
teacher,
158170
max_points,
171+
more_details,
159172
importance,
160173
verbal,
161174
percent,
175+
class_grade_avg
162176
)
163177
output.append(grade)
164178

0 commit comments

Comments
 (0)