Skip to content

Commit

Permalink
fixup! ✨(models) add assessment xAPI profile
Browse files Browse the repository at this point in the history
  • Loading branch information
quitterie-lcs committed May 9, 2023
1 parent 8461478 commit 753179b
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 144 deletions.
23 changes: 6 additions & 17 deletions src/ralph/models/xapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# flake8: noqa

from .assessment.statements import (
AssessmentCompleted,
AssessmentInitialized,
AssessmentLaunched,
AssessmentTerminated,
)
from .navigation.statements import PageTerminated, PageViewed
from .video.statements import (
VideoCompleted,
Expand All @@ -14,20 +20,3 @@
VideoTerminated,
VideoVolumeChangeInteraction,
)
from .virtual_classroom.statements import (
VirtualClassroomAnsweredPoll,
VirtualClassroomInitialized,
VirtualClassroomJoined,
VirtualClassroomLeft,
VirtualClassroomLoweredHand,
VirtualClassroomMuted,
VirtualClassroomPostedPublicMessage,
VirtualClassroomRaisedHand,
VirtualClassroomSharedScreen,
VirtualClassroomStartedCamera,
VirtualClassroomStartedPoll,
VirtualClassroomStoppedCamera,
VirtualClassroomTerminated,
VirtualClassroomUnmuted,
VirtualClassroomUnsharedScreen
)
61 changes: 61 additions & 0 deletions src/ralph/models/xapi/assessment/contexts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""`Assessment` xAPI events context fields definitions."""

from typing import List, Union

from ..base.contexts import BaseXapiContext, BaseXapiContextContextActivities
from ..base.unnested_objects import BaseXapiActivityType, BaseXapiActivityTypeDefinition
from ..concepts.constants.assessment import ASSESSMENT_CONTEXT_CATEGORY
from ..constants import CONTEXT_CONTEXTACTIVTIES_CATEGORY_DEFINITION_TYPE


class AssessmentContextActivitiesCategoryDefinition(BaseXapiActivityTypeDefinition):
# noqa: D205
"""Pydantic model for assessment `context`.`contextActivities`.`category`.
`definition` property.
Attributes:
type (str): Consists of the value `http://adlnet.gov/expapi/activities/profile`.
"""

type: CONTEXT_CONTEXTACTIVTIES_CATEGORY_DEFINITION_TYPE = (
CONTEXT_CONTEXTACTIVTIES_CATEGORY_DEFINITION_TYPE.__args__[0]
)


class AssessmentContextActivitiesCategory(BaseXapiActivityType):
# noqa: D205, D415
"""Pydantic model for assessment `context`.`contextActivities`.`category`
property.
Attributes:
id (str): Consists of the value `https://w3id.org/xapi/virtual-classroom`.
definition (dict): see AssessmentContextActivitiesCategoryDefinition.
"""

id: ASSESSMENT_CONTEXT_CATEGORY = ASSESSMENT_CONTEXT_CATEGORY.__args__[0]
definition: AssessmentContextActivitiesCategoryDefinition = (
AssessmentContextActivitiesCategoryDefinition()
)


class AssessmentContextActivities(BaseXapiContextContextActivities):
"""Pydantic model for assessment `context`.`contextActivities` property.
Attributes:
category (list): see AssessmentContextActivitiesCategory.
"""

category: Union[
AssessmentContextActivitiesCategory,
List[AssessmentContextActivitiesCategory],
] = [AssessmentContextActivitiesCategory()]


class AssessmentContext(BaseXapiContext):
"""Pydantic model for assessment base `context` property.
Attributes:
contextActivities: see AssessmentContextActivities.
"""

contextActivities: AssessmentContextActivities = AssessmentContextActivities()
43 changes: 0 additions & 43 deletions src/ralph/models/xapi/assessment/fields/contexts.py

This file was deleted.

41 changes: 0 additions & 41 deletions src/ralph/models/xapi/assessment/fields/objects.py

This file was deleted.

20 changes: 0 additions & 20 deletions src/ralph/models/xapi/assessment/fields/verbs.py

This file was deleted.

116 changes: 96 additions & 20 deletions src/ralph/models/xapi/assessment/statements.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,110 @@
"""Video xAPI event definitions."""
"""`Assessment` xAPI event definitions."""

from typing import Optional
from datetime import datetime

from ...selector import selector
from ..base import BaseXapiModel
from ..fields.results import ResultField
from .fields.contexts import AssessmentContextField
from .fields.objects import QuestionObjectField
from .fields.verbs import AnsweredVerbField
from ..base.statements import BaseXapiStatement
from ..concepts.activity_types.scorm_profile import CMIInteractionActivityType
from ..concepts.verbs.scorm_profile import (
CompletedVerb,
InitializedVerb,
LaunchedVerb,
TerminatedVerb,
)
from .contexts import AssessmentContext

# Mandatory statements

class AssessmentAnsweredQuestion(BaseXapiModel):
"""Pydantic model for video answered question statement.

Example: John has answered a question in an assessment.
class AssessmentInitialized(BaseXapiStatement):
"""Pydantic model for assessment initialized statement.
Example:
Attributes:
verb (dict): See InitializedVerb.
object (dict): See CMIInteractionActivityType.
context (dict): See AssessmentContext.
timestamp (datetime): Consists of the timestamp of when the event occurred.
"""

