def learning_record_on_logout(sender, user, **extra): if XAPI.enabled(): XAPI.emit( XAPIStatement.generate(user=user, verb=XAPIVerb.generate('logged out'), object=XAPIObject.compair())) if CaliperSensor.enabled(): CaliperSensor.emit( caliper.events.SessionEvent( action=caliper.constants.CALIPER_ACTIONS["LOGGED_OUT"], profile=caliper.constants.CALIPER_PROFILES['SESSION'], object=CaliperEntities.compair_app(), **CaliperEvent._defaults(user)))
def learning_record_on_course_delete(sender, user, **extra): course = extra.get('course') if XAPI.enabled(): XAPI.emit( XAPIStatement.generate(user=user, verb=XAPIVerb.generate('archived'), object=XAPIObject.course(course))) if CaliperSensor.enabled(): CaliperSensor.emit( caliper.events.Event( action=caliper.constants.CALIPER_ACTIONS["ARCHIVED"], profile=caliper.constants.CALIPER_PROFILES['GENERAL'], object=CaliperEntities.course(course), **CaliperEvent._defaults(user, course=course)))
def learning_record_on_criterion_update(sender, user, **extra): criterion = extra.get('criterion') if XAPI.enabled(): XAPI.emit( XAPIStatement.generate(user=user, verb=XAPIVerb.generate('updated'), object=XAPIObject.criterion(criterion))) if CaliperSensor.enabled(): CaliperSensor.emit( caliper.events.ResourceManagementEvent( action=caliper.constants.CALIPER_ACTIONS["MODIFIED"], profile=caliper.constants. CALIPER_PROFILES['RESOURCE_MANAGEMENT'], object=CaliperEntities.criterion(criterion), **CaliperEvent._defaults(user)))
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)))
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)))
def learning_record_on_user_modified(sender, user, **extra): changes = extra.get('data', {}).get('changes') if XAPI.enabled(): XAPI.emit( XAPIStatement.generate( user=user, verb=XAPIVerb.generate('updated'), object=XAPIActor.generate_actor(user), result=XAPIResult.basic(changes=changes) if changes else None)) if CaliperSensor.enabled(): CaliperSensor.emit( caliper.events.Event( action=caliper.constants.CALIPER_ACTIONS["MODIFIED"], profile=caliper.constants.CALIPER_PROFILES['GENERAL'], object=CaliperActor.generate_actor(user), extensions={"changes": changes}, **CaliperEvent._defaults(user)))
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)))
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)))
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)))
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)))