示例#1
0
def learning_record_on_answer_modified(sender, user, **extra):
    answer = extra.get('answer')

    if XAPI.enabled():
        XAPI.emit(
            XAPIStatement.generate(
                user=user,
                verb=XAPIVerb.generate('completed'),
                object=XAPIObject.answer(answer),
                context=XAPIContext.answer(answer,
                                           registration=answer.attempt_uuid),
                result=XAPIResult.basic_attempt(answer,
                                                answer.content,
                                                success=True,
                                                completion=not answer.draft)))

        XAPI.emit(
            XAPIStatement.generate(
                user=user,
                verb=XAPIVerb.generate('submitted'),
                object=XAPIObject.assignment_attempt(answer.assignment,
                                                     answer),
                context=XAPIContext.assignment_attempt(
                    answer.assignment, registration=answer.attempt_uuid),
                result=XAPIResult.basic(success=True,
                                        completion=not answer.draft)))

    if CaliperSensor.enabled():
        CaliperSensor.emit(
            caliper.events.AssessmentItemEvent(
                action=caliper.constants.CALIPER_ACTIONS["COMPLETED"],
                profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                object=CaliperEntities.assignment_question(answer.assignment),
                generated=CaliperEntities.answer(answer),
                **CaliperEvent._defaults(user,
                                         course=answer.assignment.course)))

        CaliperSensor.emit(
            caliper.events.AssessmentEvent(
                action=caliper.constants.CALIPER_ACTIONS["SUBMITTED"],
                profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                object=CaliperEntities.assignment(answer.assignment),
                generated=CaliperEntities.assignment_attempt(
                    answer.assignment, answer, user),
                **CaliperEvent._defaults(user,
                                         course=answer.assignment.course)))

        CaliperSensor.emit(
            caliper.events.ToolUseEvent(
                action=caliper.constants.CALIPER_ACTIONS["USED"],
                profile=caliper.constants.CALIPER_PROFILES['TOOL_USE'],
                object=CaliperEntities.compair_app(),
                **CaliperEvent._defaults(user,
                                         course=answer.assignment.course)))
示例#2
0
def learning_record_on_detach_file(sender, user, **extra):
    file_record = extra.get('file')
    mimetype, encoding = mimetypes.guess_type(file_record.name)

    assignment = extra.get('assignment')
    answer = extra.get('answer')

    if assignment:
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('removed'),
                    object=XAPIObject.assignment_attachment(
                        file_record, mimetype),
                    context=XAPIContext.assignment_attachment(assignment)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["REMOVED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.assignment_attachment(
                        assignment, file_record, mimetype),
                    **CaliperEvent._defaults(user, course=assignment.course)))

    elif answer:
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('removed'),
                    object=XAPIObject.answer_attachment(file_record, mimetype),
                    context=XAPIContext.answer_attachment(answer)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["REMOVED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.answer_attachment(
                        answer, file_record, mimetype),
                    **CaliperEvent._defaults(user,
                                             course=answer.assignment.course)))
示例#3
0
def learning_record_on_login_with_method(sender, user, **extra):
    if XAPI.enabled():
        XAPI.emit(
            XAPIStatement.generate(
                user=user,
                verb=XAPIVerb.generate('logged in'),
                object=XAPIObject.compair(),
                context=XAPIContext.basic(),
            ))

    if CaliperSensor.enabled():
        CaliperSensor.emit(
            caliper.events.SessionEvent(
                action=caliper.constants.CALIPER_ACTIONS["LOGGED_IN"],
                profile=caliper.constants.CALIPER_PROFILES['SESSION'],
                object=CaliperEntities.compair_app(),
                **CaliperEvent._defaults(user)))
示例#4
0
def learning_record_on_assignment_delete(sender, user, **extra):
    assignment = extra.get('assignment')

    if XAPI.enabled():
        XAPI.emit(
            XAPIStatement.generate(user=user,
                                   verb=XAPIVerb.generate('archived'),
                                   object=XAPIObject.assignment(assignment),
                                   context=XAPIContext.assignment(assignment)))

    if CaliperSensor.enabled():
        CaliperSensor.emit(
            caliper.events.ResourceManagementEvent(
                action=caliper.constants.CALIPER_ACTIONS["ARCHIVED"],
                profile=caliper.constants.
                CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                object=CaliperEntities.assignment(assignment),
                **CaliperEvent._defaults(user, course=assignment.course)))
