Skip to content

Commit

Permalink
refactor: [ACI-502, ACI-503] redesign course grading events payload
Browse files Browse the repository at this point in the history
  • Loading branch information
wowkalucky committed Mar 26, 2024
1 parent bd6b4ac commit 1b30a5c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 59 deletions.
77 changes: 48 additions & 29 deletions openedx_events/learning/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ class CourseData:
end = attr.ib(type=datetime, default=None)


@attr.s(frozen=True)
class CcxCourseData:
"""
Represents data for a CCX (Custom Courses for edX) course.
Attributes:
ccx_course_key (CCXLocator): The unique identifier for the CCX course.
master_course_key (CourseKey): The unique identifier for the original course from which the CCX is derived.
display_name (str): The name of the CCX course as it should appear to users.
coach_email (str): The email address of the coach (instructor) for the CCX course.
start (str, optional): The start date of the CCX course. Defaults to None, indicating no specific start date.
end (str, optional): The end date of the CCX course. Defaults to None, indicating no specific end date.
max_students_allowed (int, optional): The maximum number of students that can enroll in the CCX course. Defaults to None, indicating no limit.
"""

ccx_course_key = attr.ib(type=CCXLocator)
master_course_key = attr.ib(type=CourseKey)
display_name = attr.ib(type=str, factory=str)
coach_email = attr.ib(type=str, factory=str)
start = attr.ib(type=str, default=None)
end = attr.ib(type=str, default=None)
max_students_allowed = attr.ib(type=int, default=None)


