Ejemplo n.º 1
0
    def test_reset_score_highest(self):
        item = StudentItem.objects.create(
            student_id="score_test_student",
            course_id="score_test_course",
            item_id="i4x://mycourse/special_presentation"
        )

        # Reset score with no score
        Score.create_reset_score(item)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 0)
        self.assertEqual(highest.points_possible, 0)

        # Non-reset score after a reset score
        submission = Submission.objects.create(student_item=item, attempt_number=1)
        Score.objects.create(
            student_item=item,
            submission=submission,
            points_earned=2,
            points_possible=3,
        )
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 2)
        self.assertEqual(highest.points_possible, 3)

        # Reset score after a non-reset score
        Score.create_reset_score(item)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 0)
        self.assertEqual(highest.points_possible, 0)
Ejemplo n.º 2
0
    def test_reset_score_highest(self):
        item = StudentItem.objects.create(
            student_id="score_test_student",
            course_id="score_test_course",
            item_id="i4x://mycourse/special_presentation")

        # Reset score with no score
        Score.create_reset_score(item)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 0)
        self.assertEqual(highest.points_possible, 0)

        # Non-reset score after a reset score
        submission = Submission.objects.create(student_item=item,
                                               attempt_number=1)
        Score.objects.create(
            student_item=item,
            submission=submission,
            points_earned=2,
            points_possible=3,
        )
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 2)
        self.assertEqual(highest.points_possible, 3)

        # Reset score after a non-reset score
        Score.create_reset_score(item)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 0)
        self.assertEqual(highest.points_possible, 0)
Ejemplo n.º 3
0
def reset_score(student_id, course_id, item_id):
    """
    Reset scores for a specific student on a specific problem.

    Note: this does *not* delete `Score` models from the database,
    since these are immutable.  It simply creates a new score with
    the "reset" flag set to True.

    Args:
        student_id (unicode): The ID of the student for whom to reset scores.
        course_id (unicode): The ID of the course containing the item to reset.
        item_id (unicode): The ID of the item for which to reset scores.

    Returns:
        None

    Raises:
        SubmissionInternalError: An unexpected error occurred while resetting scores.

    """
    # Retrieve the student item
    try:
        student_item = StudentItem.objects.get(
            student_id=student_id, course_id=course_id, item_id=item_id
        )
    except StudentItem.DoesNotExist:
        # If there is no student item, then there is no score to reset,
        # so we can return immediately.
        return

    # Create a "reset" score
    try:
        Score.create_reset_score(student_item)
        # Send a signal out to any listeners who are waiting for scoring events.
        score_reset.send(
            sender=None,
            anonymous_user_id=student_id,
            course_id=course_id,
            item_id=item_id,
        )

    except DatabaseError:
        msg = (
            u"Error occurred while reseting scores for"
            u" item {item_id} in course {course_id} for student {student_id}"
        ).format(item_id=item_id, course_id=course_id, student_id=student_id)
        logger.exception(msg)
        raise SubmissionInternalError(msg)
    else:
        msg = u"Score reset for item {item_id} in course {course_id} for student {student_id}".format(
            item_id=item_id, course_id=course_id, student_id=student_id
        )
        logger.info(msg)
Ejemplo n.º 4
0
    def test_override_highest_no_score(self):
        item = StudentItem.objects.create(
            student_id="score_test_student",
            course_id="score_test_course",
            item_id="i4x://mycourse/special_presentation",
        )

        # Override score with no score
        Score.create_override_score(item, 9, 10)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 9)
        self.assertEqual(highest.points_possible, 10)
Ejemplo n.º 5
0
    def test_override_highest_no_score(self):
        item = StudentItem.objects.create(
            student_id="score_test_student",
            course_id="score_test_course",
            item_id="i4x://mycourse/special_presentation",
        )

        # Override score with no score
        Score.create_override_score(item, 9, 10)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 9)
        self.assertEqual(highest.points_possible, 10)
Ejemplo n.º 6
0
def score_override(student_item_dict, points_override, points_possible):
    """
    Create a score override for peer assessment question.

    Args:
        student_item (dict): The dictionary representation of a student item.
        points_override (string): Points provided by the instructor as an override.
        points_possible (string): Max points for this question.

    Returns:
        True if successful otherwise False
    """
    student_item_model = _get_or_create_student_item(student_item_dict)
    try:
        Score.create_override_score(student_item_model, points_override,
                                    points_possible)
    except (DatabaseError, ValueError):
        msg = (
            u"Error occurred while creating override score for"
            u" item {item_id} in course {course_id} for student {student_id}"
            u" points_possible {points_possible} points_override {points_override}"
        ).format(
            item_id=student_item_dict['item_id'],
            course_id=student_item_dict['course_id'],
            student_id=student_item_dict['student_id'],
            points_possible=points_possible,
            points_override=points_override,
        )
        logger.exception(msg)
        raise SubmissionInternalError(msg)
    else:
        msg = (
            u"Score overridden for item {item_id} in course {course_id} for student {student_id}"
            u" points_possible {points_possible} points_override {points_override}"
        ).format(
            item_id=student_item_dict['item_id'],
            course_id=student_item_dict['course_id'],
            student_id=student_item_dict['student_id'],
            points_possible=points_possible,
            points_override=points_override,
        )
        logger.info(msg)