示例#5
0
def learning_record_on_answer_delete(sender, user, **extra):
    answer = extra.get('answer')

    if XAPI.enabled():
        XAPI.emit(
            XAPIStatement.generate(user=user,
                                   verb=XAPIVerb.generate('archived'),
                                   object=XAPIObject.answer(answer),
                                   context=XAPIContext.answer(answer)))

    if CaliperSensor.enabled():
        CaliperSensor.emit(
            caliper.events.Event(
                action=caliper.constants.CALIPER_ACTIONS["ARCHIVED"],
                profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                object=CaliperEntities.answer(answer),
                **CaliperEvent._defaults(user,
                                         course=answer.assignment.course)))
示例#6
0
def learning_record_on_comparison_update(sender, user, **extra):
    assignment = extra.get('assignment')
    comparison = extra.get('comparison')
    is_comparison_example = extra.get('is_comparison_example')

    comparison_count = assignment.completed_comparison_count_for_user(user.id)
    current_comparison = comparison_count if comparison.completed else comparison_count + 1

    if XAPI.enabled():
        XAPI.emit(
            XAPIStatement.generate(user=user,
                                   verb=XAPIVerb.generate('completed'),
                                   object=XAPIObject.comparison(comparison),
                                   context=XAPIContext.comparison(
                                       comparison,
                                       current_comparison,
                                       registration=comparison.attempt_uuid),
                                   result=XAPIResult.comparison(
                                       comparison,
                                       success=True,
                                       completion=comparison.completed)))

        XAPI.emit(
            XAPIStatement.generate(
                user=user,
                verb=XAPIVerb.generate('submitted'),
                object=XAPIObject.assignment_attempt(comparison.assignment,
                                                     comparison),
                context=XAPIContext.assignment_attempt(
                    comparison.assignment,
                    registration=comparison.attempt_uuid),
                result=XAPIResult.basic(success=True,
                                        completion=comparison.completed)))

    if CaliperSensor.enabled():
        CaliperSensor.emit(
            caliper.events.AssessmentItemEvent(
                action=caliper.constants.CALIPER_ACTIONS["COMPLETED"],
                profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                object=CaliperEntities.comparison_question(
                    comparison.assignment, current_comparison),
                generated=CaliperEntities.comparison(comparison,
                                                     current_comparison),
                **CaliperEvent._defaults(user,
                                         course=comparison.assignment.course)))

        CaliperSensor.emit(
            caliper.events.AssessmentEvent(
                action=caliper.constants.CALIPER_ACTIONS["SUBMITTED"],
                profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                object=CaliperEntities.assignment(comparison.assignment),
                generated=CaliperEntities.assignment_attempt(
                    comparison.assignment, comparison, user),
                **CaliperEvent._defaults(user,
                                         course=comparison.assignment.course)))

        CaliperSensor.emit(
            caliper.events.ToolUseEvent(
                action=caliper.constants.CALIPER_ACTIONS["USED"],
                profile=caliper.constants.CALIPER_PROFILES['TOOL_USE'],
                object=CaliperEntities.compair_app(),
                **CaliperEvent._defaults(user,
                                         course=comparison.assignment.course)))

    if not is_comparison_example and comparison.completed:
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('ranked'),
                    object=XAPIObject.answer(comparison.answer1),
                    context=XAPIContext.answer(
                        comparison.answer1,
                        registration=comparison.attempt_uuid),
                    result=XAPIResult.answer_score(comparison.answer1,
                                                   comparison.answer1.score)))
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('ranked'),
                    object=XAPIObject.answer(comparison.answer2),
                    context=XAPIContext.answer(
                        comparison.answer2,
                        registration=comparison.attempt_uuid),
                    result=XAPIResult.answer_score(comparison.answer2,
                                                   comparison.answer2.score)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["RANKED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.answer(comparison.answer1),
                    **CaliperEvent._defaults(
                        user, course=comparison.assignment.course)))
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["RANKED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.answer(comparison.answer2),
                    **CaliperEvent._defaults(
                        user, course=comparison.assignment.course)))
