Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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