__selector__ = selector(
verb__id="http://adlnet.gov/expapi/verbs/initialized",
object__definition__type=(
"http://adlnet.gov/expapi/activities/cmi.interaction"
),
)

verb: InitializedVerb = InitializedVerb()
object: CMIInteractionActivityType
context: AssessmentContext
timestamp: datetime


class AssessmentLaunched(BaseXapiStatement):
"""Pydantic model for assessment launched statement.
Example:
Attributes:
object (dict): See QuestionObjectField.
verb (dict): See AnsweredVerbField.
context (dict): See AssessmentContextField.
verb (dict): See LaunchedVerb.
object (dict): See CMIInteractionActivityType.
context (dict): See AssessmentContext.
timestamp (datetime): Consists of the timestamp of when the event occurred.
"""

__selector__ = selector(
verb__id="http://adlnet.gov/expapi/verbs/answered",
context__contextActivities__definition__type=(
"http://adlnet.gov/expapi/activities/assessment"
verb__id="http://adlnet.gov/expapi/verbs/launched",
object__definition__type=(
"http://adlnet.gov/expapi/activities/cmi.interaction"
),
)

object: QuestionObjectField = QuestionObjectField()
verb: AnsweredVerbField = AnsweredVerbField()
context: AssessmentContextField = AssessmentContextField()
result: Optional[ResultField]
verb: LaunchedVerb = LaunchedVerb()
object: CMIInteractionActivityType
context: AssessmentContext
timestamp: datetime


class AssessmentCompleted(BaseXapiStatement):
"""Pydantic model for assessment completed statement.
Example:
Attributes:
verb (dict): See CompletedVerb.
result (dict): See CMIInteractionActivityType.
context (dict): See VideoCompletedContext.
"""

__selector__ = selector(
object__definition__type="http://adlnet.gov/expapi/activities/cmi.interaction",
verb__id="http://adlnet.gov/expapi/verbs/completed",
)

verb: CompletedVerb = CompletedVerb()
result: CMIInteractionActivityType
context: AssessmentContext
timestamp: datetime


class AssessmentTerminated(BaseXapiStatement):
"""Pydantic model for assessment terminated statement.
Example:
Attributes:
verb (dict): See CompletedVerb.
result (dict): See CMIInteractionActivityType.
context (dict): See VideoCompletedContext.
"""

__selector__ = selector(
object__definition__type="http://adlnet.gov/expapi/activities/cmi.interaction",
verb__id="http://adlnet.gov/expapi/verbs/terminated",
)

verb: TerminatedVerb = TerminatedVerb()
result: CMIInteractionActivityType
context: AssessmentContext
timestamp: datetime
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""`Virtual classroom` activity types definitions."""

from ...fields.unnested_objects import ActivityObjectField, ObjectDefinitionField
from ...base.unnested_objects import (
BaseXapiActivityType,
BaseXapiActivityTypeDefinition,
)
from ..constants.virtual_classroom import VIRTUAL_CLASSROOM_OBJECT_DEFINITION_TYPE


class VirtualClassroomObjectDefinitionField(ObjectDefinitionField):
class VirtualClassroomObjectDefinitionField(BaseXapiActivityTypeDefinition):
"""Pydantic model for virtual classroom `object`.`definition` field.
Attributes:
Expand All @@ -17,7 +20,7 @@ class VirtualClassroomObjectDefinitionField(ObjectDefinitionField):
)


class VirtualClassroomObjectField(ActivityObjectField):
class VirtualClassroomObjectField(BaseXapiActivityType):
"""Pydantic model for virtual classroom `object` field.
Attributes:
Expand Down
11 changes: 11 additions & 0 deletions src/ralph/models/xapi/concepts/constants/assessment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Constants for `Assessment` xAPI profile."""

try:
from typing import Literal
except ImportError:
from typing_extensions import Literal


ASSESSMENT_CONTEXT_CATEGORY = Literal[ # pylint:disable=invalid-name
"https://w3id.org/xapi/assessment"
]
4 changes: 4 additions & 0 deletions src/ralph/models/xapi/concepts/constants/scorm_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
VERB_INTERACTED_ID = Literal[ # pylint:disable=invalid-name
"http://adlnet.gov/expapi/verbs/interacted"
]
VERB_LAUNCHED_ID = Literal[ # pylint:disable=invalid-name
"http://adlnet.gov/expapi/verbs/launched"
]
VERB_TERMINATED_ID = Literal[ # pylint:disable=invalid-name
"http://adlnet.gov/expapi/verbs/terminated"
]
Expand All @@ -23,6 +26,7 @@
VERB_COMPLETED_DISPLAY = Literal["completed"] # pylint:disable=invalid-name
VERB_INITIALIZED_DISPLAY = Literal["initialized"] # pylint:disable=invalid-name
VERB_INTERACTED_DISPLAY = Literal["interacted"] # pylint:disable=invalid-name
VERB_LAUNCHED_DISPLAY = Literal["launched"] # pylint:disable=invalid-name
VERB_TERMINATED_DISPLAY = Literal["terminated"] # pylint:disable=invalid-name

# Activity types IRIs
Expand Down
Loading

0 comments on commit 753179b

Please sign in to comment.