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


Python ScoresClient.fetch_scores方法代码示例

本文整理汇总了Python中courseware.model_data.ScoresClient.fetch_scores方法的典型用法代码示例。如果您正苦于以下问题:Python ScoresClient.fetch_scores方法的具体用法?Python ScoresClient.fetch_scores怎么用?Python ScoresClient.fetch_scores使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在courseware.model_data.ScoresClient的用法示例。


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

示例1: _calculate_score_for_modules

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import fetch_scores [as 别名]
def _calculate_score_for_modules(user_id, course, modules):
    """
    Calculates the cumulative score (percent) of the given modules
    """

    # removing branch and version from exam modules locator
    # otherwise student module would not return scores since module usage keys would not match
    modules = [m for m in modules]
    locations = [
        BlockUsageLocator(
            course_key=course.id,
            block_type=module.location.block_type,
            block_id=module.location.block_id
        )
        if isinstance(module.location, BlockUsageLocator) and module.location.version
        else module.location
        for module in modules
    ]

    scores_client = ScoresClient(course.id, user_id)
    scores_client.fetch_scores(locations)

    # Iterate over all of the exam modules to get score percentage of user for each of them
    module_percentages = []
    ignore_categories = ['course', 'chapter', 'sequential', 'vertical', 'randomize', 'library_content']
    for index, module in enumerate(modules):
        if module.category not in ignore_categories and (module.graded or module.has_score):
            module_score = scores_client.get(locations[index])
            if module_score:
                correct = module_score.correct or 0
                total = module_score.total or 1
                module_percentages.append(correct / total)

    return sum(module_percentages) / float(len(module_percentages)) if module_percentages else 0
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:36,代码来源:module_grades.py

示例2: _calculate_entrance_exam_score

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import fetch_scores [as 别名]
def _calculate_entrance_exam_score(user, course_descriptor, exam_modules):
    """
    Calculates the score (percent) of the entrance exam using the provided modules
    """
    student_module_dict = {}
    scores_client = ScoresClient(course_descriptor.id, user.id)
    locations = [exam_module.location for exam_module in exam_modules]
    scores_client.fetch_scores(locations)

    # Iterate over all of the exam modules to get score of user for each of them
    for exam_module in exam_modules:
        exam_module_score = scores_client.get(exam_module.location)
        if exam_module_score:
            student_module_dict[unicode(exam_module.location)] = {
                "grade": exam_module_score.correct,
                "max_grade": exam_module_score.total,
            }
    exam_percentage = 0
    module_percentages = []
    ignore_categories = ["course", "chapter", "sequential", "vertical"]

    for module in exam_modules:
        if module.graded and module.category not in ignore_categories:
            module_percentage = 0
            module_location = unicode(module.location)
            if module_location in student_module_dict and student_module_dict[module_location]["max_grade"]:
                student_module = student_module_dict[module_location]
                module_percentage = student_module["grade"] / student_module["max_grade"]

            module_percentages.append(module_percentage)
    if module_percentages:
        exam_percentage = sum(module_percentages) / float(len(module_percentages))
    return exam_percentage
开发者ID:chauhanhardik,项目名称:populo,代码行数:35,代码来源:entrance_exams.py

示例3: _calculate_entrance_exam_score

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import fetch_scores [as 别名]
def _calculate_entrance_exam_score(user, course_descriptor, exam_modules):
    """
    Calculates the score (percent) of the entrance exam using the provided modules
    """
    student_module_dict = {}
    scores_client = ScoresClient(course_descriptor.id, user.id)
    # removing branch and version from exam modules locator
    # otherwise student module would not return scores since module usage keys would not match
    locations = [
        BlockUsageLocator(
            course_key=course_descriptor.id,
            block_type=exam_module.location.block_type,
            block_id=exam_module.location.block_id
        )
        if isinstance(exam_module.location, BlockUsageLocator) and exam_module.location.version
        else exam_module.location
        for exam_module in exam_modules
    ]
    scores_client.fetch_scores(locations)

    # Iterate over all of the exam modules to get score of user for each of them
    for index, exam_module in enumerate(exam_modules):
        exam_module_score = scores_client.get(locations[index])
        if exam_module_score:
            student_module_dict[unicode(locations[index])] = {
                'grade': exam_module_score.correct,
                'max_grade': exam_module_score.total
            }
    exam_percentage = 0
    module_percentages = []
    ignore_categories = ['course', 'chapter', 'sequential', 'vertical']

    for index, module in enumerate(exam_modules):
        if module.graded and module.category not in ignore_categories:
            module_percentage = 0
            module_location = unicode(locations[index])
            if module_location in student_module_dict and student_module_dict[module_location]['max_grade']:
                student_module = student_module_dict[module_location]
                module_percentage = student_module['grade'] / student_module['max_grade']

            module_percentages.append(module_percentage)
    if module_percentages:
        exam_percentage = sum(module_percentages) / float(len(module_percentages))
    return exam_percentage
开发者ID:Akif-Vohra,项目名称:edx-platform,代码行数:46,代码来源:entrance_exams.py

示例4: condition_on_problem_list

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import fetch_scores [as 别名]
    def condition_on_problem_list(self, problems):
        """ Returns the score for a list of problems """
        # pylint: disable=no-member
        user_id = self.xmodule_runtime.user_id
        scores_client = ScoresClient(self.course_id, user_id)
        correct_neutral = {'correct': 0.0}
        total_neutral = {'total': 0.0}
        total = 0
        correct = 0

        def _get_usage_key(problem):

            loc = self.get_location_string(problem)
            try:
                uk = UsageKey.from_string(loc)
            except InvalidKeyError:
                uk = _get_draft_usage_key(problem)
            return uk

        def _get_draft_usage_key(problem):

            loc = self.get_location_string(problem, True)
            try:
                uk = UsageKey.from_string(loc)
                uk = uk.map_into_course(self.course_id)
            except InvalidKeyError:
                uk = None

            return uk

        def _to_reducible(score):
            correct_default = 0.0
            total_default = 1.0
            if not score.total:
                return {'correct': correct_default, 'total': total_default}
            else:
                return {'correct': score.correct, 'total': score.total}

        def _calculate_correct(first_score, second_score):
            correct = first_score['correct'] + second_score['correct']
            return {'correct': correct}

        def _calculate_total(first_score, second_score):
            total = first_score['total'] + second_score['total']
            return {'total': total}

        usages_keys = map(_get_usage_key, problems)
        scores_client.fetch_scores(usages_keys)
        scores = map(scores_client.get, usages_keys)
        scores = filter(None, scores)

        problems_to_answer = [score.total for score in scores]
        if self.operator in self.SPECIAL_COMPARISON_DISPATCHER.keys():
            evaluation = self.SPECIAL_COMPARISON_DISPATCHER[self.operator](
                self,
                problems_to_answer)

            return evaluation

        reducible_scores = map(_to_reducible, scores)
        correct = reduce(_calculate_correct, reducible_scores,
                         correct_neutral)
        total = reduce(_calculate_total, reducible_scores,
                       total_neutral)

        return self.compare_scores(correct['correct'], total['total'])
开发者ID:eduNEXT,项目名称:flow-control-xblock,代码行数:68,代码来源:flow.py


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