当前位置: 首页>>代码示例>>Python>>正文


Python contexts.course_context_from_course_id函数代码示例

本文整理汇总了Python中track.contexts.course_context_from_course_id函数的典型用法代码示例。如果您正苦于以下问题:Python course_context_from_course_id函数的具体用法?Python course_context_from_course_id怎么用?Python course_context_from_course_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了course_context_from_course_id函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _emit_grade_calculated_event

 def _emit_grade_calculated_event(grade):
     """
     Emits an edx.grades.subsection.grade_calculated event
     with data from the passed grade.
     """
     # TODO: remove this context manager after completion of AN-6134
     event_name = u'edx.grades.subsection.grade_calculated'
     context = contexts.course_context_from_course_id(grade.course_id)
     with tracker.get_tracker().context(event_name, context):
         tracker.emit(
             event_name,
             {
                 'user_id': unicode(grade.user_id),
                 'course_id': unicode(grade.course_id),
                 'block_id': unicode(grade.usage_key),
                 'course_version': unicode(grade.course_version),
                 'weighted_total_earned': grade.earned_all,
                 'weighted_total_possible': grade.possible_all,
                 'weighted_graded_earned': grade.earned_graded,
                 'weighted_graded_possible': grade.possible_graded,
                 'first_attempted': unicode(grade.first_attempted),
                 'subtree_edited_timestamp': unicode(grade.subtree_edited_timestamp),
                 'event_transaction_id': unicode(get_event_transaction_id()),
                 'event_transaction_type': unicode(get_event_transaction_type()),
                 'visible_blocks_hash': unicode(grade.visible_blocks_id),
             }
         )
开发者ID:bryanlandia,项目名称:edx-platform,代码行数:27,代码来源:models.py

示例2: emit_event

    def emit_event(self, event_name):
        """
        Emits an event to explicitly track course enrollment and unenrollment.
        """

        try:
            context = contexts.course_context_from_course_id(self.course_id)
            assert(isinstance(self.course_id, CourseKey))
            data = {
                'user_id': self.user.id,
                'course_id': self.course_id.to_deprecated_string(),
                'mode': self.mode,
            }

            with tracker.get_tracker().context(event_name, context):
                tracker.emit(event_name, data)

                if settings.FEATURES.get('SEGMENT_IO_LMS') and settings.SEGMENT_IO_LMS_KEY:
                    tracking_context = tracker.get_tracker().resolve_context()
                    analytics.track(self.user_id, event_name, {
                        'category': 'conversion',
                        'label': self.course_id.to_deprecated_string(),
                        'org': self.course_id.org,
                        'course': self.course_id.course,
                        'run': self.course_id.run,
                        'mode': self.mode,
                    }, context={
                        'Google Analytics': {
                            'clientId': tracking_context.get('client_id')
                        }
                    })

        except:  # pylint: disable=bare-except
            if event_name and self.course_id:
                log.exception('Unable to emit event %s for user %s and course %s', event_name, self.user.username, self.course_id)
开发者ID:BinaryStudio,项目名称:edx-platform,代码行数:35,代码来源:models.py

示例3: emit_event

    def emit_event(self, event_name):
        """
        Emits an event to explicitly track course enrollment and unenrollment.
        """

        try:
            context = contexts.course_context_from_course_id(self.course_id)
            assert isinstance(self.course_id, CourseKey)
            data = {"user_id": self.user.id, "course_id": self.course_id.to_deprecated_string(), "mode": self.mode}

            with tracker.get_tracker().context(event_name, context):
                tracker.emit(event_name, data)

                if settings.FEATURES.get("SEGMENT_IO_LMS") and settings.SEGMENT_IO_LMS_KEY:
                    tracking_context = tracker.get_tracker().resolve_context()
                    analytics.track(
                        self.user_id,
                        event_name,
                        {
                            "category": "conversion",
                            "label": self.course_id.to_deprecated_string(),
                            "org": self.course_id.org,
                            "course": self.course_id.course,
                            "run": self.course_id.run,
                            "mode": self.mode,
                        },
                        context={"Google Analytics": {"clientId": tracking_context.get("client_id")}},
                    )

        except:  # pylint: disable=bare-except
            if event_name and self.course_id:
                log.exception(
                    "Unable to emit event %s for user %s and course %s", event_name, self.user.username, self.course_id
                )
开发者ID:daveloper,项目名称:edx-platform,代码行数:34,代码来源:models.py

示例4: subsection_grade_calculated

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': unicode(subsection_grade.user_id),
                'course_id': unicode(subsection_grade.course_id),
                'block_id': unicode(subsection_grade.usage_key),
                'course_version': unicode(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': unicode(subsection_grade.first_attempted),
                'subtree_edited_timestamp': unicode(subsection_grade.subtree_edited_timestamp),
                'event_transaction_id': unicode(get_event_transaction_id()),
                'event_transaction_type': unicode(get_event_transaction_type()),
                'visible_blocks_hash': unicode(subsection_grade.visible_blocks_id),
            }
        )
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:27,代码来源:events.py

