Exemplo n.º 1
0
 def answer_comment(cls, answer_comment):
     return caliper.entities.Comment(
         id=ResourceIRI.answer_comment(answer_comment.course_uuid,
                                       answer_comment.assignment_uuid,
                                       answer_comment.answer_uuid,
                                       answer_comment.uuid),
         commenter=CaliperActor.generate_actor(answer_comment.user),
         commentedOn=CaliperEntities.answer(answer_comment.answer),
         value=LearningRecord.trim_text_to_size_limit(
             answer_comment.content),
         dateCreated=answer_comment.created.replace(
             tzinfo=pytz.utc).strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
         dateModified=answer_comment.modified.replace(
             tzinfo=pytz.utc).strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
         extensions={
             "type":
             answer_comment.comment_type.value,
             "isDraft":
             answer_comment.draft,
             "characterCount":
             LearningRecord.character_count(answer_comment.content)
             if answer_comment.content else 0,
             "wordCount":
             LearningRecord.word_count(answer_comment.content)
             if answer_comment.content else 0
         })
Exemplo n.º 2
0
    def membership(cls, course, user):
        roles = []
        extensions = {}

        course_role = user.get_course_role(course.id)
        if course_role in [
                CourseRole.instructor, CourseRole.teaching_assistant
        ]:
            roles.append("Instructor")
        if course_role == CourseRole.teaching_assistant:
            roles.append("Instructor#TeachingAssistant")
        if course_role == CourseRole.student:
            roles.append("Learner")
        if user.system_role == SystemRole.sys_admin:
            roles.append("Administrator")

        if course.lti_has_sis_data:
            sis_data = course.lti_sis_data
            extensions['sis_courses'] = []
            for sis_course_id, sis_section_ids in sis_data.items():
                extensions['sis_courses'].append({
                    'id': sis_course_id,
                    'section_ids': sis_section_ids
                })

        return caliper.entities.Membership(
            id=ResourceIRI.user_membership(course.uuid, user.uuid),
            member=CaliperActor.generate_actor(user),
            organization=ResourceIRI.course(course.uuid),
            roles=roles if len(roles) > 0 else None,
            status="Active"
            if course_role != CourseRole.dropped else "Inactive",
            extensions=extensions)
Exemplo n.º 3
0
    def comparison_attempt(cls, comparison, current_comparison):
        ret = {
            "id": ResourceIRI.comparison_attempt(comparison.course_uuid, comparison.assignment_uuid, current_comparison, comparison.attempt_uuid),
            "type": CALIPER_ENTITY_TYPES["ATTEMPT"],
            "assignee": CaliperActor.generate_actor(comparison.user),
            "assignable": CaliperEntities.comparison_question(comparison.assignment, current_comparison),
        }
        ret.update(cls._basic_attempt(comparison))

        return ret
Exemplo n.º 4
0
    def answer_attempt(cls, answer):
        ret = {
            "id": ResourceIRI.answer_attempt(answer.course_uuid, answer.assignment_uuid, answer.attempt_uuid),
            "type": CALIPER_ENTITY_TYPES["ATTEMPT"],
            "assignee": CaliperActor.generate_actor(answer.user),
            "assignable": CaliperEntities.assignment_question(answer.assignment),
        }
        ret.update(cls._basic_attempt(answer))

        return ret
Exemplo n.º 5
0
    def assignment_attempt(cls, assignment, attempt_mixin_object, user):
        ret = {
            "id": ResourceIRI.assignment_attempt(assignment.course_uuid, assignment.uuid, attempt_mixin_object.attempt_uuid),
            "type": CALIPER_ENTITY_TYPES["ATTEMPT"],
            "assignee": CaliperActor.generate_actor(user),
            "assignable": CaliperEntities.assignment(assignment),
        }
        ret.update(cls._basic_attempt(attempt_mixin_object))

        return ret
Exemplo n.º 6
0
    def assignment_attempt(cls, assignment, attempt_mixin_object, user):
        (duration, startedAtTime,
         endedAtTime) = cls._basic_attempt(attempt_mixin_object)

        return caliper.entities.Attempt(
            id=ResourceIRI.assignment_attempt(
                assignment.course_uuid, assignment.uuid,
                attempt_mixin_object.attempt_uuid),
            assignee=CaliperActor.generate_actor(user),
            assignable=CaliperEntities.assignment(assignment),
            duration=duration,
            startedAtTime=startedAtTime,
            endedAtTime=endedAtTime)
Exemplo n.º 7
0
    def self_evaluation_attempt(cls, answer_comment):
        (duration, startedAtTime,
         endedAtTime) = cls._basic_attempt(answer_comment)

        return caliper.entities.Attempt(
            id=ResourceIRI.self_evaluation_attempt(
                answer_comment.course_uuid, answer_comment.assignment_uuid,
                answer_comment.attempt_uuid),
            assignee=CaliperActor.generate_actor(answer_comment.user),
            assignable=CaliperEntities.self_evaluation_question(
                answer_comment.answer.assignment),
            duration=duration,
            startedAtTime=startedAtTime,
            endedAtTime=endedAtTime)