Ejemplo n.º 7
0
    def test_override_highest_with_score(self):
        item = StudentItem.objects.create(
            student_id="score_test_student",
            course_id="score_test_course",
            item_id="i4x://mycourse/special_presentation",
        )
        # Override score after a non-reset score
        submission = Submission.objects.create(
            student_item=item,
            attempt_number=1,
        )
        Score.objects.create(
            student_item=item,
            submission=submission,
            points_earned=1,
            points_possible=15,
        )

        Score.create_override_score(item, 5, 15)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 5)
        self.assertEqual(highest.points_possible, 15)
Ejemplo n.º 8
0
    def test_override_highest_with_score(self):
        item = StudentItem.objects.create(
            student_id="score_test_student",
            course_id="score_test_course",
            item_id="i4x://mycourse/special_presentation",
        )
        # Override score after a non-reset score
        submission = Submission.objects.create(
            student_item=item,
            attempt_number=1,
        )
        Score.objects.create(
            student_item=item,
            submission=submission,
            points_earned=1,
            points_possible=15,
        )

        Score.create_override_score(item, 5, 15)
        highest = ScoreSummary.objects.get(student_item=item).highest
        self.assertEqual(highest.points_earned, 5)
        self.assertEqual(highest.points_possible, 15)
Ejemplo n.º 9
0
def reset_score(student_id,
                course_id,
                item_id,
                clear_state=False,
                emit_signal=True):
    """
    Reset scores for a specific student on a specific problem.

    Note: this does *not* delete `Score` models from the database,
    since these are immutable.  It simply creates a new score with
    the "reset" flag set to True.

    Args:
        student_id (unicode): The ID of the student for whom to reset scores.
        course_id (unicode): The ID of the course containing the item to reset.
        item_id (unicode): The ID of the item for which to reset scores.
        clear_state (bool): If True, will appear to delete any submissions associated with the specified StudentItem

    Returns:
        None

    Raises:
        SubmissionInternalError: An unexpected error occurred while resetting scores.

    """
    # Retrieve the student item
    try:
        student_item = StudentItem.objects.get(student_id=student_id,
                                               course_id=course_id,
                                               item_id=item_id)
    except StudentItem.DoesNotExist:
        # If there is no student item, then there is no score to reset,
        # so we can return immediately.
        return

    # Create a "reset" score
    try:
        score = Score.create_reset_score(student_item)
        if emit_signal:
            # Send a signal out to any listeners who are waiting for scoring events.
            score_reset.send(
                sender=None,
                anonymous_user_id=student_id,
                course_id=course_id,
                item_id=item_id,
                created_at=score.created_at,
            )

        if clear_state:
            for sub in student_item.submission_set.all():
                # soft-delete the Submission
                sub.status = DELETED
                sub.save(update_fields=["status"])

                # Also clear out cached values
                cache_key = Submission.get_cache_key(sub.uuid)
                cache.delete(cache_key)

    except DatabaseError as error:
        msg = ("Error occurred while reseting scores for"
               " item {item_id} in course {course_id} for student {student_id}"
               ).format(item_id=item_id,
                        course_id=course_id,
                        student_id=student_id)
        logger.exception(msg)
        raise SubmissionInternalError(msg) from error
    else:
        msg = "Score reset for item {item_id} in course {course_id} for student {student_id}".format(
            item_id=item_id, course_id=course_id, student_id=student_id)
        logger.info(msg)
Ejemplo n.º 10
0
def reset_score(student_id, course_id, item_id, clear_state=False, emit_signal=True):
    """
    Reset scores for a specific student on a specific problem.

    Note: this does *not* delete `Score` models from the database,
    since these are immutable.  It simply creates a new score with
    the "reset" flag set to True.

    Args:
        student_id (unicode): The ID of the student for whom to reset scores.
        course_id (unicode): The ID of the course containing the item to reset.
        item_id (unicode): The ID of the item for which to reset scores.
        clear_state (bool): If True, will appear to delete any submissions associated with the specified StudentItem

    Returns:
        None

    Raises:
        SubmissionInternalError: An unexpected error occurred while resetting scores.

    """
    # Retrieve the student item
    try:
        student_item = StudentItem.objects.get(
            student_id=student_id, course_id=course_id, item_id=item_id
        )
    except StudentItem.DoesNotExist:
        # If there is no student item, then there is no score to reset,
        # so we can return immediately.
        return

    # Create a "reset" score
    try:
        score = Score.create_reset_score(student_item)
        if emit_signal:
            # Send a signal out to any listeners who are waiting for scoring events.
            score_reset.send(
                sender=None,
                anonymous_user_id=student_id,
                course_id=course_id,
                item_id=item_id,
                created_at=score.created_at,
            )

        if clear_state:
            for sub in student_item.submission_set.all():
                # soft-delete the Submission
                sub.status = Submission.DELETED
                sub.save(update_fields=["status"])

                # Also clear out cached values
                cache_key = Submission.get_cache_key(sub.uuid)
                cache.delete(cache_key)

    except DatabaseError:
        msg = (
            u"Error occurred while reseting scores for"
            u" item {item_id} in course {course_id} for student {student_id}"
        ).format(item_id=item_id, course_id=course_id, student_id=student_id)
        logger.exception(msg)
        raise SubmissionInternalError(msg)
    else:
        msg = u"Score reset for item {item_id} in course {course_id} for student {student_id}".format(
            item_id=item_id, course_id=course_id, student_id=student_id
        )
        logger.info(msg)