示例5: emit_team_event

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)
开发者ID:nanolearningllc,项目名称:edx-platform-cypress-2,代码行数:8,代码来源:views.py

示例6: emit_event

    def emit_event(self, event_name):
        """
        Emits an event to explicitly track course enrollment and unenrollment.
        """

        try:
            context = contexts.course_context_from_course_id(self.course_id)
            data = {"user_id": self.user.id, "course_id": self.course_id, "mode": self.mode}

            with tracker.get_tracker().context(event_name, context):
                server_track(crum.get_current_request(), event_name, data)
        except:  # pylint: disable=bare-except
            if event_name and self.course_id:
                log.exception(
                    "Unable to emit event %s for user %s and course %s", event_name, self.user.username, self.course_id
                )
开发者ID:hmcmooc,项目名称:edx-platform,代码行数:16,代码来源:models.py

示例7: publish_event

 def publish_event(event_name, result, **kwargs):
     """
     Helper function to publish an event for analytics purposes
     """
     event_data = {
         "location": unicode(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)
开发者ID:cmscom,项目名称:edx-platform,代码行数:17,代码来源:library_content.py

示例8: emit_event

    def emit_event(self, event_name):
        """
        Emits an event to explicitly track course enrollment and unenrollment.
        """

        try:
            context = contexts.course_context_from_course_id(self.course_id)
            assert isinstance(self.course_id, SlashSeparatedCourseKey)
            data = {"user_id": self.user.id, "course_id": self.course_id.to_deprecated_string(), "mode": self.mode}

            with tracker.get_tracker().context(event_name, context):
                tracker.emit(event_name, data)
        except:  # pylint: disable=bare-except
            if event_name and self.course_id:
                log.exception(
                    "Unable to emit event %s for user %s and course %s", event_name, self.user.username, self.course_id
                )
开发者ID:kriwil,项目名称:edx-platform,代码行数:17,代码来源:models.py

示例9: emit_event

    def emit_event(self, event_name):
        """
        Emits an event to explicitly track course enrollment and unenrollment.
        """

        try:
            context = contexts.course_context_from_course_id(self.course_id)
            data = {
                'user_id': self.user.id,
                'course_id': self.course_id,
                'mode': self.mode,
            }

            with tracker.get_tracker().context(event_name, context):
                tracker.emit(event_name, data)
        except:  # pylint: disable=bare-except
            if event_name and self.course_id:
                log.exception('Unable to emit event %s for user %s and course %s', event_name, self.user.username, self.course_id)
开发者ID:cecep-edu,项目名称:edx-platform,代码行数:18,代码来源:models.py

示例10: publish

 def publish(block, event_type, event):
     """
     A function that allows XModules to publish events.
     """
     handle_event = get_event_handler(event_type)
     if handle_event and not is_masquerading_as_specific_student(user, course_id):
         handle_event(block, event)
     else:
         context = contexts.course_context_from_course_id(course_id)
         if block.runtime.user_id:
             context['user_id'] = block.runtime.user_id
         context['asides'] = {}
         for aside in block.runtime.get_asides(block):
             if hasattr(aside, 'get_event_context'):
                 aside_event_info = aside.get_event_context(event_type, event)
                 if aside_event_info is not None:
                     context['asides'][aside.scope_ids.block_type] = aside_event_info
         with tracker.get_tracker().context(event_type, context):
             track_function(event_type, event)
开发者ID:dehamzah,项目名称:edx-platform,代码行数:19,代码来源:module_render.py

示例11: publish

 def publish(block, event_type, event):
     """A function that allows XModules to publish events."""
     if event_type == 'grade' and not is_masquerading_as_specific_student(user, course_id):
         SCORE_PUBLISHED.send(
             sender=None,
             block=block,
             user=user,
             raw_earned=event['value'],
             raw_possible=event['max_value'],
             only_if_higher=event.get('only_if_higher'),
         )
     else:
         context = contexts.course_context_from_course_id(course_id)
         if block.runtime.user_id:
             context['user_id'] = block.runtime.user_id
         context['asides'] = {}
         for aside in block.runtime.get_asides(block):
             if hasattr(aside, 'get_event_context'):
                 aside_event_info = aside.get_event_context(event_type, event)
                 if aside_event_info is not None:
                     context['asides'][aside.scope_ids.block_type] = aside_event_info
         with tracker.get_tracker().context(event_type, context):
             track_function(event_type, event)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:23,代码来源:module_render.py

示例12: course_grade_calculated

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': unicode(course_grade.user_id),
                'course_id': unicode(course_grade.course_id),
                'course_version': unicode(course_grade.course_version),
                'percent_grade': course_grade.percent_grade,
                'letter_grade': unicode(course_grade.letter_grade),
                'course_edited_timestamp': unicode(course_grade.course_edited_timestamp),
                'event_transaction_id': unicode(get_event_transaction_id()),
                'event_transaction_type': unicode(get_event_transaction_type()),
                'grading_policy_hash': unicode(course_grade.grading_policy_hash),
            }
        )
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:23,代码来源:events.py


注:本文中的track.contexts.course_context_from_course_id函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。