@attr.s(frozen=True)
class CourseEnrollmentData:
"""
Expand Down Expand Up @@ -448,17 +472,36 @@ class CourseNotificationData:


@attr.s(frozen=True)
class UserCourseData:
class CourseGradeThresholdCrossingData:
"""
Attributes defined for Open edX user course data object.
Represents the event data when a user's grade crosses a grading policy threshold in a course.
Arguments:
user (UserData): user associated with the Course Enrollment.
course (CourseData): course where the user is enrolled in.
Attributes:
user (UserData): An instance of UserData containing information about the user whose grade crossed the threshold.
course (CourseData): An instance of CourseData containing details about the course in which the grade threshold was crossed.
update_timestamp (datetime): The timestamp when the grade crossing event was recorded.
grading_policy_hash (str): A hash of the course's grading policy at the time of the event, used for verifying the grading policy has not changed.
"""

user = attr.ib(type=UserData)
course = attr.ib(type=CourseData)
update_timestamp = attr.ib(type=datetime)
grading_policy_hash = attr.ib(type=str)


@attr.s(frozen=True)
class CcxCourseGradeThresholdCrossingData(CourseGradeThresholdCrossingData):
"""
Extends CourseGradeThresholdCrossingData for CCX courses, specifying CCX course data.
This class is used for events where a user's grade crosses a threshold specifically in a CCX course,
providing a custom course attribute suited for CCX course instances.
Attributes:
course (CcxCourseData): An instance of CcxCourseData containing details about the CCX course in which the grade threshold was crossed.
All other attributes are inherited from CourseGradeThresholdCrossingData.
"""
course = attr.ib(type=CcxCourseData)


@attr.s(frozen=True)
Expand Down Expand Up @@ -495,27 +538,3 @@ class BadgeData:
uuid = attr.ib(type=str)
user = attr.ib(type=UserData)
template = attr.ib(type=BadgeTemplateData)


@attr.s(frozen=True)
class CcxCourseData:
"""
Represents data for a CCX (Custom Courses for edX) course.
Attributes:
ccx_course_key (CCXLocator): The unique identifier for the CCX course.
master_course_key (CourseKey): The unique identifier for the original course from which the CCX is derived.
display_name (str): The name of the CCX course as it should appear to users.
coach_email (str): The email address of the coach (instructor) for the CCX course.
start (str, optional): The start date of the CCX course. Defaults to None, indicating no specific start date.
end (str, optional): The end date of the CCX course. Defaults to None, indicating no specific end date.
max_students_allowed (int, optional): The maximum number of students that can enroll in the CCX course. Defaults to None, indicating no limit.
"""

ccx_course_key = attr.ib(type=CCXLocator)
master_course_key = attr.ib(type=CourseKey)
display_name = attr.ib(type=str, factory=str)
coach_email = attr.ib(type=str, factory=str)
start = attr.ib(type=str, default=None)
end = attr.ib(type=str, default=None)
max_students_allowed = attr.ib(type=int, default=None)
61 changes: 31 additions & 30 deletions openedx_events/learning/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

from openedx_events.learning.data import (
BadgeData,
CcxCourseData,
CcxCourseGradeThresholdCrossingData,
CertificateData,
CohortData,
CourseAccessRoleData,
CourseDiscussionConfigurationData,
CourseEnrollmentData,
CourseGradeThresholdCrossingData,
CourseNotificationData,
DiscussionThreadData,
ExamAttemptData,
PersistentCourseGradeData,
ProgramCertificateData,
UserCourseData,
UserData,
UserNotificationData,
XBlockSkillVerificationData,
Expand Down Expand Up @@ -343,25 +343,50 @@
# .. event_type: org.openedx.learning.course.grade.now.passed.v1
# .. event_name: COURSE_GRADE_NOW_PASSED
# .. event_description: Emmited when course grade is passed.
# .. event_data: UserCourseData
# .. event_data: CourseGradeThresholdCrossingData
COURSE_GRADE_NOW_PASSED = OpenEdxPublicSignal(
event_type="org.openedx.learning.course.grade.now.passed.v1",
data={
"user_course_data": UserCourseData,
"course_grade_threshold_crossing": CourseGradeThresholdCrossingData,
}
)

# .. event_type: org.openedx.learning.course.grade.now.failed.v1
# .. event_name: COURSE_GRADE_NOW_FAILED
# .. event_description: Emmited when course grade is failed.
# .. event_data: UserCourseData
# .. event_data: CourseGradeThresholdCrossingData
COURSE_GRADE_NOW_FAILED = OpenEdxPublicSignal(
event_type="org.openedx.learning.course.grade.now.failed.v1",
data={
"user_course_data": UserCourseData,
"course_grade_threshold_crossing": CourseGradeThresholdCrossingData,
}
)


# .. event_type: org.openedx.learning.ccx.course.grade.now.passed.v1
# .. event_name: CCX_COURSE_GRADE_NOW_PASSED
# .. event_description: Emit when a ccx course grade is passed
# .. event_data: CcxCourseGradeThresholdCrossingData
CCX_COURSE_GRADE_NOW_PASSED = OpenEdxPublicSignal(
event_type="org.openedx.learning.ccx.course.grade.now.passed.v1",
data={
"course_grade_threshold_crossing": CcxCourseGradeThresholdCrossingData,
}
)


# .. event_type: org.openedx.learning.ccx.course.grade.now.failed.v1
# .. event_name: CCX_COURSE_GRADE_NOW_FAILED
# .. event_description: Emit when a ccx course grade is failed
# .. event_data: CcxCourseGradeThresholdCrossingData
CCX_COURSE_GRADE_NOW_FAILED = OpenEdxPublicSignal(
event_type="org.openedx.learning.ccx.course.grade.now.failed.v1",
data={
"course_grade_threshold_crossing": CcxCourseGradeThresholdCrossingData,
}
)


# .. event_type: org.openedx.learning.badge.awarded.v1
# .. event_name: BADGE_AWARDED
# .. event_description: Emit when a badge is awarded to a learner
Expand All @@ -384,27 +409,3 @@
"badge": BadgeData,
}
)


# .. event_type: org.openedx.learning.ccx.course.grade.now.passed.v1
# .. event_name: CCX_COURSE_GRADE_NOW_PASSED
# .. event_description: Emit when a ccx course grade is passed
# .. event_data: CcxCourseData
CCX_COURSE_GRADE_NOW_PASSED = OpenEdxPublicSignal(
event_type="org.openedx.learning.ccx.course.grade.now.passed.v1",
data={
"ccx_course": CcxCourseData,
}
)


# .. event_type: org.openedx.learning.ccx.course.grade.now.failed.v1
# .. event_name: CCX_COURSE_GRADE_NOW_FAILED
# .. event_description: Emit when a ccx course grade is failed
# .. event_data: CcxCourseData
CCX_COURSE_GRADE_NOW_FAILED = OpenEdxPublicSignal(
event_type="org.openedx.learning.ccx.course.grade.now.failed.v1",
data={
"ccx_course": CcxCourseData,
}
)

0 comments on commit 1b30a5c

Please sign in to comment.