示例#1
0
def get_subsection_grade_percentage(subsection_usage_key, user):
    """
    Computes grade percentage for a subsection in a given course for a user

    Arguments:
        subsection_usage_key: key of subsection
        user: The user whose grade needs to be computed

    Returns:
        User's grade percentage for given subsection
    """
    subsection_grade_percentage = 0.0
    try:
        subsection_structure = get_course_blocks(user, subsection_usage_key)
        if any(subsection_structure):
            subsection_grade_factory = SubsectionGradeFactory(user, course_structure=subsection_structure)
            if subsection_usage_key in subsection_structure:
                # this will force a recalculation of the subsection grade
                subsection_grade = subsection_grade_factory.update(
                    subsection_structure[subsection_usage_key], persist_grade=False
                )
                subsection_grade_percentage = subsection_grade.percent_graded * 100.0
    except ItemNotFoundError as err:
        log.warning("Could not find course_block for subsection=%s error=%s", subsection_usage_key, err)
    return subsection_grade_percentage
示例#2
0
def get_subsection_grade_percentage(subsection_usage_key, user):
    """
    Computes grade percentage for a subsection in a given course for a user

    Arguments:
        subsection_usage_key: key of subsection
        user: The user whose grade needs to be computed

    Returns:
        User's grade percentage for given subsection
    """
    subsection_grade_percentage = 0.0
    try:
        subsection_structure = get_course_blocks(user, subsection_usage_key)
        if any(subsection_structure):
            subsection_grade_factory = SubsectionGradeFactory(
                user, course_structure=subsection_structure)
            if subsection_usage_key in subsection_structure:
                # this will force a recalculation of the subsection grade
                subsection_grade = subsection_grade_factory.update(
                    subsection_structure[subsection_usage_key],
                    persist_grade=False)
                subsection_grade_percentage = subsection_grade.percent_graded * 100.0
    except ItemNotFoundError as err:
        log.warning("Could not find course_block for subsection=%s error=%s",
                    subsection_usage_key, err)
    return subsection_grade_percentage
示例#3
0
def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
    """
    Returns true if the prequiste has been met for a given milestone.
    Will recalculate the subsection grade if specified and prereq unmet

    Arguments:
        content_id (BlockUsageLocator): BlockUsageLocator for the content
        user_id: The id of the user
        recalc_on_unmet: Recalculate the grade if prereq has not yet been met

    Returns:
        tuple: True|False,
        prereq_meta_info = { 'url': prereq_url|None, 'display_name': prereq_name|None}
    """
    course_key = content_id.course_key

    # if unfullfilled milestones exist it means prereq has not been met
    unfulfilled_milestones = milestones_helpers.get_course_content_milestones(
        course_key,
        content_id,
        'requires',
        user_id
    )

    prereq_met = not unfulfilled_milestones
    prereq_meta_info = {'url': None, 'display_name': None}

    if prereq_met or not recalc_on_unmet:
        return prereq_met, prereq_meta_info

    milestone = unfulfilled_milestones[0]
    student = User.objects.get(id=user_id)
    store = modulestore()

    with store.bulk_operations(course_key):
        subsection_usage_key = UsageKey.from_string(_get_gating_block_id(milestone))
        subsection = store.get_item(subsection_usage_key)
        prereq_meta_info = {
            'url': reverse('jump_to', kwargs={'course_id': course_key, 'location': subsection_usage_key}),
            'display_name': subsection.display_name
        }

        try:
            subsection_structure = get_course_blocks(student, subsection_usage_key)
            if any(subsection_structure):
                subsection_grade_factory = SubsectionGradeFactory(student, course_structure=subsection_structure)
                if subsection_usage_key in subsection_structure:
                    # this will force a recalcuation of the subsection grade
                    subsection_grade = subsection_grade_factory.update(subsection_structure[subsection_usage_key], persist_grade=False)
                    prereq_met = update_milestone(milestone, subsection_grade, milestone, user_id)
        except ItemNotFoundError as err:
            log.warning("Could not find course_block for subsection=%s error=%s", subsection_usage_key, err)

    return prereq_met, prereq_meta_info
示例#4
0
 def _get_subsection_grade_and_verify(self, all_earned, all_possible,
                                      graded_earned, graded_possible):
     """
     Retrieves the subsection grade and verifies that
     its scores match those expected.
     """
     subsection_grade_factory = SubsectionGradeFactory(
         self.user, self.course,
         get_course_blocks(self.user, self.course.location))
     grade = subsection_grade_factory.create(self.sequence)
     self.assertEqual(grade.all_total.earned, all_earned)
     self.assertEqual(grade.graded_total.earned, graded_earned)
     self.assertEqual(grade.all_total.possible, all_possible)
     self.assertEqual(grade.graded_total.possible, graded_possible)
