Пример #1
0
    def test_get_gating_milestone_is_none(self):
        """ Test test_get_gating_milestone_is_none """

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)

        self.assertIsNone(gating_api.get_gating_milestone(self.course.id, self.seq1.location, 'requires'))
        self.assertIsNone(gating_api.get_gating_milestone(self.course.id, self.seq2.location, 'fulfills'))
Пример #2
0
 def _setup_gating_milestone(self, min_score):
     """
     Setup a gating milestone for testing
     """
     gating_api.add_prerequisite(self.course.id, self.seq1.location)
     gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, min_score)
     self.prereq_milestone = gating_api.get_gating_milestone(self.course.id, self.seq1.location, 'fulfills')
Пример #3
0
def evaluate_prerequisite(course, subsection_grade, user):
    """
    Evaluates any gating milestone relationships attached to the given
    subsection. If the subsection_grade and subsection_completion meets
    the minimum score required by dependent subsections, the related
    milestone will be marked fulfilled for the user.
    """
    prereq_milestone = gating_api.get_gating_milestone(
        course.id, subsection_grade.location, 'fulfills')
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(
                course.id, content_key=None, relationship='requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            grade_percentage = subsection_grade.percent_graded * 100.0 \
                if hasattr(subsection_grade, 'percent_graded') else None

            for milestone in gated_content:
                gating_api.update_milestone(milestone,
                                            subsection_grade.location,
                                            prereq_milestone, user,
                                            grade_percentage)
Пример #4
0
def evaluate_prerequisite(course, subsection_grade, user):
    """
    Evaluates any gating milestone relationships attached to the given
    subsection. If the subsection_grade meets the minimum score required
    by dependent subsections, the related milestone will be marked
    fulfilled for the user.
    """
    prereq_milestone = gating_api.get_gating_milestone(
        course.id, subsection_grade.location, 'fulfills')
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(
                course.id, content_key=None, relationship='requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            for milestone in gated_content:
                min_percentage = _get_minimum_required_percentage(milestone)
                subsection_percentage = _get_subsection_percentage(
                    subsection_grade)
                if subsection_percentage >= min_percentage:
                    milestones_helpers.add_user_milestone({'id': user.id},
                                                          prereq_milestone)
                else:
                    milestones_helpers.remove_user_milestone({'id': user.id},
                                                             prereq_milestone)
Пример #5
0
 def setup_gating_milestone(self, min_score):
     """
     Setup a gating milestone for testing.
     Gating content: seq1 (must be fulfilled before access to seq2)
     Gated content: seq2 (requires completion of seq1 before access)
     """
     gating_api.add_prerequisite(self.course.id, str(self.seq1.location))
     gating_api.set_required_content(self.course.id, str(self.seq2.location), str(self.seq1.location), min_score)
     self.prereq_milestone = gating_api.get_gating_milestone(self.course.id, self.seq1.location, 'fulfills')
Пример #6
0
 def setup_gating_milestone(self, min_score):
     """
     Setup a gating milestone for testing.
     Gating content: seq1 (must be fulfilled before access to seq2)
     Gated content: seq2 (requires completion of seq1 before access)
     """
     gating_api.add_prerequisite(self.course.id, str(self.seq1.location))
     gating_api.set_required_content(self.course.id, str(self.seq2.location), str(self.seq1.location), min_score)
     self.prereq_milestone = gating_api.get_gating_milestone(self.course.id, self.seq1.location, 'fulfills')
Пример #7
0
def evaluate_prerequisite(course, prereq_content_key, user_id):
    """
    Finds the parent subsection of the content in the course and evaluates
    any milestone relationships attached to that subsection. If the calculated
    grade of the prerequisite subsection meets the minimum score required by
    dependent subsections, the related milestone will be fulfilled for the user.

    Arguments:
        user_id (int): ID of User for which evaluation should occur
        course (CourseModule): The course
        prereq_content_key (UsageKey): The prerequisite content usage key

    Returns:
        None
    """
    xblock = modulestore().get_item(prereq_content_key)
    sequential = _get_xblock_parent(xblock, 'sequential')
    if sequential:
        prereq_milestone = gating_api.get_gating_milestone(
            course.id, sequential.location.for_branch(None), 'fulfills')
        if prereq_milestone:
            gated_content_milestones = defaultdict(list)
            for milestone in gating_api.find_gating_milestones(
                    course.id, None, 'requires'):
                gated_content_milestones[milestone['id']].append(milestone)

            gated_content = gated_content_milestones.get(
                prereq_milestone['id'])
            if gated_content:
                from courseware.grades import get_module_score
                user = User.objects.get(id=user_id)
                score = get_module_score(user, course, sequential) * 100
                for milestone in gated_content:
                    # Default minimum score to 100
                    min_score = 100
                    requirements = milestone.get('requirements')
                    if requirements:
                        try:
                            min_score = int(requirements.get('min_score'))
                        except (ValueError, TypeError):
                            log.warning(
                                'Failed to find minimum score for gating milestone %s, defaulting to 100',
                                json.dumps(milestone))

                    if score >= min_score:
                        milestones_api.add_user_milestone({'id': user_id},
                                                          prereq_milestone)
                    else:
                        milestones_api.remove_user_milestone({'id': user_id},
                                                             prereq_milestone)
Пример #8
0
def evaluate_prerequisite(course, prereq_content_key, user_id):
    """
    Finds the parent subsection of the content in the course and evaluates
    any milestone relationships attached to that subsection. If the calculated
    grade of the prerequisite subsection meets the minimum score required by
    dependent subsections, the related milestone will be fulfilled for the user.

    Arguments:
        user_id (int): ID of User for which evaluation should occur
        course (CourseModule): The course
        prereq_content_key (UsageKey): The prerequisite content usage key

    Returns:
        None
    """
    xblock = modulestore().get_item(prereq_content_key)
    sequential = _get_xblock_parent(xblock, 'sequential')
    if sequential:
        prereq_milestone = gating_api.get_gating_milestone(
            course.id,
            sequential.location.for_branch(None),
            'fulfills'
        )
        if prereq_milestone:
            gated_content_milestones = defaultdict(list)
            for milestone in gating_api.find_gating_milestones(course.id, None, 'requires'):
                gated_content_milestones[milestone['id']].append(milestone)

            gated_content = gated_content_milestones.get(prereq_milestone['id'])
            if gated_content:
                from courseware.grades import get_module_score
                user = User.objects.get(id=user_id)
                score = get_module_score(user, course, sequential) * 100
                for milestone in gated_content:
                    # Default minimum score to 100
                    min_score = 100
                    requirements = milestone.get('requirements')
                    if requirements:
                        try:
                            min_score = int(requirements.get('min_score'))
                        except (ValueError, TypeError):
                            log.warning(
                                'Failed to find minimum score for gating milestone %s, defaulting to 100',
                                json.dumps(milestone)
                            )

                    if score >= min_score:
                        milestones_api.add_user_milestone({'id': user_id}, prereq_milestone)
                    else:
                        milestones_api.remove_user_milestone({'id': user_id}, prereq_milestone)
Пример #9
0
def evaluate_prerequisite(course, subsection_grade, user):
    """
    Evaluates any gating milestone relationships attached to the given
    subsection. If the subsection_grade meets the minimum score required
    by dependent subsections, the related milestone will be marked
    fulfilled for the user.
    """
    prereq_milestone = gating_api.get_gating_milestone(course.id, subsection_grade.location, 'fulfills')
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(course.id, content_key=None, relationship='requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            for milestone in gated_content:
                gating_api.update_milestone(milestone, subsection_grade, prereq_milestone, user.id)
Пример #10
0
def evaluate_prerequisite(course, user, subsection_usage_key, new_score):
    """
    Finds the parent subsection of the content in the course and evaluates
    any milestone relationships attached to that subsection. If the calculated
    grade of the prerequisite subsection meets the minimum score required by
    dependent subsections, the related milestone will be fulfilled for the user.

    Arguments:
        user (User): User for which evaluation should occur
        course (CourseModule): The course
        subsection_usage_key (UsageKey): Usage key of the updated subsection
        new_score (float): New score of the given subsection, in percentage.

    Returns:
        None
    """
    prereq_milestone = gating_api.get_gating_milestone(
        course.id,
        subsection_usage_key,
        'fulfills'
    )
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(course.id, None, 'requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            for milestone in gated_content:
                # Default minimum score to 100
                min_score = 100.0
                requirements = milestone.get('requirements')
                if requirements:
                    try:
                        min_score = float(requirements.get('min_score'))
                    except (ValueError, TypeError):
                        log.warning(
                            'Failed to find minimum score for gating milestone %s, defaulting to 100',
                            json.dumps(milestone)
                        )

                if new_score >= min_score:
                    milestones_helpers.add_user_milestone({'id': user.id}, prereq_milestone)
                else:
                    milestones_helpers.remove_user_milestone({'id': user.id}, prereq_milestone)
Пример #11
0
def evaluate_prerequisite(course, user, subsection_usage_key, new_score):
    """
    Finds the parent subsection of the content in the course and evaluates
    any milestone relationships attached to that subsection. If the calculated
    grade of the prerequisite subsection meets the minimum score required by
    dependent subsections, the related milestone will be fulfilled for the user.

    Arguments:
        user (User): User for which evaluation should occur
        course (CourseModule): The course
        subsection_usage_key (UsageKey): Usage key of the updated subsection
        new_score (float): New score of the given subsection, in percentage.

    Returns:
        None
    """
    prereq_milestone = gating_api.get_gating_milestone(course.id,
                                                       subsection_usage_key,
                                                       'fulfills')
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(
                course.id, None, 'requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            for milestone in gated_content:
                # Default minimum score to 100
                min_score = 100.0
                requirements = milestone.get('requirements')
                if requirements:
                    try:
                        min_score = float(requirements.get('min_score'))
                    except (ValueError, TypeError):
                        log.warning(
                            'Failed to find minimum score for gating milestone %s, defaulting to 100',
                            json.dumps(milestone))

                if new_score >= min_score:
                    milestones_helpers.add_user_milestone({'id': user.id},
                                                          prereq_milestone)
                else:
                    milestones_helpers.remove_user_milestone({'id': user.id},
                                                             prereq_milestone)
Пример #12
0
def evaluate_prerequisite(course, user, subsection_usage_key, new_score):
    """
    Finds the parent subsection of the content in the course and evaluates
    any milestone relationships attached to that subsection. If the calculated
    grade of the prerequisite subsection meets the minimum score required by
    dependent subsections, the related milestone will be fulfilled for the user.

    Arguments:
        course (CourseModule): The course
        prereq_content_key (UsageKey): The prerequisite content usage key
        user_id (int): ID of User for which evaluation should occur

    Returns:
        None
    """
    prereq_milestone = gating_api.get_gating_milestone(course.id,
                                                       subsection_usage_key,
                                                       'fulfills')
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(
                course.id, None, 'requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            for milestone in gated_content:
                # Default minimum score to 100
                min_score = 100
                requirements = milestone.get('requirements')
                if requirements:
                    try:
                        min_score = int(requirements.get('min_score'))
                    except (ValueError, TypeError):
                        # Use default value of 100
                        pass

                if new_score >= min_score:
                    milestones_helpers.add_user_milestone({'id': user.id},
                                                          prereq_milestone)
                else:
                    milestones_helpers.remove_user_milestone({'id': user.id},
                                                             prereq_milestone)
Пример #13
0
def evaluate_prerequisite(course, subsection_grade, user):
    """
    Evaluates any gating milestone relationships attached to the given
    subsection. If the subsection_grade meets the minimum score required
    by dependent subsections, the related milestone will be marked
    fulfilled for the user.
    """
    prereq_milestone = gating_api.get_gating_milestone(course.id, subsection_grade.location, 'fulfills')
    if prereq_milestone:
        gated_content_milestones = defaultdict(list)
        for milestone in gating_api.find_gating_milestones(course.id, content_key=None, relationship='requires'):
            gated_content_milestones[milestone['id']].append(milestone)

        gated_content = gated_content_milestones.get(prereq_milestone['id'])
        if gated_content:
            for milestone in gated_content:
                min_percentage = _get_minimum_required_percentage(milestone)
                subsection_percentage = _get_subsection_percentage(subsection_grade)
                if subsection_percentage >= min_percentage:
                    milestones_helpers.add_user_milestone({'id': user.id}, prereq_milestone)
                else:
                    milestones_helpers.remove_user_milestone({'id': user.id}, prereq_milestone)