Esempio n. 1
0
def subsection_grade_calculated(subsection_grade):
    """
    Emits an edx.grades.subsection.grade_calculated event
    with data from the passed subsection_grade.
    """
    event_name = SUBSECTION_GRADE_CALCULATED
    context = contexts.course_context_from_course_id(subsection_grade.course_id)
    # TODO (AN-6134): remove this context manager
    with tracker.get_tracker().context(event_name, context):
        tracker.emit(
            event_name,
            {
                'user_id': str(subsection_grade.user_id),
                'course_id': str(subsection_grade.course_id),
                'block_id': str(subsection_grade.usage_key),
                'course_version': str(subsection_grade.course_version),
                'weighted_total_earned': subsection_grade.earned_all,
                'weighted_total_possible': subsection_grade.possible_all,
                'weighted_graded_earned': subsection_grade.earned_graded,
                'weighted_graded_possible': subsection_grade.possible_graded,
                'first_attempted': str(subsection_grade.first_attempted),
                'subtree_edited_timestamp': str(subsection_grade.subtree_edited_timestamp),
                'event_transaction_id': str(get_event_transaction_id()),
                'event_transaction_type': str(get_event_transaction_type()),
                'visible_blocks_hash': str(subsection_grade.visible_blocks_id),
            }
        )
def course_grade_calculated(course_grade):
    """
    Emits an edx.grades.course.grade_calculated event
    with data from the passed course_grade.
    """
    event_name = COURSE_GRADE_CALCULATED
    context = contexts.course_context_from_course_id(course_grade.course_id)
    # TODO (AN-6134): remove this context manager
    with tracker.get_tracker().context(event_name, context):
        tracker.emit(
            event_name, {
                'user_id':
                str(course_grade.user_id),
                'course_id':
                str(course_grade.course_id),
                'course_version':
                str(course_grade.course_version),
                'percent_grade':
                course_grade.percent_grade,
                'letter_grade':
                str(course_grade.letter_grade),
                'course_edited_timestamp':
                str(course_grade.course_edited_timestamp),
                'event_transaction_id':
                str(get_event_transaction_id()),
                'event_transaction_type':
                str(get_event_transaction_type()),
                'grading_policy_hash':
                str(course_grade.grading_policy_hash),
            })
Esempio n. 3
0
def emit_team_event(event_name, course_key, event_data):
    """
    Emit team events with the correct course id context.
    """
    context = contexts.course_context_from_course_id(course_key)

    with tracker.get_tracker().context(event_name, context):
        tracker.emit(event_name, event_data)
Esempio n. 4
0
def course_grade_now_failed(user, course_id):
    """
    Emits an edx.course.grade.now_failed event
    with data from the course and user failed now .
    """
    event_name = COURSE_GRADE_NOW_FAILED_EVENT_TYPE
    context = contexts.course_context_from_course_id(course_id)
    with tracker.get_tracker().context(event_name, context):
        tracker.emit(
            event_name,
            {
                'user_id': str(user.id),
                'course_id': str(course_id),
                'event_transaction_id': str(get_event_transaction_id()),
                'event_transaction_type': str(get_event_transaction_type())
            }
        )
Esempio n. 5
0
 def publish_event(event_name, result, **kwargs):
     """
     Helper function to publish an event for analytics purposes
     """
     event_data = {
         "location": six.text_type(location),
         "previous_count": previous_count,
         "result": result,
         "max_count": max_count,
     }
     event_data.update(kwargs)
     context = contexts.course_context_from_course_id(location.course_key)
     if user_id:
         context['user_id'] = user_id
     full_event_name = "edx.librarycontentblock.content.{}".format(event_name)
     with tracker.get_tracker().context(full_event_name, context):
         tracker.emit(full_event_name, event_data)
Esempio n. 6
0
def course_grade_passed_first_time(user_id, course_id):
    """
    Emits an event edx.course.grade.passed.first_time
    with data from the passed course_grade.
    """
    event_name = COURSE_GRADE_PASSED_FIRST_TIME_EVENT_TYPE
    context = contexts.course_context_from_course_id(course_id)
    # TODO (AN-6134): remove this context manager
    with tracker.get_tracker().context(event_name, context):
        tracker.emit(
            event_name,
            {
                'user_id': str(user_id),
                'course_id': str(course_id),
                'event_transaction_id': str(get_event_transaction_id()),
                'event_transaction_type': str(get_event_transaction_type())
            }
        )