示例#5
0
 def _get_grade_data_for_not_attempted_assignment(self, user_id, usage_key):
     """
     Return grade for an assignment that wasn't attempted
     """
     student = get_user_model().objects.get(id=user_id)
     course_structure = get_course_blocks(student, usage_key)
     subsection_grade_factory = SubsectionGradeFactory(student, course_structure=course_structure)
     grade = subsection_grade_factory.create(course_structure[usage_key], read_only=True, force_calculate=True)
     grade_data = {
         'earned_all': grade.all_total.earned,
         'possible_all': grade.all_total.possible,
         'earned_graded': grade.graded_total.earned,
         'possible_graded': grade.graded_total.possible,
     }
     return grade_data
 def _get_grade_data_for_not_attempted_assignment(self, user_id, usage_key):
     """
     Return grade for an assignment that wasn't attempted
     """
     student = get_user_model().objects.get(id=user_id)
     course_structure = get_course_blocks(student, usage_key)
     if usage_key not in course_structure:
         raise SubsectionUnavailableToUserException(
             _("Cannot override subsection grade: subsection is not available for target learner.")
         )
     subsection_grade_factory = SubsectionGradeFactory(student, course_structure=course_structure)
     grade = subsection_grade_factory.create(course_structure[usage_key], read_only=True, force_calculate=True)
     grade_data = {
         'earned_all': grade.all_total.earned,
         'possible_all': grade.all_total.possible,
         'earned_graded': grade.graded_total.earned,
         'possible_graded': grade.graded_total.possible,
     }
     return grade_data
示例#7
0
def get_subsection_grade_percentage(subsection_usage_key, user):
    """
    Computes grade percentage for a subsection in a given course for a user

    Arguments:
        subsection_usage_key: key of subsection
        user: The user whose grade needs to be computed

    Returns:
        User's grade percentage for given subsection
    """
    try:
        subsection_structure = get_course_blocks(user, subsection_usage_key)
        if any(subsection_structure):
            subsection_grade_factory = SubsectionGradeFactory(user, course_structure=subsection_structure)
            if subsection_usage_key in subsection_structure:
                subsection_grade = subsection_grade_factory.update(subsection_structure[subsection_usage_key])
                return _get_subsection_percentage(subsection_grade)
    except ItemNotFoundError as err:
        log.warning(u"Could not find course_block for subsection=%s error=%s", subsection_usage_key, err)
    return 0.0
示例#8
0
 def setUp(self):
     super(TestGradesBulkAPIView, self).setUp()
     self.client.login(username=self.global_staff.username, password=self.password)
     self.course_structure = get_course_blocks(self.global_staff, self.course.location)
     self.subsection_grade_factory = SubsectionGradeFactory(self.global_staff, self.course, self.course_structure)
     
     
     with mock_get_score(1, 2):
         self.created_grade = CreateSubsectionGrade(
                 self.section,
                 self.course_structure,
                 self.subsection_grade_factory._submissions_scores,
                 self.subsection_grade_factory._csm_scores,
             )
示例#9
0
def get_subsection_grade_percentage(subsection_usage_key, user):
    """
    Computes grade percentage for a subsection in a given course for a user

    Arguments:
        subsection_usage_key: key of subsection
        user: The user whose grade needs to be computed

    Returns:
        User's grade percentage for given subsection
    """
    try:
        subsection_structure = get_course_blocks(user, subsection_usage_key)
        if any(subsection_structure):
            subsection_grade_factory = SubsectionGradeFactory(
                user, course_structure=subsection_structure)
            if subsection_usage_key in subsection_structure:
                subsection_grade = subsection_grade_factory.update(
                    subsection_structure[subsection_usage_key])
                return _get_subsection_percentage(subsection_grade)
    except ItemNotFoundError as err:
        log.warning(u"Could not find course_block for subsection=%s error=%s",
                    subsection_usage_key, err)
    return 0.0
def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
    """
    Returns true if the prequiste has been met for a given milestone.
    Will recalculate the subsection grade if specified and prereq unmet

    Arguments:
        content_id (BlockUsageLocator): BlockUsageLocator for the content
        user_id: The id of the user
        recalc_on_unmet: Recalculate the grade if prereq has not yet been met

    Returns:
        tuple: True|False,
        prereq_meta_info = { 'url': prereq_url|None, 'display_name': prereq_name|None}
    """
    course_key = content_id.course_key

    # if unfullfilled milestones exist it means prereq has not been met
    unfulfilled_milestones = milestones_helpers.get_course_content_milestones(
        course_key, content_id, 'requires', user_id)

    prereq_met = not unfulfilled_milestones
    prereq_meta_info = {'url': None, 'display_name': None}

    if prereq_met or not recalc_on_unmet:
        return prereq_met, prereq_meta_info

    milestone = unfulfilled_milestones[0]
    student = User.objects.get(id=user_id)
    store = modulestore()

    with store.bulk_operations(course_key):
        subsection_usage_key = UsageKey.from_string(
            _get_gating_block_id(milestone))
        subsection = store.get_item(subsection_usage_key)
        prereq_meta_info = {
            'url':
            reverse('jump_to',
                    kwargs={
                        'course_id': course_key,
                        'location': subsection_usage_key
                    }),
            'display_name':
            subsection.display_name
        }

        try:
            subsection_structure = get_course_blocks(student,
                                                     subsection_usage_key)
            if any(subsection_structure):
                subsection_grade_factory = SubsectionGradeFactory(
                    student, course_structure=subsection_structure)
                if subsection_usage_key in subsection_structure:
                    # this will force a recalcuation of the subsection grade
                    subsection_grade = subsection_grade_factory.update(
                        subsection_structure[subsection_usage_key],
                        persist_grade=False)
                    prereq_met = update_milestone(milestone, subsection_grade,
                                                  milestone, user_id)
        except ItemNotFoundError as err:
            log.warning(
                "Could not find course_block for subsection=%s error=%s",
                subsection_usage_key, err)

    return prereq_met, prereq_meta_info