示例#7
0
def learning_record_on_answer_comment_modified(sender, user, **extra):
    answer_comment = extra.get('answer_comment')
    was_draft = extra.get('was_draft')

    if answer_comment.comment_type == AnswerCommentType.evaluation:
        evaluation_number = extra.get('evaluation_number')

        if XAPI.enabled():
            if not answer_comment.draft:
                XAPI.emit(
                    XAPIStatement.generate(
                        user=user,
                        verb=XAPIVerb.generate(
                            'commented' if was_draft else 'updated'),
                        object=XAPIObject.answer_comment(answer_comment),
                        context=XAPIContext.answer_comment(
                            answer_comment,
                            registration=answer_comment.attempt_uuid),
                        result=XAPIResult.basic_content(
                            answer_comment.content)))

            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('completed'),
                    object=XAPIObject.evaluation_response(answer_comment),
                    context=XAPIContext.evaluation_response(
                        answer_comment,
                        evaluation_number,
                        registration=answer_comment.attempt_uuid),
                    result=XAPIResult.basic_attempt(
                        answer_comment,
                        answer_comment.content,
                        success=True,
                        completion=not answer_comment.draft)))

        if CaliperSensor.enabled():
            if not answer_comment.draft:
                if was_draft:
                    CaliperSensor.emit(
                        caliper.events.FeedbackEvent(
                            action=caliper.constants.
                            CALIPER_ACTIONS["COMMENTED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['FEEDBACK'],
                            object=CaliperEntities.answer(
                                answer_comment.answer),
                            generated=CaliperEntities.answer_comment(
                                answer_comment),
                            **CaliperEvent._defaults(
                                user,
                                course=answer_comment.answer.assignment.course
                            )))
                else:
                    CaliperSensor.emit(
                        caliper.events.Event(
                            action=caliper.constants.
                            CALIPER_ACTIONS["MODIFIED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['GENERAL'],
                            object=CaliperEntities.answer_comment(
                                answer_comment),
                            **CaliperEvent._defaults(
                                user,
                                course=answer_comment.answer.assignment.course
                            )))

            CaliperSensor.emit(
                caliper.events.AssessmentItemEvent(
                    action=caliper.constants.CALIPER_ACTIONS["COMPLETED"],
                    profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                    object=CaliperEntities.evaluation_question(
                        answer_comment.answer.assignment, evaluation_number),
                    generated=CaliperEntities.evaluation_response(
                        answer_comment, evaluation_number),
                    **CaliperEvent._defaults(
                        user, course=answer_comment.answer.assignment.course)))

    elif answer_comment.comment_type == AnswerCommentType.self_evaluation:
        if XAPI.enabled():
            if not answer_comment.draft:
                XAPI.emit(
                    XAPIStatement.generate(
                        user=user,
                        verb=XAPIVerb.generate(
                            'commented' if was_draft else 'updated'),
                        object=XAPIObject.answer_comment(answer_comment),
                        context=XAPIContext.answer_comment(
                            answer_comment,
                            registration=answer_comment.attempt_uuid),
                        result=XAPIResult.basic_content(
                            answer_comment.content)))

            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('completed'),
                    object=XAPIObject.self_evaluation_response(answer_comment),
                    context=XAPIContext.self_evaluation_response(
                        answer_comment,
                        registration=answer_comment.attempt_uuid),
                    result=XAPIResult.basic_attempt(
                        answer_comment,
                        answer_comment.content,
                        success=True,
                        completion=not answer_comment.draft)))

            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('submitted'),
                    object=XAPIObject.assignment_attempt(
                        answer_comment.answer.assignment, answer_comment),
                    context=XAPIContext.assignment_attempt(
                        answer_comment.answer.assignment,
                        registration=answer_comment.attempt_uuid),
                    result=XAPIResult.basic(
                        success=True, completion=not answer_comment.draft)))

        if CaliperSensor.enabled():
            if not answer_comment.draft:
                if was_draft:
                    CaliperSensor.emit(
                        caliper.events.FeedbackEvent(
                            action=caliper.constants.
                            CALIPER_ACTIONS["COMMENTED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['FEEDBACK'],
                            object=CaliperEntities.answer(
                                answer_comment.answer),
                            generated=CaliperEntities.answer_comment(
                                answer_comment),
                            **CaliperEvent._defaults(
                                user,
                                course=answer_comment.answer.assignment.course
                            )))
                else:
                    CaliperSensor.emit(
                        caliper.events.Event(
                            action=caliper.constants.
                            CALIPER_ACTIONS["MODIFIED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['GENERAL'],
                            object=CaliperEntities.answer_comment(
                                answer_comment),
                            **CaliperEvent._defaults(
                                user,
                                course=answer_comment.answer.assignment.course
                            )))

            CaliperSensor.emit(
                caliper.events.AssessmentItemEvent(
                    action=caliper.constants.CALIPER_ACTIONS["COMPLETED"],
                    profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                    object=CaliperEntities.self_evaluation_question(
                        answer_comment.answer.assignment),
                    generated=CaliperEntities.self_evaluation_response(
                        answer_comment),
                    **CaliperEvent._defaults(
                        user, course=answer_comment.answer.assignment.course)))

            CaliperSensor.emit(
                caliper.events.AssessmentEvent(
                    action=caliper.constants.CALIPER_ACTIONS["SUBMITTED"],
                    profile=caliper.constants.CALIPER_PROFILES['ASSESSMENT'],
                    object=CaliperEntities.assignment(
                        answer_comment.answer.assignment),
                    generated=CaliperEntities.assignment_attempt(
                        answer_comment.answer.assignment, answer_comment,
                        answer_comment.user),
                    **CaliperEvent._defaults(
                        user, course=answer_comment.answer.assignment.course)))

            CaliperSensor.emit(
                caliper.events.ToolUseEvent(
                    action=caliper.constants.CALIPER_ACTIONS["USED"],
                    profile=caliper.constants.CALIPER_PROFILES['TOOL_USE'],
                    object=CaliperEntities.compair_app(),
                    **CaliperEvent._defaults(
                        user, course=answer_comment.answer.assignment.course)))

    else:
        # (public or private)

        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('updated'),
                    object=XAPIObject.answer_comment(answer_comment),
                    context=XAPIContext.answer_comment(answer_comment),
                    result=XAPIResult.basic_content(answer_comment.content)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["MODIFIED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.answer_comment(answer_comment),
                    **CaliperEvent._defaults(
                        user, course=answer_comment.answer.assignment.course)))
示例#8
0
def learning_record_on_get_file(sender, user, **extra):
    file_type = extra.get('file_type')
    file_name = extra.get('file_name')
    mimetype, encoding = mimetypes.guess_type(file_name)

    # only send when file_type is report
    if file_type and file_type == 'report':
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(user=user,
                                       verb=XAPIVerb.generate('downloaded'),
                                       object=XAPIObject.report(
                                           file_name, mimetype)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.ResourceManagementEvent(
                    action=caliper.constants.CALIPER_ACTIONS["DOWNLOADED"],
                    profile=caliper.constants.
                    CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                    object=CaliperEntities.report(file_name, mimetype),
                    **CaliperEvent._defaults(user)))

    elif file_type and file_type == 'attachment':
        file_record = File.query.filter_by(name=file_name).first()
        if file_record:
            assignment = file_record.assignments.first()
            answer = file_record.answers.first()

            if assignment:
                if XAPI.enabled():
                    XAPI.emit(
                        XAPIStatement.generate(
                            user=user,
                            verb=XAPIVerb.generate('downloaded'),
                            object=XAPIObject.assignment_attachment(
                                file_record, mimetype),
                            context=XAPIContext.assignment_attachment(
                                assignment)))

                if CaliperSensor.enabled():
                    CaliperSensor.emit(
                        caliper.events.ResourceManagementEvent(
                            action=caliper.constants.
                            CALIPER_ACTIONS["DOWNLOADED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                            object=CaliperEntities.assignment_attachment(
                                assignment, file_record, mimetype),
                            **CaliperEvent._defaults(
                                user, course=assignment.course)))

            elif answer:
                if XAPI.enabled():
                    XAPI.emit(
                        XAPIStatement.generate(
                            user=user,
                            verb=XAPIVerb.generate('downloaded'),
                            object=XAPIObject.answer_attachment(
                                file_record, mimetype),
                            context=XAPIContext.answer_attachment(answer)))

                if CaliperSensor.enabled():
                    CaliperSensor.emit(
                        caliper.events.ResourceManagementEvent(
                            action=caliper.constants.
                            CALIPER_ACTIONS["DOWNLOADED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                            object=CaliperEntities.answer_attachment(
                                answer, file_record, mimetype),
                            **CaliperEvent._defaults(
                                user, course=answer.assignment.course)))