Exemplo n.º 8
0
    def comparison_attempt(cls, comparison, current_comparison):
        (duration, startedAtTime, endedAtTime) = cls._basic_attempt(comparison)

        return caliper.entities.Attempt(
            id=ResourceIRI.comparison_attempt(comparison.course_uuid,
                                              comparison.assignment_uuid,
                                              current_comparison,
                                              comparison.attempt_uuid),
            assignee=CaliperActor.generate_actor(comparison.user),
            assignable=CaliperEntities.comparison_question(
                comparison.assignment, current_comparison),
            duration=duration,
            startedAtTime=startedAtTime,
            endedAtTime=endedAtTime)
Exemplo n.º 9
0
    def group(cls, group):
        members = [
            CaliperActor.generate_actor(uc.user)
            for uc in group.user_courses.all()
        ]

        return caliper.entities.Group(
            id=ResourceIRI.group(group.course_uuid, group.uuid),
            name=group.name,
            subOrganizationOf=ResourceIRI.course(group.course_uuid),
            members=members,
            dateCreated=group.created.replace(
                tzinfo=pytz.utc).strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
            dateModified=group.modified.replace(
                tzinfo=pytz.utc).strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
        )
Exemplo n.º 10
0
 def answer_comment(cls, answer_comment):
     #TODO: this isn't in the Caliper spec yet
     return {
         "id": ResourceIRI.answer_comment(answer_comment.course_uuid, answer_comment.assignment_uuid,
             answer_comment.answer_uuid, answer_comment.uuid),
         "type": "Comment",
         "commenter": CaliperActor.generate_actor(answer_comment.user),
         "commented": CaliperEntities.answer(answer_comment.answer),
         "value": LearningRecord.trim_text_to_size_limit(answer_comment.content),
         "dateCreated": answer_comment.created.replace(tzinfo=pytz.utc).isoformat(),
         "dateModified": answer_comment.modified.replace(tzinfo=pytz.utc).isoformat(),
         "extensions": {
             "type": answer_comment.comment_type.value,
             "isDraft": answer_comment.draft,
             "characterCount": LearningRecord.character_count(answer_comment.content) if answer_comment.content else 0,
             "wordCount": LearningRecord.word_count(answer_comment.content) if answer_comment.content else 0
         }
     }
Exemplo n.º 11
0
    def membership(cls, course, user):
        membership = {
            "id": ResourceIRI.user_membership(course.uuid, user.uuid),
            "type": CALIPER_ENTITY_TYPES["MEMBERSHIP"],
            "member": CaliperActor.generate_actor(user),
            "organization": ResourceIRI.course(course.uuid),
            "status": "Active",
            "extensions": {}
        }

        roles = []
        course_role = user.get_course_role(course.id)
        if course_role in [CourseRole.instructor, CourseRole.teaching_assistant]:
            roles.append("Instructor")
        if course_role == CourseRole.teaching_assistant:
            roles.append("Instructor#TeachingAssistant")
        if course_role == CourseRole.student:
            roles.append("Learner")
        if user.system_role == SystemRole.sys_admin:
            roles.append("Administrator")

        if len(roles) > 0:
            membership["roles"] = roles

        if course_role == CourseRole.dropped:
            membership['status'] = "Inactive"

        if course.lti_has_sis_data:
            sis_data = course.lti_sis_data
            membership['extensions']['sis_courses'] = []
            membership['extensions']['sis_sections'] = []
            for sis_course_id, sis_section_ids in sis_data.items():
                membership['extensions']['sis_courses'].append(ResourceIRI.sis_course(sis_course_id))

                for sis_section_id in sis_section_ids:
                    membership['extensions']['sis_sections'].append(ResourceIRI.sis_section(sis_course_id, sis_section_id))

            sis_course_id = list(sis_data.keys())[0]
            sis_section_id = sis_data[sis_course_id][0]
            membership['organization'] = cls.course_section(sis_course_id, sis_section_id)

        return membership
Exemplo n.º 12
0
    def answer_attempt(cls, answer):
        (duration, startedAtTime, endedAtTime) = cls._basic_attempt(answer)

        assignee = None
        extensions = {}

        # Caliper v1.1, v1.2 doesn't easily support tracking group submissions
        # might be able to use assignee in v1.3 https://github.com/IMSGlobal/caliper-spec/issues/535
        if answer.group_id != None:
            extensions['group'] = CaliperEntities.group(answer.group).as_dict()
        else:
            assignee = CaliperActor.generate_actor(answer.user)

        return caliper.entities.Attempt(
            id=ResourceIRI.answer_attempt(answer.course_uuid,
                                          answer.assignment_uuid,
                                          answer.attempt_uuid),
            assignee=assignee,
            assignable=CaliperEntities.assignment_question(answer.assignment),
            duration=duration,
            startedAtTime=startedAtTime,
            endedAtTime=endedAtTime,
            extensions=extensions)