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


Python ScoresClient.get方法代码示例

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


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

示例1: _calculate_entrance_exam_score

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import get [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

示例2: _calculate_score_for_modules

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import get [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

示例3: _calculate_entrance_exam_score

# 需要导入模块: from courseware.model_data import ScoresClient [as 别名]
# 或者: from courseware.model_data.ScoresClient import get [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


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