Commit c19eb221 by Diana Huang Committed by Andy Armstrong

Add grading statistics to the API.

parent a3a23a99
......@@ -230,7 +230,8 @@ def get_assessment_scores_by_criteria(submission_uuid):
def get_submission_to_assess(course_id, item_id, scorer_id):
"""Get a submission for staff evaluation.
"""
Get a submission for staff evaluation.
Retrieves a submission for assessment for the given staff member.
......@@ -281,6 +282,20 @@ def get_submission_to_assess(course_id, item_id, scorer_id):
return None
def get_staff_grading_statistics(course_id, item_id):
"""
Returns the number of graded, ungraded, and in-progress submissions for staff grading.
Args:
course_id (str): The course that this problem belongs to
item_id (str): The student_item (problem) that we want to know statistics about.
Returns:
dict: a dictionary that contains the following keys: 'graded', 'ungraded', and 'in-progress'
"""
return StaffWorkflow.get_workflow_statistics(course_id, item_id)
def create_assessment(
submission_uuid,
scorer_id,
......
......@@ -51,6 +51,35 @@ class StaffWorkflow(models.Model):
return bool(self.cancelled_at)
@classmethod
def get_workflow_statistics(cls, course_id, item_id):
"""
Returns the number of graded, ungraded, and in-progress submissions for staff grading.
Args:
course_id (str): The course that this problem belongs to
item_id (str): The student_item (problem) that we want to know statistics about.
Returns:
dict: a dictionary that contains the following keys: 'graded', 'ungraded', and 'in-progress'
"""
timeout = (now() - cls.TIME_LIMIT).strftime("%Y-%m-%d %H:%M:%S")
ungraded = cls.objects.filter(
models.Q(grading_started_at=None) | models.Q(grading_started_at__lte=timeout),
course_id=course_id, item_id=item_id, grading_completed_at=None, cancelled_at=None
).count()
in_progress = cls.objects.filter(
course_id=course_id, item_id=item_id, grading_completed_at=None, cancelled_at=None,
grading_started_at__gt=timeout
).count()
graded = cls.objects.filter(
course_id=course_id, item_id=item_id, cancelled_at=None
).exclude(grading_completed_at=None).count()
return {'ungraded': ungraded, 'in-progress': in_progress, 'graded': graded}
@classmethod
def get_submission_for_review(cls, course_id, item_id, scorer_id):
"""
Find a submission for staff assessment. This function will find the next
......
......@@ -445,7 +445,48 @@ class TestStaffAssessment(CacheResetTest):
tim_sub, tim = self._create_student_and_submission("Tim", "Tim's answer")
workflow_api.cancel_workflow(tim_sub['uuid'], "Test Cancel", "Bob", {})
workflow = StaffWorkflow.objects.get(submission_uuid=tim_sub['uuid'])
self.assertIsNotNone(workflow.cancelled_at)
self.assertTrue(workflow.is_cancelled)
def test_grading_statistics(self):
bob_sub, bob = self._create_student_and_submission("bob", "bob's answer")
course_id = bob['course_id']
item_id = bob['item_id']
tim_sub, tim = self._create_student_and_submission("Tim", "Tim's answer")
sue_sub, sue = self._create_student_and_submission("Sue", "Sue's answer")
stats = staff_api.get_staff_grading_statistics(course_id, item_id)
self.assertEqual(stats, {'graded': 0, 'ungraded': 3, 'in-progress': 0})
# Fetch a grade so that there's one 'in-progress'
tim_to_grade = staff_api.get_submission_to_assess(course_id, item_id, tim['student_id'])
stats = staff_api.get_staff_grading_statistics(course_id, item_id)
self.assertEqual(stats, {'graded': 0, 'ungraded': 2, 'in-progress': 1})
bob_to_grade = staff_api.get_submission_to_assess(tim['course_id'], tim['item_id'], bob['student_id'])
stats = staff_api.get_staff_grading_statistics(course_id, item_id)
self.assertEqual(stats, {'graded': 0, 'ungraded': 1, 'in-progress': 2})
# Grade one of the submissions
staff_assessment = staff_api.create_assessment(
tim_to_grade["uuid"],
tim['student_id'],
OPTIONS_SELECTED_DICT["all"]["options"], dict(), "",
RUBRIC,
)
stats = staff_api.get_staff_grading_statistics(course_id, item_id)
self.assertEqual(stats, {'graded': 1, 'ungraded': 1, 'in-progress': 1})
# When one of the 'locks' times out, verify that it is no longer
# considered ungraded.
workflow = StaffWorkflow.objects.get(scorer_id=bob['student_id'])
timestamp = (now() - (workflow.TIME_LIMIT + timedelta(hours=1))).strftime("%Y-%m-%d %H:%M:%S")
workflow.grading_started_at = timestamp
workflow.save()
stats = staff_api.get_staff_grading_statistics(course_id, item_id)
self.assertEqual(stats, {'graded': 1, 'ungraded': 2, 'in-progress': 0})
workflow_api.cancel_workflow(bob_to_grade['uuid'], "Test Cancel", bob['student_id'], {})
stats = staff_api.get_staff_grading_statistics(course_id, item_id)
self.assertEqual(stats, {'graded': 1, 'ungraded': 1, 'in-progress': 0})
@staticmethod
def _create_student_and_submission(student, answer, date=None, problem_steps=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment